#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int first = 0, second = 0;
  vector<int> a;
  while (n--) {
    int k, x;
    cin >> k;
    for (int i = 1; i <= k / 2; i++) {
      cin >> x;
      first += x;
    }
    if (k % 2) {
      cin >> x;
      a.push_back(x);
    }
    for (int i = 1; i <= k / 2; i++) {
      cin >> x;
      second += x;
    }
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  bool k = true;
  for (auto it : a) {
    if (k)
      first += it;
    else
      second += it;
    k = !k;
  }
  cout << first << " " << second << endl;
}
