#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int i, j, a = 0, b = 0, c, k, n;
  std::vector<int> v;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> k;
    for (j = 0; j < k / 2; j++) cin >> c, a += c;
    if (k & 1) cin >> c, v.push_back(c);
    for (j = 0; j < k / 2; j++) cin >> c, b += c;
  }
  sort(v.begin(), v.end(), greater<int>());
  for (i = 0; i < v.size(); i++)
    if (i & 1)
      b += v[i];
    else
      a += v[i];
  cout << a << " " << b;
}
