#include <bits/stdc++.h>
using namespace std;
namespace RA {
int r(int p) { return 1ll * rand() * rand() % p; }
int r(int L, int R) { return r(R - L + 1) + L; }
}  // namespace RA
int n;
int a[1000], b[1000], lb;
int A, B;
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) {
    int x;
    scanf("%d", &x);
    for (int i = (1); i <= (x); ++i) scanf("%d", &a[i]);
    for (int i = 1, j = x; i < j; i++, j--) A += a[i], B += a[j];
    if (x & 1) b[++lb] = a[x / 2 + 1];
  }
  sort(b + 1, b + lb + 1);
  reverse(b + 1, b + lb + 1);
  for (int i = (1); i <= (lb); ++i) i& 1 ? A += b[i] : B += b[i];
  printf("%d %d\n", A, B);
  return 0;
}
