#include <bits/stdc++.h>
using namespace std;
long long int Lpow(long long int a, long long int b) {
  long long int ans = 1;
  while (b > 0) {
    if (b % 2) ans = (ans * a);
    a = (a * a);
    b = b / 2;
  }
  return ans;
}
long long int Lpow(long long int a, long long int b, long long int M) {
  long long int ans = 1;
  while (b > 0) {
    if (b % 2) ans = (ans * a) % M;
    a = (a * a) % M;
    b = b / 2;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> brr;
  int f1 = 0;
  int f2 = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    int sum = 0;
    int y;
    int sum2 = 0;
    for (int j = 0; j < x; j++) {
      cin >> y;
      if (j > ((x - 1) / 2)) sum += y;
      if (j < (x / 2)) sum2 += y;
      if (x % 2 == 1 && j == x / 2) brr.push_back(y);
    }
    f1 += sum2;
    f2 += sum;
  }
  sort(brr.begin(), brr.end());
  reverse(brr.begin(), brr.end());
  for (int i = 0; i < brr.size(); i += 2) f1 += brr[i];
  for (int i = 1; i < brr.size(); i -= -2) f2 += brr[i];
  cout << f1 << " " << f2 << '\n';
  return 0;
}
