#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t, l, r, i, x, n, y, m, j, z, k, v, q, w, mini, g;
  cin >> n;
  vector<long long> a;
  l = 0;
  r = 0;
  for (j = 0; j < n; j++) {
    cin >> m;
    for (i = 0; i < m / 2; i++) {
      cin >> x;
      l = l + x;
    }
    if (m % 2 == 1) {
      cin >> x;
      a.push_back(x);
    }
    for (i = 0; i < m / 2; i++) {
      cin >> x;
      r = r + x;
    }
  }
  sort(a.begin(), a.end());
  n = a.size();
  for (i = n - 1; i >= 0; i--) {
    if (i % 2 == (n - 1) % 2) {
      l = l + a[i];
    } else {
      r = r + a[i];
    }
  }
  cout << l << " " << r << endl;
  return 0;
}
