#include <bits/stdc++.h>
using namespace std;
priority_queue<int> q;
int n, m, t, ans1, ans2;
int main() {
  scanf("%d", &n);
  ans1 = ans2 = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &m);
    for (int i = 1; i <= m / 2; i++) {
      scanf("%d", &t);
      ans1 += t;
    }
    if (m % 2) {
      scanf("%d", &t);
      q.push(t);
    }
    for (int i = 1; i <= m / 2; i++) {
      scanf("%d", &t);
      ans2 += t;
    }
  }
  int flag = 1;
  while (!q.empty()) {
    if (flag) {
      ans1 += q.top();
      flag = 0;
    } else {
      ans2 += q.top();
      flag = 1;
    }
    q.pop();
  }
  printf("%d %d\n", ans1, ans2);
  return 0;
}
