#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> vec;
  int clei = 0, jiro = 0;
  for (int i = 0; i < n; i++) {
    int s, e;
    cin >> s;
    int h = s / 2;
    for (int j = 0; j < h; j++) {
      cin >> e;
      clei += e;
    }
    if (s & 1) cin >> e, vec.push_back(e), h++;
    for (int j = h; j < s; j++) {
      cin >> e;
      jiro += e;
    }
  }
  sort((vec).rbegin(), (vec).rend());
  int f = 1;
  for (int& e : vec) {
    if (f)
      clei += e;
    else
      jiro += e;
    f ^= 1;
  }
  cout << clei << " " << jiro << '\n';
}
