#include <bits/stdc++.h>
using namespace std;
int a[1005][1005];
vector<int> v;
bool cmp(const int &a, const int &b) { return a > b; }
int main() {
  int n;
  long long sc = 0, sj = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i][0];
    for (int j = 1; j <= a[i][0]; j++) cin >> a[i][j];
  }
  for (int i = 1; i <= n; i++) {
    if (a[i][0] & 1) {
      for (int j = 1; j <= a[i][0] / 2; j++) sc += a[i][j];
      for (int j = a[i][0] / 2 + 2; j <= a[i][0]; j++) sj += a[i][j];
      v.push_back(a[i][a[i][0] / 2 + 1]);
    } else {
      for (int j = 1; j <= a[i][0] / 2; j++) sc += a[i][j];
      for (int j = a[i][0] / 2 + 1; j <= a[i][0]; j++) sj += a[i][j];
    }
  }
  sort(v.begin(), v.end(), cmp);
  bool flag = true;
  for (auto i : v) {
    if (flag) {
      sc += i;
      flag = !flag;
    } else {
      sj += i;
      flag = !flag;
    }
  }
  cout << sc << ' ' << sj << endl;
  return 0;
}
