#include <bits/stdc++.h>
using namespace std;
int n;
long long suma1;
long long suma2;
int x;
long long k;
vector<long long> sredine;
long long sumasredine;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  cin >> n;
  suma1 = 0;
  suma2 = 0;
  sumasredine = 0;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x % 2 == 0) {
      for (int i = 1; i <= x / 2; i++) {
        cin >> k;
        suma1 += k;
      }
      for (int i = 1; i <= x / 2; i++) {
        cin >> k;
        suma2 += k;
      }
    } else {
      for (int i = 1; i <= x / 2; i++) {
        cin >> k;
        suma1 += k;
      }
      cin >> k;
      sredine.push_back(k);
      sumasredine += k;
      for (int i = 1; i <= x / 2; i++) {
        cin >> k;
        suma2 += k;
      }
    }
  }
  sort(sredine.begin(), sredine.end());
  long long s = 0;
  for (int i = sredine.size() - 1; i >= 0; i = i - 2) {
    s += sredine[i];
  }
  cout << suma1 + s << " " << suma2 + (sumasredine - s);
  return 0;
}
