#include <bits/stdc++.h>
void shell(int vec[], int n);
int main(int argc, char const *argv[]) {
  int pilas, i, j;
  scanf("%d", &pilas);
  int pil[100], cant = 0;
  int N, suma1 = 0, suma2 = 0, valor, medio;
  for (i = 0; i < pilas; i++) {
    scanf("%d", &N);
    medio = N / 2;
    for (j = 0; j < N; j++) {
      scanf("%d", &valor);
      if (medio > j) {
        suma1 += valor;
      } else if (medio == j && N % 2 == 1) {
        pil[cant] = valor;
        cant++;
      } else {
        suma2 += valor;
      }
    }
  }
  shell(pil, cant);
  i = cant - 1;
  int selec = 0;
  while (i >= 0) {
    if (selec % 2 == 0) {
      suma1 += pil[i];
    } else {
      suma2 += pil[i];
    }
    i--;
    selec++;
  }
  printf("%d %d", suma1, suma2);
  return 0;
}
void shell(int vec[], int n) {
  for (int salto = n / 2; salto > 0; salto /= 2) {
    for (int i = salto; i < n; i += 1) {
      int aux = vec[i], j;
      for (j = i; (j >= salto) && (vec[j - salto] > aux); j -= salto)
        vec[j] = vec[j - salto];
      vec[j] = aux;
    }
  }
}
