#include <bits/stdc++.h>
using namespace std;
const int ms = 110;
const int sigma = 30;
int n, m, k, t;
vector<int> ele[ms];
int start[ms];
int endi[ms];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int a, qt;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> qt;
    while (qt--) {
      cin >> a;
      ele[i].push_back(a);
    }
  }
  int aa = 0, bb = 0;
  bool turn = 1;
  vector<int> left;
  for (int i = 0; i < n; i++) {
    int j = 0, k = ele[i].size() - 1;
    for (; j < k; j++, k--) {
      aa += ele[i][j];
      bb += ele[i][k];
    }
    if (j == k) {
      left.push_back(ele[i][j]);
    }
  }
  sort(left.begin(), left.end());
  for (int i = left.size() - 1; i >= 0; i--) {
    if (turn) {
      aa += left[i];
    } else {
      bb += left[i];
    }
    turn = !turn;
  }
  cout << aa << ' ' << bb << '\n';
}
