#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int n, s, c[maxn], res[maxn], res0;
bool cmp(int a, int b) { return a > b; }
int main() {
  scanf("%d", &n);
  int sa = 0, sb = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s);
    for (int j = 1; j <= s; j++) scanf("%d", &c[j]);
    for (int j = 1; j <= s / 2; j++) sa += c[j], sb += c[s - j + 1];
    if (s & 1) res[++res0] = c[s / 2 + 1];
  }
  sort(res + 1, res + 1 + res0, cmp);
  for (int i = 1; i <= res0; i++)
    if (i & 1)
      sa += res[i];
    else
      sb += res[i];
  printf("%d %d\n", sa, sb);
}
