#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  vector<int> data, ans(2, 0);
  int n, s, start, num;
  cin >> n;
  for (int i = 0; i <= n - 1; ++i) {
    cin >> s;
    for (int j = 1; j <= s / 2; ++j) {
      cin >> num;
      ans[0] += num;
    }
    if (s & 1) {
      cin >> num;
      data.emplace_back(num);
      start = s / 2 + 2;
    } else {
      start = s / 2 + 1;
    }
    for (int j = start; j <= s; ++j) {
      cin >> num;
      ans[1] += num;
    }
  }
  sort(data.begin(), data.end(), greater<int>());
  for (int i = 0; i <= (int)data.size() - 1; ++i) {
    ans[i % 2] += data[i];
  }
  cout << ans[0] << " " << ans[1] << endl;
  return 0;
}
