#include <bits/stdc++.h>
const char en = '\n';
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long a = 0, b = 0, n;
  vector<long long> X;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    vector<long long> V;
    int p;
    cin >> p;
    for (int j = 1; j <= p; j++) {
      long long t;
      cin >> t;
      V.push_back(t);
    }
    if (V.size() % 2 == 1) X.push_back(V[V.size() / 2]);
    for (int j = 0; j < V.size() / 2; j++) {
      a += V[j];
      b += V[V.size() - j - 1];
    }
  }
  sort(X.begin(), X.end());
  reverse(X.begin(), X.end());
  for (int i = 0; i < X.size(); i += 2) a += X[i];
  for (int i = 1; i < X.size(); i += 2) b += X[i];
  cout << a << " " << b << endl;
}
