#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-9;
int first, second;
int n, k, a[100500];
vector<int> v;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) cin >> a[j];
    for (int j = 0; j < k / 2; j++) {
      first += a[j];
      second += a[k - 1 - j];
    }
    if (k % 2) v.push_back(a[k / 2]);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++)
    if (i % 2)
      second += v[i];
    else
      first += v[i];
  cout << first << ' ' << second << endl;
  return 0;
}
