#include <bits/stdc++.h>
using namespace std;
int n, len[110], ans1 = 0, ans2 = 0, num[110], cnt = 1;
bool cmp(int a, int b) { return a > b; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &len[i]);
    if (len[i] % 2) {
      int x;
      for (int j = 1; j <= len[i] / 2; j++) {
        scanf("%d", &x);
        ans1 += x;
      }
      scanf("%d", &x);
      num[cnt++] = x;
      for (int j = 1; j <= len[i] / 2; j++) {
        scanf("%d", &x);
        ans2 += x;
      }
    } else {
      int x;
      for (int j = 1; j <= len[i] / 2; j++) {
        scanf("%d", &x);
        ans1 += x;
      }
      for (int j = 1; j <= len[i] / 2; j++) {
        scanf("%d", &x);
        ans2 += x;
      }
    }
  }
  sort(num + 1, num + cnt, cmp);
  for (int i = 1; i < cnt; i++) {
    if (i % 2)
      ans1 += num[i];
    else
      ans2 += num[i];
  }
  printf("%d %d", ans1, ans2);
  return 0;
}
