#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
int toto, other;
vector<int> ps;
int main() {
  scanf("%d", &n);
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    scanf("%d", &k);
    int l = (k - 1) / 2, r = l + 1, mid = -1;
    if (k & 1) {
      mid = l;
      l--;
    }
    for (int(j) = 0; (j) < (int)(k); (j)++) {
      scanf("%d", &m);
      if (j <= l)
        toto += m;
      else if (r <= j)
        other += m;
      else
        ps.push_back(m);
    }
  }
  sort(ps.begin(), ps.end());
  for (int i = ps.size() - 1, t = 0; i >= 0; i--, t ^= 1) {
    if (t == 0)
      toto += ps[i];
    else
      other += ps[i];
  }
  printf("%d %d\n", toto, other);
  return 0;
}
