#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n;
  while (cin >> n) {
    int ans[2] = {0, 0};
    vector<int> mid;
    int k;
    while (n--) {
      cin >> k;
      vector<int> a(k);
      for (int i = 0; i < k; i++) cin >> a[i];
      if (k & 1) mid.push_back(a[k >> 1]);
      for (int i = 0; i < (k >> 1); i++) ans[0] += a[i];
      for (int i = 0; i < (k >> 1); i++) ans[1] += a[k - i - 1];
    }
    sort(mid.begin(), mid.end());
    reverse(mid.begin(), mid.end());
    for (int i = 0; i < mid.size(); i++) ans[i & 1] += mid[i];
    cout << ans[0] << ' ' << ans[1] << endl;
  }
  return 0;
}
