#include <bits/stdc++.h>
using namespace std;
int a[200][200];
int s[200];
int tmp[200];
int sp = 0;
void quicksort(int A[], int l, int r) {
  if (l >= r) return;
  int i = l;
  int j = r;
  int x = A[(l + r) / 2];
  while (i <= j) {
    while (A[i] < x) i++;
    while (A[j] > x) j--;
    if (i <= j) {
      int temp = A[i];
      A[i] = A[j];
      A[j] = temp;
      i++;
      j--;
    }
  }
  quicksort(A, l, j);
  quicksort(A, i, r);
}
int main() {
  long long n, m;
  int i, j;
  long long Tr = 0, Sa = 0;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> s[i];
    for (j = 0; j < s[i]; ++j) cin >> a[i][j];
  }
  for (i = 0; i < n; ++i) {
    if (s[i] % 2 == 0) {
      for (j = 0; j < s[i] / 2; ++j) Tr += a[i][j];
      for (j = s[i] / 2; j < s[i]; ++j) Sa += a[i][j];
    } else {
      for (j = 0; j < s[i] / 2; ++j) Tr += a[i][j];
      for (j = s[i] / 2 + 1; j < s[i]; ++j) Sa += a[i][j];
      tmp[sp++] = a[i][s[i] / 2];
    }
  }
  quicksort(tmp, 0, sp - 1);
  for (i = sp - 1; i >= 0; i--) {
    if ((sp - i) % 2 == 1) {
      Tr += tmp[i];
    } else
      Sa += tmp[i];
  }
  cout << Tr << " " << Sa << "\n";
}
