#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> for_battle;
int main() {
  scanf("%d", &N);
  long long a = 0, b = 0;
  for (int i = 0; i < N; i++) {
    int x;
    scanf("%d ", &x);
    int mid = x % 2 == 0 ? (x / 2) - 1 : (x / 2) - 1;
    int right_mid = x % 2 == 0 ? (x / 2) : (x / 2) + 1;
    for (int j = 0; j < x; j++) {
      int y;
      scanf("%d ", &y);
      if (j <= mid)
        a += y;
      else if (j >= right_mid)
        b += y;
      else
        for_battle.push_back(y);
    }
  }
  sort(for_battle.begin(), for_battle.end());
  for (int i = for_battle.size() - 1, j = 0; i >= 0; i--, j++)
    if (j % 2 == 0)
      a += for_battle[i];
    else
      b += for_battle[i];
  printf("%I64d %I64d\n", a, b);
  return 0;
}
