#include <bits/stdc++.h>
using namespace std;
int cd[101];
int main() {
  int n;
  int da = 0, db = 0;
  int zs = 0;
  cin >> n;
  for (int xx = 1; xx <= n; xx++) {
    int x, y;
    cin >> x;
    for (int yy = 1; yy <= x / 2; yy++) cin >> y, da += y;
    if (x & 1) zs++, cin >> cd[zs];
    for (int yy = 1; yy <= x / 2; yy++) cin >> y, db += y;
  }
  sort(cd + 1, cd + zs + 1);
  for (int xx = zs; xx >= 1; xx -= 2) da += cd[xx];
  zs--;
  for (int xx = zs; xx >= 1; xx -= 2) db += cd[xx];
  cout << da << ' ' << db;
}
