#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  int sum = 0, tot = 0;
  int t;
  priority_queue<int> pq;
  while (N--) {
    int M;
    cin >> M;
    for (int i = 0; i < M / 2; i++) {
      cin >> t;
      sum += t;
      tot += t;
    }
    if (M % 2) {
      cin >> t;
      pq.push(t);
    }
    for (int i = 0; i < M / 2; i++) {
      cin >> t;
      tot += t;
    }
  }
  while (!pq.empty()) {
    t = pq.top();
    pq.pop();
    sum += t;
    tot += t;
    if (!pq.empty()) {
      t = pq.top();
      pq.pop();
      tot += t;
    }
  }
  cout << sum << " " << tot - sum << endl;
}
