#include <bits/stdc++.h>
using namespace std;
const int INF = (-1u) / 2;
const long long int INF2 = (-1ull) / 2;
int a, b, i, d[1011000], j, k, n, m, timer = 0, l, r, x, y;
int c[1011000], cnt = 0, fl = 0, a2, a3 = -1000000, ans = 0;
vector<int> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> m;
    for (j = 1; j <= m; j++) {
      cin >> a;
      if (m % 2 == 0) {
        if (j <= m / 2)
          x += a;
        else
          y += a;
      } else {
        if (j <= m / 2)
          x += a;
        else if (j > m / 2 + 1)
          y += a;
        else
          v.push_back(a);
      }
    }
  }
  sort(v.begin(), v.end());
  for (i = 0; i < v.size(); i++) {
    a = v[v.size() - 1 - i];
    if (i % 2 == 0)
      x += a;
    else
      y += a;
  }
  cout << x << " " << y << endl;
  return 0;
}
