#include <bits/stdc++.h>
using namespace std;
bool comp(const vector<int> &l, const vector<int> &r) {
  if (l[0] % 2 && r[0] % 2) {
    return l[1] < r[1];
  }
  if ((l[0] % 2) && (r[0] % 2 == 0)) return true;
  if ((l[0] % 2 == 0) && (r[0] % 2))
    return false;
  else
    return true;
}
int main() {
  int tmp, ans, test, c, i, j, n, k, t, odd, ans1 = 0, ans2 = 0;
  vector<int> ar[102], v;
  scanf("%d", &test);
  for (int i = 1; i <= test; i++) {
    scanf("%d", &n);
    ar[i].push_back(n);
    if (n % 2 == 0) {
      ans = 0;
      for (k = 1; k <= n / 2; k++) {
        scanf("%d", &t);
        ans += t;
      }
      ar[i].push_back(ans);
      ans = 0;
      for (k = 1; k <= n / 2; k++) {
        scanf("%d", &t);
        ans += t;
      }
      ar[i].push_back(ans);
      ar[i].push_back(-1);
    } else {
      ans = 0;
      for (k = 1; k <= n / 2; k++) {
        scanf("%d", &t);
        ans += t;
      }
      ar[i].push_back(ans);
      scanf("%d", &odd);
      ans = 0;
      for (k = 1; k <= n / 2; k++) {
        scanf("%d", &t);
        ans += t;
      }
      ar[i].push_back(ans);
      ar[i].push_back(odd);
      v.push_back(odd);
    }
  }
  for (i = 1; i <= test; i++) {
    if (1 || ar[i][0] % 2 == 0) {
      ans1 += ar[i][1];
      ans2 += ar[i][2];
    }
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  bool ok = true;
  for (i = 0; i < v.size(); i++) {
    if (ok)
      ans1 += v[i];
    else
      ans2 += v[i];
    ok = !ok;
  }
  cout << ans1 << " " << ans2 << endl;
  return 0;
}
