#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, anA = 0, anB = 0;
  vector<int> ms;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int m, tmp;
    cin >> m;
    for (int j = 1; j <= m; j++) {
      cin >> tmp;
      if (m % 2 == 1) {
        int mid = int(m / 2) + 1;
        if (j < mid)
          anA += tmp;
        else if (j > mid)
          anB += tmp;
        else
          ms.push_back(tmp);
      } else {
        if (j <= m / 2)
          anA += tmp;
        else
          anB += tmp;
      }
    }
  }
  sort(ms.begin(), ms.end());
  reverse(ms.begin(), ms.end());
  for (int j = 0; j < ms.size(); j++) {
    if (j % 2)
      anB += ms[j];
    else
      anA += ms[j];
  }
  cout << anA << ' ' << anB;
  return 0;
}
