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