#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
bool comp(int a, int b) { return a > b; }
int main() {
  int n;
  cin >> n;
  int ciel = 0, jiro = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    if (m % 2 == 0) {
      for (int i = 1; i <= m / 2; i++) {
        int x;
        cin >> x;
        ciel += x;
      }
      for (int i = 1; i <= m / 2; i++) {
        int x;
        cin >> x;
        jiro += x;
      }
    } else {
      for (int i = 1; i <= m / 2; i++) {
        int x;
        cin >> x;
        ciel += x;
      }
      int x;
      cin >> x;
      v.push_back(x);
      for (int i = 1; i <= m / 2; i++) {
        int x;
        cin >> x;
        jiro += x;
      }
    }
  }
  sort(v.begin(), v.end(), comp);
  for (int i = 0; i < v.size(); i++)
    if (i % 2 == 0)
      ciel += v[i];
    else
      jiro += v[i];
  cout << ciel << " " << jiro << endl;
}
