#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int s[N], a[N][N], n, ciel[N], jiro[N], cur[N], _ciel[N], _jiro[N];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    cur[i] = s[i];
    _jiro[i] = s[i] - 1;
    if (s[i] % 2) {
      ciel[i] = s[i] / 2 - 1;
      jiro[i] = s[i] / 2 + 1;
    } else {
      ciel[i] = s[i] / 2 - 1;
      jiro[i] = s[i] / 2;
    }
    for (int j = 0; j < s[i]; j++) {
      cin >> a[i][j];
    }
  }
  bool ciel_move = 0;
  int ciel_score = 0, jiro_score = 0;
  for (int _n = n; _n;) {
    ciel_move = !ciel_move;
    if (ciel_move) {
      int index, best_add = -int(1e9);
      for (int i = 0; i < n; i++) {
        if (!cur[i]) continue;
        int add;
        if (cur[i] % 2) {
          add = a[i][ciel[i] + 1];
        } else {
          add = 0;
        }
        if (add > best_add) {
          best_add = add;
          index = i;
        }
      }
      if (cur[index] % 2) {
        ciel[index]++;
      } else {
        jiro[index]++;
      }
      ciel_score += a[index][_ciel[index]++];
      cur[index]--;
      if (!cur[index]) _n--;
    } else {
      int index, best_add = -int(1e9);
      for (int i = 0; i < n; i++) {
        if (!cur[i]) continue;
        int add;
        if (cur[i] % 2) {
          add = a[i][jiro[i] - 1];
        } else {
          add = 0;
        }
        if (add > best_add) {
          best_add = add;
          index = i;
        }
      }
      if (cur[index] % 2) {
        jiro[index]--;
      } else {
        ciel[index]--;
      }
      jiro_score += a[index][_jiro[index]--];
      cur[index]--;
      if (!cur[index]) _n--;
    }
  }
  cout << ciel_score << " " << jiro_score << endl;
  return 0;
}
