#include <bits/stdc++.h>
using namespace std;
vector<int> vv;
int main() {
  int t, n, x, c1, c2;
  scanf("%d", &t);
  vv.clear();
  c1 = c2 = 0;
  for (int i = 0; i < t; i++) {
    scanf("%d", &n);
    for (int j = 0; j < n / 2; j++) {
      scanf("%d", &x);
      c1 += x;
    }
    if (n % 2) {
      scanf("%d", &x);
      vv.push_back(x);
    }
    for (int j = 0; j < n / 2; j++) {
      scanf("%d", &x);
      c2 += x;
    }
  }
  sort(vv.begin(), vv.end());
  int flag = 1;
  for (int i = vv.size() - 1; i >= 0; i--) {
    if (flag == 1)
      c1 += vv[i];
    else
      c2 += vv[i];
    flag = -flag;
  }
  printf("%d %d\n", c1, c2);
  return 0;
}
