#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1};
int ans[2];
int main() {
  priority_queue<int> q;
  int n;
  scanf("%d", &n);
  for (int(i) = (0); (i) <= (n - 1); (i) += (1)) {
    int k;
    scanf("%d", &k);
    int m = k / 2;
    if (k & 1) {
      for (int(t) = (0); (t) <= (k - 1); (t) += (1)) {
        int x;
        scanf("%d", &x);
        if (t < m)
          ans[0] += x;
        else if (t == m)
          q.push(x);
        else
          ans[1] += x;
      }
    } else {
      for (int(t) = (0); (t) <= (k - 1); (t) += (1)) {
        int x;
        scanf("%d", &x);
        if (t < m)
          ans[0] += x;
        else
          ans[1] += x;
      }
    }
  }
  int now = 0;
  while (!q.empty()) {
    ans[now] += q.top();
    q.pop();
    now = 1 - now;
  }
  printf("%d %d", ans[0], ans[1]);
}
