#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, m, num, a, b;
  vector<int> rems;
  scanf("%d", &n);
  a = b = 0;
  for (j = 0; j < n; j++) {
    scanf("%d", &m);
    for (i = 0; i < m; i++) {
      scanf("%d", &num);
      if (i < m / 2)
        a += num;
      else if ((m % 2 == 1) && (i == m / 2))
        rems.push_back(num);
      else
        b += num;
    }
  }
  sort((rems).begin(), (rems).end(), greater<int>());
  for (i = 0; i < rems.size(); i++) {
    if (i % 2 == 0)
      a += rems[i];
    else
      b += rems[i];
  }
  printf("%d %d\n", a, b);
  return 0;
}
