#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, vector<int> > > x;
  int res1 = 0, res2 = 0;
  for (int i = 0; i < (n); ++i) {
    int db;
    scanf("%d", &db);
    vector<int> tmp(db);
    for (int j = 0; j < (db); ++j) {
      scanf("%d", &tmp[j]);
    }
    if (tmp.size() & 1) {
      x.push_back(make_pair(tmp[tmp.size() / 2], tmp));
    } else {
      for (int j = 0; j < (db); ++j) {
        if (j < db / 2)
          res1 += tmp[j];
        else
          res2 += tmp[j];
      }
    }
  }
  sort(x.begin(), x.end());
  int b = 0;
  for (int i = x.size() - 1; i > -1; --i) {
    const vector<int>& tmp = x[i].second;
    for (int j = 0; j < (tmp.size()); ++j) {
      if (j < tmp.size() / 2)
        res1 += tmp[j];
      else if (j > tmp.size() / 2)
        res2 += tmp[j];
    }
    if (b) {
      res2 += tmp[tmp.size() / 2];
    } else {
      res1 += tmp[tmp.size() / 2];
    }
    b = 1 - b;
  }
  printf("%d %d\n", res1, res2);
  return 0;
}
