#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int ciel = 0;
  int jiro = 0;
  int m;
  vector<int> odd;
  for (int i = 0; i < n; i++) {
    int ni;
    cin >> ni;
    for (int j = 0; j < ni / 2; j++) {
      cin >> m;
      ciel += m;
    }
    if (ni % 2) {
      cin >> m;
      odd.push_back(m);
    }
    for (int j = 0; j < ni / 2; j++) {
      cin >> m;
      jiro += m;
    }
  }
  sort(odd.begin(), odd.end());
  n = odd.size();
  for (int j = 0; j < n; j++) {
    if (j % 2 == 0)
      ciel += odd[n - 1 - j];
    else
      jiro += odd[n - 1 - j];
  }
  cout << ciel << " " << jiro << endl;
}
