#include <bits/stdc++.h>
using namespace std;
int getnum() {
  char c = getchar();
  int num;
  int sign = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (num = 0; c >= '0' && c <= '9';) {
    c -= '0';
    num = num * 10 + c;
    c = getchar();
  }
  return (num * sign);
}
vector<int> Y;
int main() {
  int n = getnum(), c = 0;
  int A = 0, B = 0, r = 0;
  for (int i = 1; i <= n; i++) {
    int y = getnum();
    c += y;
    for (int j = 1, h = y; j <= y; j++, h--) {
      if (h > j)
        A += getnum();
      else if (h < j)
        B += getnum();
      else if (h == j)
        Y.push_back(getnum());
    }
  }
  sort(Y.begin(), Y.end());
  bool you = false;
  for (int i = Y.size() - 1; i >= 0; i--) {
    if (you = !you)
      A += Y[i];
    else
      B += Y[i];
  }
  cout << A << ' ' << B;
}
