#include <bits/stdc++.h>
using namespace std;
int n, sz, Ciel, Jiro;
int a[110];
int main() {
  cin >> n;
  int temp;
  while (n--) {
    int k;
    cin >> k;
    for (int i = 0; i < k / 2; i++) {
      cin >> temp;
      Ciel += temp;
    }
    if (k % 2) {
      cin >> temp;
      a[++sz] = temp;
    }
    for (int i = 0; i < k / 2; i++) {
      cin >> temp;
      Jiro += temp;
    }
  }
  sort(a + 1, a + sz + 1);
  for (int i = sz; i >= 1; i -= 2) Ciel += a[i];
  for (int i = sz - 1; i >= 1; i -= 2) Jiro += a[i];
  cout << Ciel << " " << Jiro << endl;
  return 0;
}
