#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, a, c1 = 0, c2 = 0;
  vector<int> v;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x & 1) {
      x /= 2;
      for (int j = 1; j <= x; j++) {
        cin >> a;
        c1 += a;
      }
      cin >> a;
      v.push_back(a);
      for (int j = 1; j <= x; j++) {
        cin >> a;
        c2 += a;
      }
    } else {
      x /= 2;
      for (int j = 1; j <= x; j++) {
        cin >> a;
        c1 += a;
      }
      for (int j = 1; j <= x; j++) {
        cin >> a;
        c2 += a;
      }
    }
  }
  sort(v.begin(), v.end());
  int i = v.size() - 1;
  while (i >= 0) {
    c1 += v[i];
    i--;
    if (i == -1) break;
    c2 += v[i];
    i--;
  }
  cout << c1 << " " << c2 << endl;
  return 0;
}
