#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int a[maxn], b[maxn], c[maxn], m, top, x, d[maxn], n, T, suma, sumb, ans, res;
bool cmp(int a, int b) { return a > b; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> m;
    for (int i = 1; i <= m; i++) {
      cin >> x;
      if (i <= m / 2)
        suma += x;
      else if (m % 2 == 1 && i == m / 2 + 1)
        a[++top] = x;
      else
        sumb += x;
    }
  }
  sort(a + 1, a + 1 + top, cmp);
  for (int i = 1; i <= top; i++)
    if (i % 2 == 1)
      suma += a[i];
    else
      sumb += a[i];
  cout << suma << " " << sumb;
}
