#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  int n;
  cin >> n;
  int a1 = 0, a2 = 0;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    for (int i = 0; i < s / 2; i++) {
      int x;
      cin >> x;
      a1 += x;
    }
    if (s % 2 == 1) {
      int x;
      cin >> x;
      a.push_back(x);
    }
    for (int i = 0; i < s / 2; i++) {
      int x;
      cin >> x;
      a2 += x;
    }
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; i < (int)a.size(); i++)
    if (i % 2 == 0)
      a1 += a[i];
    else
      a2 += a[i];
  cout << a1 << " " << a2 << "\n";
  return 0;
}
