#include <bits/stdc++.h>
using namespace std;
long long min(long long x, long long y) { return (x < y) ? x : y; }
long long max(long long x, long long y) { return (x > y) ? x : y; }
const int N = 100009;
int x, y, n, m, i, u, ans1, ans2, w, mx, z, sum, best, j, k, t, ans;
int a[N], d[N], p[N];
pair<int, int> opt[N];
int solve(int x) {
  int i, j, ans = 0, sum = 0;
  for (i = 0; i < x; i++) sum += a[i];
  for (i = 0; i < x / 2 + (x % 2); i++) ans += a[i];
  return ans - sum + ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> m;
    for (j = 0; j < m; j++) cin >> a[j], sum += a[j];
    d[i] = solve(m);
    for (j = 0; j < m / 2; j++) swap(a[j], a[m - j - 1]);
    p[i] = solve(m);
    opt[i].first = d[i] + p[i];
    opt[i].second = i;
  }
  sort(opt, opt + n);
  int h = (n - 1) % 2;
  for (i = n - 1; i >= 0; i--) {
    if (i % 2 == h)
      ans1 += d[opt[i].second];
    else
      ans2 += p[opt[i].second];
  }
  k = ans1 - ans2;
  sum = sum - k;
  sum /= 2;
  cout << endl << sum + k << ' ' << sum;
  return 0;
}
