#include <bits/stdc++.h>
using namespace std;
int ansA = 0, ansB = 0;
int MAIN() {
  int n;
  cin >> n;
  vector<int> mids;
  for (int i = 1; i <= n; i++) {
    int s;
    cin >> s;
    for (int j = 1; j <= s; j++) {
      int t;
      cin >> t;
      if (s % 2 == 0) {
        if (j <= s / 2)
          ansA += t;
        else
          ansB += t;
      } else {
        if (j <= s / 2)
          ansA += t;
        else if (j > s / 2 + 1)
          ansB += t;
        else
          mids.push_back(t);
      }
    }
  }
  sort(mids.begin(), mids.end());
  reverse(mids.begin(), mids.end());
  for (int i = 0; i < mids.size(); i++)
    if (i % 2 == 0)
      ansA += mids[i];
    else
      ansB += mids[i];
  cout << ansA << " " << ansB << endl;
  return 0;
}
int main() {
  ios ::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  return MAIN();
}
