#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, i, j, k, l, m, n;
  cin >> n;
  int l1 = 0;
  int l2 = 0;
  vector<int> v1;
  for (i = 0; i < n; i++) {
    cin >> m;
    if (m % 2 == 0) {
      for (j = 1; j <= m; j++) {
        cin >> a;
        if (j <= m / 2)
          l1 += a;
        else
          l2 += a;
      }
    } else {
      for (j = 1; j <= m; j++) {
        cin >> a;
        if (j <= m / 2)
          l1 += a;
        else
          l2 += a;
        if (j == (m / 2) + 1) {
          v1.push_back(a);
          l2 -= a;
        }
      }
    }
  }
  sort(v1.rbegin(), v1.rend());
  for (i = 0; i < v1.size(); i++) {
    if (i % 2 == 0)
      l1 += v1[i];
    else
      l2 += v1[i];
  }
  cout << l1 << " " << l2 << endl;
  return 0;
}
