#include <bits/stdc++.h>
using namespace std;
int n, k, t, tmp, ans1, ans2;
int cnt, a[110];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k);
    t = k >> 1;
    for (int i = 1; i <= t; i++) {
      scanf("%d", &tmp);
      ans1 += tmp;
    }
    if (k & 1) {
      scanf("%d", &tmp);
      a[++cnt] = tmp;
    }
    for (int i = 1; i <= t; i++) {
      scanf("%d", &tmp);
      ans2 += tmp;
    }
  }
  sort(a + 1, a + cnt + 1, greater<int>());
  for (int i = 1; i <= cnt; i++) {
    if (i & 1)
      ans1 += a[i];
    else
      ans2 += a[i];
  }
  printf("%d %d\n", ans1, ans2);
  return 0;
}
