#include <bits/stdc++.h>
using namespace std;
vector<long long> vrr;
int main() {
  long long n, i, k, j, a, Siel, Djiro;
  cin >> n;
  Siel = Djiro = 0;
  for (i = 1; i <= n; i++) {
    cin >> k;
    for (j = 1; j <= k; j++) {
      cin >> a;
      if (j <= k / 2)
        Siel += a;
      else if (j + (k / 2) == k)
        vrr.push_back(a);
      else
        Djiro += a;
    }
  }
  if (vrr.size() > 0) {
    sort(vrr.begin(), vrr.end());
    for (i = vrr.size() - 1; i >= 0; i--) {
      if ((vrr.size() - 1) % 2 == i % 2)
        Siel += vrr[i];
      else
        Djiro += vrr[i];
    }
  }
  cout << Siel << " " << Djiro;
  return 0;
}
