#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5), mod = int(1e9) + 7;
int n, k, a[N], an, c[N];
int x, y;
int main() {
  cin >> n;
  while (n--) {
    cin >> k;
    for (int i = 1; i <= k; i++) {
      int v;
      cin >> v;
      if (k % 2 == 0) {
        if (i <= k / 2)
          x += v;
        else
          y += v;
      } else {
        if (i == k / 2 + 1)
          a[++an] = v;
        else if (i <= k / 2)
          x += v;
        else
          y += v;
      }
    }
  }
  if (an > 0) {
    sort(a + 1, a + an + 1);
    reverse(a + 1, a + an + 1);
    for (int i = 1; i <= an; i++) {
      if (i & 1)
        x += a[i];
      else
        y += a[i];
    }
  }
  cout << x << " " << y;
  return 0;
}
