#include <bits/stdc++.h>
using namespace std;
const int OO = (int)2e9;
const double eps = 1e-9;
int main() {
  std::ios_base::sync_with_stdio(false);
  int t, n, i, p1 = 0, p2 = 0, x;
  vector<int> v;
  cin >> t;
  while (t--) {
    cin >> n;
    for ((i) = 0; (i) < (n); (i)++) {
      cin >> x;
      if ((n & 1) && i == n / 2)
        v.push_back(x);
      else if (i < n / 2)
        p1 += x;
      else
        p2 += x;
    }
  }
  sort((v).rbegin(), (v).rend());
  n = ((int)(v).size());
  for ((i) = 0; (i) < (n); (i)++) (i & 1) ? p2 += v[i] : p1 += v[i];
  cout << p1 << " " << p2 << endl;
  return 0;
}
