#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
}
int n, m, a[1000], ans1, ans2, k, x;
int main() {
  read(n);
  m = 0;
  for (int i = 1; i <= (n); ++i) {
    read(k);
    for (int j = 1; j <= (k); ++j) {
      read(x);
      if (k % 2 && j * 2 - 1 == k)
        a[++m] = x;
      else if (j * 2 <= k)
        ans1 += x;
      else
        ans2 += x;
    }
  }
  sort(a + 1, a + m + 1);
  int o(1);
  for (int i = (m); i >= (1); --i) {
    if (o == 1)
      ans1 += a[i];
    else
      ans2 += a[i];
    o = 3 - o;
  }
  printf("%d %d\n", ans1, ans2);
  return 0;
}
