#include <bits/stdc++.h>
using namespace std;
const long long mxN = 1e5 + 1;
long long n, r;
int32_t main() {
  cin >> n;
  vector<long long> v[n], l;
  long long a = 0, b = 0;
  for (long long i = 0; i < n; i++) {
    cin >> r;
    v[i].resize(r);
    for (long long j = 0; j < r; j++) cin >> v[i][j];
    for (long long j = 0; j < r / 2; j++) a += v[i][j];
    for (long long j = 0; j < r / 2; j++) b += v[i][r - 1 - j];
    if (r % 2) {
      l.push_back(v[i][r / 2]);
    }
  }
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  for (long long i = 0; i < l.size(); i++)
    if (i % 2)
      b += l[i];
    else
      a += l[i];
  cout << a << ' ' << b << endl;
}
