#include <bits/stdc++.h>
typedef struct {
  int vector[100];
} cartas;
void cerar(int *vect, int dim);
int pivot(int *unarray, int izq, int der);
void Quicksort(int *unarray, int izq, int der);
int main() {
  int k, n, i, j, aux = 0, sumaCiel = 0, sumaJiro = 0;
  scanf("%d", &n);
  cartas pilas[n];
  int dimension[n];
  int sobrante[n];
  int div = 0;
  int encontrado = 0, controlador = 0;
  int resto, indice = 0;
  cerar(sobrante, n);
  for (i = 0; i < n; i++) {
    scanf("%d", &dimension[i]);
    aux = dimension[i];
    for (j = 0; j < aux; j++) {
      scanf("%d", &pilas[i].vector[j]);
    }
  }
  for (i = 0; i < n; i++) {
    aux = dimension[i];
    resto = aux % 2;
    div = aux / 2;
    if (resto == 0) {
      for (j = 0; j < div; j++) {
        sumaCiel += pilas[i].vector[j];
        pilas[i].vector[j] = 0;
      }
      for (k = div; k < aux; k++) {
        sumaJiro += pilas[i].vector[k];
        pilas[i].vector[k] = 0;
      }
    } else {
      for (j = 0; j < div; j++) {
        sumaCiel += pilas[i].vector[j];
      }
      for (k = div + 1; k < aux; k++) {
        sumaJiro += pilas[i].vector[k];
      }
      sobrante[indice] = pilas[i].vector[div];
      indice++;
    }
  }
  Quicksort(sobrante, 0, n - 1);
  for (i = 0; i < n; i++) {
    if (sobrante[i] != 0) {
      if (encontrado == 0) {
        sumaCiel += sobrante[i];
        encontrado = 1;
      } else {
        sumaJiro += sobrante[i];
        encontrado = 0;
      }
    } else {
      i = n;
    }
  }
  printf("%d %d", sumaCiel, sumaJiro);
  return 0;
}
void cerar(int *vect, int dim) {
  int i = 0;
  for (i = 0; i < dim; i++) {
    vect[i] = 0;
  }
}
int pivot(int *unarray, int izq, int der) {
  int i;
  int pivote, valor_pivote;
  int aux;
  pivote = izq;
  valor_pivote = unarray[pivote];
  for (i = izq + 1; i <= der; i++) {
    if (unarray[i] > valor_pivote) {
      pivote++;
      aux = unarray[i];
      unarray[i] = unarray[pivote];
      unarray[pivote] = aux;
    }
  }
  aux = unarray[izq];
  unarray[izq] = unarray[pivote];
  unarray[pivote] = aux;
  return pivote;
}
void Quicksort(int *unarray, int izq, int der) {
  int pivote;
  if (izq < der) {
    pivote = pivot(unarray, izq, der);
    Quicksort(unarray, izq, pivote - 1);
    Quicksort(unarray, pivote + 1, der);
  }
}
