#include <bits/stdc++.h>
void Quicksort(int *v, int izq, int der);
int pivot(int *v, int izq, int der);
int main() {
  int i, n, carta, contador = 0, j, m;
  scanf("%d", &n);
  int vector[101], ciel = 0, jiro = 0;
  for (i = 0; i < 101; i++) {
    vector[i] = 0;
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &m);
    for (j = 0; j < m; j++) {
      scanf("%d", &carta);
      if (j < m / 2) {
        ciel = ciel + carta;
      } else if (m % 2 != 0 && j == m / 2) {
        vector[contador] = carta;
        contador++;
      } else {
        jiro = jiro + carta;
      }
    }
  }
  Quicksort(vector, 0, 100);
  for (i = 0; i < contador; i++) {
    if (i % 2 != 0)
      jiro = jiro + vector[i];
    else
      ciel = ciel + vector[i];
  }
  printf("%d %d", ciel, jiro);
  return 0;
}
int pivot(int *v, int izq, int der) {
  int i;
  int pivote, valor_pivote;
  int aux;
  pivote = izq;
  valor_pivote = v[pivote];
  for (i = izq + 1; i <= der; i++) {
    if (v[i] > valor_pivote) {
      pivote++;
      aux = v[i];
      v[i] = v[pivote];
      v[pivote] = aux;
    }
  }
  aux = v[izq];
  v[izq] = v[pivote];
  v[pivote] = aux;
  return pivote;
}
void Quicksort(int *v, int izq, int der) {
  int pivote;
  if (izq < der) {
    pivote = pivot(v, izq, der);
    Quicksort(v, izq, pivote - 1);
    Quicksort(v, pivote + 1, der);
  }
}
