#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int s1 = 0, s2 = 0;
  vector<int> mids;
  int i, j;
  for (i = 0; i < n; ++i) {
    int psize, read;
    cin >> psize;
    for (j = 0; j < psize / 2; ++j) {
      cin >> read;
      s1 += read;
    }
    if (psize % 2 != 0) {
      cin >> read;
      mids.push_back(read);
    }
    for (j = 0; j < psize / 2; ++j) {
      cin >> read;
      s2 += read;
    }
  }
  sort(mids.begin(), mids.end());
  reverse(mids.begin(), mids.end());
  int parity = 0;
  for (i = 0; i < mids.size(); ++i) {
    if (parity % 2 == 0) {
      s1 += mids[i];
    } else {
      s2 += mids[i];
    }
    parity++;
  }
  cout << s1 << " " << s2 << endl;
  return 0;
}
