#include <bits/stdc++.h>
using namespace std;
int ansa, ansb;
int mid[110], cnt;
int yy;
int cmp(int a, int b) { return a > b; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int s;
    scanf("%d", &s);
    int m = s / 2;
    int x;
    if (s & 1) {
      for (int i = 1; i <= m; ++i) {
        scanf("%d", &x);
        ansa += x;
      }
      scanf("%d", &x);
      mid[cnt++] = x;
      for (int i = 1; i <= m; ++i) {
        scanf("%d", &x);
        ansb += x;
      }
    } else {
      for (int i = 1; i <= m; ++i) {
        scanf("%d", &x);
        ansa += x;
      }
      for (int i = 1; i <= m; ++i) {
        scanf("%d", &x);
        ansb += x;
      }
    }
  }
  sort(mid, mid + cnt, cmp);
  for (int i = 0; i < cnt; ++i) {
    if (i & 1)
      ansb += mid[i];
    else
      ansa += mid[i];
  }
  printf("%d %d", ansa, ansb);
}
