#include <bits/stdc++.h>
using namespace std;
void Solution();
int main() {
  Solution();
  return 0;
}
int n, m, sum[110][110], lt[110], rt[110], res[2];
vector<int> a[110];
void Solution() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &m);
    a[i].resize(m);
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
      sum[i][j + 1] = sum[i][j] + a[i][j];
    }
    lt[i] = 0, rt[i] = m;
  }
  int player = 0;
  while (true) {
    int bv = 10000, bp = 0, op;
    if (player == 0) {
      for (int i = 0; i < n; i++)
        if (lt[i] != rt[i]) {
          if ((rt[i] - lt[i]) % 2 == 0 && bv > a[i][(lt[i] + rt[i]) >> 1])
            bv = a[i][(lt[i] + rt[i]) >> 1], bp = i;
          if ((rt[i] - lt[i]) % 2 == 1 && bv > -a[i][(lt[i] + rt[i]) >> 1])
            bv = -a[i][(lt[i] + rt[i]) >> 1], bp = i;
        }
      if (bv == 10000) break;
      op = lt[bp]++;
    } else {
      for (int i = 0; i < n; i++)
        if (lt[i] != rt[i]) {
          if ((rt[i] - lt[i]) % 2 == 0 && bv > a[i][((lt[i] + rt[i]) >> 1) - 1])
            bv = a[i][((lt[i] + rt[i]) >> 1) - 1], bp = i;
          if ((rt[i] - lt[i]) % 2 == 1 && bv > -a[i][(lt[i] + rt[i]) >> 1])
            bv = -a[i][(lt[i] + rt[i]) >> 1], bp = i;
        }
      if (bv == 10000) break;
      op = --rt[bp];
    }
    res[player] += a[bp][op];
    player = 1 - player;
  }
  printf("%d %d\n", res[0], res[1]);
}
