#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn];
vector<int> vc;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  int tot = 0;
  int i, j, k;
  int sa = 0, sb = 0;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%d", &m);
    for (j = 0; j < m; ++j) scanf("%d", &a[j]);
    for (j = 0, k = m - 1; j < k; ++j, --k) {
      sa += a[j];
      sb += a[k];
    }
    if (m & 1) vc.push_back(a[m >> 1]);
  }
  sort((vc).begin(), (vc).end(), greater<int>());
  n = ((int)(vc).size());
  for (i = 0; i < n; ++i) {
    if (i & 1) {
      sb += vc[i];
    } else {
      sa += vc[i];
    }
  }
  printf("%d %d\n", sa, sb);
  return 0;
}
