#include <bits/stdc++.h>
using namespace std;
int score[2];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  multiset<int> left;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    for (int j = 0; j < s; j++) {
      int x;
      cin >> x;
      if (j < s / 2) {
        score[0] += x;
      } else if (j >= (s + 1) / 2)
        score[1] += x;
      if (s % 2 && j == s / 2) left.insert(x);
    }
  }
  int f = 0;
  while (!left.empty()) {
    score[f] += *(--left.end());
    f = 1 - f;
    left.erase(--left.end());
  }
  cout << score[0] << " " << score[1];
  return 0;
}
