#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 * 100 + 10;
int a[maxn];
bool cmp(int A, int B) { return A > B; }
int main() {
  int n;
  while (~scanf("%d", &n)) {
    memset(a, 0, sizeof(a));
    int m, tmp, ans1 = 0, ans2 = 0;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &m);
      if (m % 2 == 0) {
        for (int i = 0; i < m; i++) {
          scanf("%d", &tmp);
          if (i <= (m - 1) / 2)
            ans1 += tmp;
          else
            ans2 += tmp;
        }
      } else {
        for (int i = 0; i < m; i++) {
          scanf("%d", &tmp);
          if (i < m / 2)
            ans1 += tmp;
          else if (i > m / 2)
            ans2 += tmp;
          else
            a[cnt++] = tmp;
        }
      }
    }
    sort(a, a + n, cmp);
    for (int i = 0; i < cnt; i++) {
      if (i % 2 == 0)
        ans1 += a[i];
      else
        ans2 += a[i];
    }
    printf("%d %d\n", ans1, ans2);
  }
  return 0;
}
