#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int c[1000];
int main() {
  int n, m;
  int s1 = 0, s2 = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m;
    int g1 = m / 2 - 1;
    int g2 = (m + 1) / 2;
    for (int j = 0; j < m; j++) {
      cin >> c[j];
      if (j <= g1) s1 += c[j];
      if (j >= g2) s2 += c[j];
    }
    if (m % 2 == 1) v.push_back(c[g1 + 1]);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (i % 2 == 0)
      s1 += v[i];
    else
      s2 += v[i];
  }
  cout << s1 << " " << s2;
}
