#include <bits/stdc++.h>
using namespace std;
int n, k, t, suma, sumb, midc;
int mid[200];
int main() {
  scanf("%d", &n);
  suma = 0;
  sumb = 0;
  midc = 0;
  for (int j = 0; j < n; ++j) {
    scanf("%d", &k);
    for (int i = 0; i < k / 2; ++i) {
      scanf("%d", &t);
      suma += t;
    }
    if (k & 1) {
      scanf("%d", &t);
      mid[midc++] = t;
    }
    for (int i = 0; i < k / 2; ++i) {
      scanf("%d", &t);
      sumb += t;
    }
  }
  sort(mid, mid + midc);
  for (int i = 0; i < midc; ++i) {
    if (i % 2 == midc % 2)
      sumb += mid[i];
    else
      suma += mid[i];
  }
  printf("%d %d\n", suma, sumb);
  return 0;
}
