#include <bits/stdc++.h>
using namespace std;
int a[200][200];
int s[200];
vector<int> v;
int n;
int main() {
  cin >> n;
  int sum1 = 0, sum2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < s[i]; j++) {
      cin >> a[i][j];
      if (j < s[i] / 2)
        sum1 += a[i][j];
      else if (j == s[i] / 2 && s[i] % 2)
        v.push_back(a[i][j]);
      else
        sum2 += a[i][j];
    }
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (i % 2 == 0)
      sum1 += v[i];
    else
      sum2 += v[i];
  }
  cout << sum1 << " " << sum2 << endl;
}
