#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int t, s, c[110], sum[2];
int main() {
  cin >> t;
  while (t--) {
    cin >> s;
    for (int i = 0; i < s; i++) cin >> c[i];
    int l = 0, r = s - 1;
    while (r > l) {
      sum[0] += c[l];
      sum[1] += c[r];
      l++;
      r--;
    }
    if (l == r) v.push_back(c[l]);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) sum[i % 2] += v[i];
  cout << sum[0] << " " << sum[1];
  return 0;
}
