#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long n, second, sum, sum2, a;
int32_t main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> second;
    for (long long j = 1; j <= second; j++) {
      cin >> a;
      if (j <= second / 2) sum += a;
      if (j > (second + 1) / 2) sum2 += a;
      if (second % 2)
        if (j == (second + 1) / 2) v.push_back(a);
    }
  }
  sort(v.begin(), v.end(), greater<long long>());
  for (long long i = 0; i < (long long)v.size(); i++)
    if (i % 2)
      sum2 += v[i];
    else
      sum += v[i];
  return cout << sum << " " << sum2 << endl, 0;
}
