#include <bits/stdc++.h>
int odd_mid[100];
int main() {
  int n;
  scanf("%d", &n);
  int odd_n = 0;
  std::pair<int, int> ans(0, 0);
  for (int i = 0; i < n; i++) {
    int s, c;
    scanf("%d", &s);
    for (int j = 0; j < s / 2; j++) {
      scanf("%d", &c);
      ans.first += c;
    }
    if (s % 2) {
      scanf("%d", &c);
      odd_mid[odd_n++] = c;
    }
    for (int j = (s + 1) / 2; j < s; j++) {
      scanf("%d", &c);
      ans.second += c;
    }
  }
  std::sort(odd_mid, odd_mid + odd_n);
  for (int i = 0; i < odd_n; i++) {
    if (i % 2 == 0)
      ans.first += odd_mid[odd_n - i - 1];
    else
      ans.second += odd_mid[odd_n - i - 1];
  }
  printf("%d %d\n", ans.first, ans.second);
  return 0;
}
