#include <bits/stdc++.h>
using namespace std;
int n;
int s;
int p1, p2;
int c;
int main() {
  vector<int> r;
  p1 = p2 = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < s / 2; j++) {
      cin >> c;
      p1 += c;
    }
    if (s % 2) {
      cin >> c;
      r.push_back(c);
    }
    for (int j = (s / 2 + s % 2); j < s; j++) {
      cin >> c;
      p2 += c;
    }
  }
  sort(r.begin(), r.end());
  bool t1 = (r.size() % 2);
  for (vector<int>::iterator it = r.begin(); it != r.end(); it++) {
    if (t1)
      p1 += *it;
    else
      p2 += *it;
    t1 = !t1;
  }
  cout << p1 << " " << p2 << endl;
}
