#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
vector<int> v;
int main() {
  int nn, n;
  cin >> nn;
  int alice = 0, bob = 0;
  while (nn--) {
    cin >> n;
    bool flag = 0;
    if (n % 2 == 0) flag = 1;
    if (flag) {
      for (int i = 0; i < n / 2; i++) {
        int q;
        cin >> q;
        alice += q;
      }
      for (int i = 0; i < n / 2; i++) {
        int q;
        cin >> q;
        bob += q;
      }
    } else {
      for (int i = 0; i < n / 2; i++) {
        int q;
        cin >> q;
        alice += q;
      }
      int w;
      cin >> w;
      v.push_back(w);
      for (int i = 0; i < n / 2; i++) {
        int q;
        cin >> q;
        bob += q;
      }
    }
  }
  sort(v.begin(), v.end(), cmp);
  int ert = 1;
  for (int i = 0; i < v.size(); i++) {
    if (ert)
      alice += v[i];
    else
      bob += v[i];
    ert = !ert;
  }
  cout << alice << " " << bob << endl;
}
