#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(15);
  int n, x, a = 0, b = 0;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> x;
    for (int j = 1; j <= x; j++) {
      int y;
      cin >> y;
      int l = j - 1, r = x - j;
      if (l < r)
        a += y;
      else if (r < l)
        b += y;
      else
        v.push_back(y);
    }
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < (int)v.size(); i++) {
    if (i % 2 == 0)
      a += v[i];
    else
      b += v[i];
  }
  cout << a << " " << b;
  return 0;
}
