#include <bits/stdc++.h>
using namespace std;
int n, m;
int in() {
  int x;
  cin >> x;
  return x;
}
int main() {
  int i, j;
  while (cin >> n) {
    vector<int> v;
    int sum[2] = {0};
    for (int i = 0; i < (int)(n); i++) {
      cin >> m;
      for (int j = 0; j < (int)(m / 2); j++) sum[0] += in();
      if (m & 1) v.push_back(in());
      for (int j = 0; j < (int)(m / 2); j++) sum[1] += in();
    }
    sort(v.rbegin(), v.rend());
    for (int i = 0; i < (int)(v.size()); i++) sum[i & 1] += v[i];
    cout << sum[0] << " " << sum[1] << endl;
  }
  return 0;
}
