#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int llINF = 0x3f3f3f3f3f3f3f;
const int N = 1e6 + 1;
const int MAX_SIEVE = 1e6 + 2;
int main() {
  long long int a = 0, b = 0;
  vector<long long int> mid;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int s;
    scanf("%d", &s);
    for (int j = 0; j < s / 2; j++) {
      long long int plc;
      scanf("%lld", &plc);
      a += plc;
    }
    if (s % 2) {
      long long int plc;
      scanf("%lld", &plc);
      mid.push_back(plc);
    }
    for (int j = 0; j < s / 2; j++) {
      long long int plc;
      scanf("%lld", &plc);
      b += plc;
    }
  }
  sort(mid.begin(), mid.end());
  for (int i = mid.size() - 1, j = 0; i >= 0; i--, j++) {
    if (j % 2)
      b += mid[i];
    else
      a += mid[i];
  }
  printf("%lld %lld\n", a, b);
}
