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