#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, c = 0, z = 0;
  cin >> n;
  vector<long long> vec;
  for (long long i = 0; i < n; i++) {
    long long k;
    cin >> k;
    if (k % 2 == 0) {
      for (long long j = 1; j <= k / 2; j++) {
        long long num;
        cin >> num;
        c += num;
      }
      for (long long j = (k / 2) + 1; j <= k; j++) {
        long long num;
        cin >> num;
        z += num;
      }
    } else {
      for (long long j = 1; j <= k / 2; j++) {
        long long num;
        cin >> num;
        c += num;
      }
      long long a;
      cin >> a;
      vec.push_back(a);
      for (long long j = (k / 2) + 2; j <= k; j++) {
        long long num;
        cin >> num;
        z += num;
      }
    }
  }
  sort(vec.rbegin(), vec.rend());
  for (long long i = 0; i < vec.size(); i++) {
    if (i % 2 == 0) {
      c += vec[i];
    } else
      z += vec[i];
  }
  cout << c << " " << z << endl;
}
