#include <bits/stdc++.h>
using namespace std;
int r[102], tot;
bool cmp(int x, int y) { return x > y; }
int main() {
  int n, x, y, a, b;
  while (scanf("%d", &n) != EOF) {
    tot = 0;
    a = 0;
    b = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &x);
      for (int i = 0; i < x / 2; i++) {
        scanf("%d", &y);
        a += y;
      }
      if (x & 1) scanf("%d", &y);
      if (x & 1) r[tot++] = y;
      for (int i = 0; i < x / 2; i++) {
        scanf("%d", &y);
        b += y;
      }
    }
    sort(r, r + tot, cmp);
    for (int i = 0; i < tot; i++) {
      if (i & 1)
        b += r[i];
      else
        a += r[i];
    }
    printf("%d %d\n", a, b);
  }
  return 0;
}
