#include <bits/stdc++.h>
using namespace std;
long long n, a, b, i, sum, sum1, j;
vector<long long> v;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a;
    if (a % 2 == 0) {
      for (j = 1; j <= a; j++) {
        cin >> b;
        if (j <= a / 2) {
          sum += b;
        } else {
          sum1 += b;
        }
      }
    } else {
      for (j = 1; j <= a; j++) {
        cin >> b;
        if (j <= (a - 1) / 2) {
          sum += b;
        } else if (j == a / 2 + 1) {
          v.push_back(b);
        } else {
          sum1 += b;
        }
      }
    }
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (i = 0; i < v.size(); i++) {
    if (i % 2 == 0) {
      sum += v[i];
    } else {
      sum1 += v[i];
    }
  }
  cout << sum << " " << sum1 << endl;
  return 0;
}
