#include <bits/stdc++.h>
using namespace std;
int a[101];
int main() {
  int n;
  int l, c;
  int t1, t2;
  int i, j;
  int ll = 0;
  scanf("%d", &n);
  t1 = 0;
  t2 = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &l);
    for (j = 1; j <= l / 2; j++) {
      scanf("%d", &c);
      t1 = t1 + c;
    }
    if (l % 2 == 1) {
      ll++;
      scanf("%d", &a[ll]);
    }
    for (j = 1; j <= l / 2; j++) {
      scanf("%d", &c);
      t2 = t2 + c;
    }
  }
  sort(a + 1, a + ll + 1);
  for (i = ll; i >= 1; i = i - 2) {
    t1 = t1 + a[i];
    if (i > 1) t2 = t2 + a[i - 1];
  }
  printf("%d %d\n", t1, t2);
  return 0;
}
