#include <bits/stdc++.h>
using namespace std;
int dt[110], ansa, ansb, n, t, cnt, d;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &t);
    if (t & 1) {
      for (int j = 1; j <= t / 2; ++j) {
        scanf("%d", &d);
        ansa += d;
      }
      scanf("%d", &d);
      dt[++cnt] = d;
      for (int j = 1; j <= t / 2; ++j) {
        scanf("%d", &d);
        ansb += d;
      }
    } else {
      for (int j = 1; j <= t / 2; ++j) {
        scanf("%d", &d);
        ansa += d;
      }
      for (int j = 1; j <= t / 2; ++j) {
        scanf("%d", &d);
        ansb += d;
      }
    }
  }
  sort(dt + 1, dt + 1 + cnt);
  reverse(dt + 1, dt + 1 + cnt);
  for (int i = 1; i <= cnt; ++i) {
    if (i & 1)
      ansa += dt[i];
    else
      ansb += dt[i];
  }
  printf("%d %d\n", ansa, ansb);
}
