#include <bits/stdc++.h>
using namespace std;
const long long infl = 1e18 + 5;
long long int n, q, x, y, mx = -1, mn = infl, f, val, sz, cnt, ans, t = 1, i, j,
                          ind = -1, sm;
long long int b[1000004];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  if (fopen("inp.txt", "r")) {
    freopen("myfile.txt", "w", stdout);
    freopen("inp.txt", "r", stdin);
  }
  cin >> n;
  long long int s1 = 0, s2 = 0;
  std::vector<long long int> v;
  for (i = 0; i < n; i++) {
    cin >> b[i];
    cnt = 0;
    t = -1, sm = 0;
    for (j = 0; j < b[i]; j++) {
      cin >> x;
      if (b[i] % 2 == 1 && cnt == b[i] / 2) t = x;
      cnt++;
      if (cnt <= (b[i]) / 2) sm += x;
      s2 += x;
    }
    if (t != -1) {
      v.push_back(t);
      s2 -= t;
    }
    s2 -= sm;
    s1 += sm;
  }
  sort(v.begin(), v.end(), greater<long long int>());
  for (i = 0; i < (long long int)v.size(); i++) {
    s1 += v[i];
    ++i;
    if (i < (long long int)v.size()) s2 += v[i];
  }
  cout << s1 << " " << s2;
  return 0;
}
