#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n;
  int x = 0, y = 0;
  int t, tmp;
  vector<int> vect;
  cin >> n;
  while (n--) {
    cin >> t;
    for (int i = 0; i < t; i++) {
      cin >> tmp;
      if (i < t / 2)
        x += tmp;
      else if (1 == (1 & t) && i == t / 2)
        vect.push_back(tmp);
      else
        y += tmp;
    }
  }
  sort(vect.begin(), vect.end());
  reverse(vect.begin(), vect.end());
  for (int i = 0; i < vect.size(); i++) {
    if (0 == (i & 1))
      x += vect[i];
    else
      y += vect[i];
  }
  cout << x << " " << y << endl;
  return 0;
}
