#include <bits/stdc++.h>
int pile[105][105], buf[105];
int main() {
  int n, first = 0, second = 0, cnt = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int k, t;
    scanf("%d", &k);
    for (int i = 0; i < k / 2; i++) {
      scanf("%d", &t);
      first += t;
    }
    if (k % 2) scanf("%d", &buf[cnt++]);
    for (int i = 0; i < k / 2; i++) {
      scanf("%d", &t);
      second += t;
    }
  }
  std::sort(buf, buf + cnt);
  for (int i = cnt - 1, flg = 1; i >= 0; i--, flg = !flg) {
    if (flg)
      first += buf[i];
    else
      second += buf[i];
  }
  printf("%d %d\n", first, second);
}
