#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int N;
int second[MAXN];
int arr[MAXN][MAXN];
int lb[MAXN], rb[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> second[i];
    for (int j = 0; j < second[i]; j++) cin >> arr[i][j];
    lb[i] = 0;
    rb[i] = second[i];
  }
  int s1 = 0, s2 = 0;
  int turn = 0;
  while (1) {
    int bst = -1, bstval = 0;
    for (int i = 0; i < N; i++) {
      if (lb[i] == rb[i]) continue;
      int mb = lb[i] + rb[i];
      int pos;
      if (mb % 2 == 0) {
        if (turn == 0)
          pos = mb / 2;
        else
          pos = mb / 2 - 1;
      } else
        pos = (mb - 1) / 2;
      if (arr[i][pos] > bstval) {
        bstval = arr[i][pos];
        bst = i;
      }
    }
    if (bst == -1) break;
    if (turn == 0)
      s1 += arr[bst][lb[bst]++];
    else
      s2 += arr[bst][--rb[bst]];
    turn ^= 1;
  }
  cout << s1 << " " << s2 << endl;
  return 0;
}
