#include <bits/stdc++.h>
using namespace std;
const int MAXN = 123456;
vector<int> a;
int n, b[MAXN], x, y, foo;
int main() {
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &foo);
    for (int i = 0; i < (foo); i++) scanf("%d", b + i);
    for (int i = 0; i < (foo / 2); i++) {
      x += b[i];
      y += b[foo - (foo / 2) + i];
    }
    if (foo % 2 == 1) a.push_back(b[foo / 2]);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; i < (int)a.size(); i++) {
    if (i % 2 == 0)
      x += a[i];
    else
      y += a[i];
  }
  printf("%d %d\n", x, y);
  return 0;
}
