#include <bits/stdc++.h>
using namespace std;
int a[105], b[105], i, m, ans, k, j, q, x, n, ma, mi, ans1, ans2;
string s;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> ma;
    for (j = 1; j <= ma; j++) cin >> a[j];
    for (j = 1; j <= ma / 2; j++) ans1 += a[j], ans2 += a[ma - j + 1];
    if (ma % 2) b[k++] = a[(ma + 1) / 2];
  }
  sort(b, b + k);
  reverse(b, b + k);
  for (i = 0; i < k; i++)
    if (i % 2)
      ans2 += b[i];
    else
      ans1 += b[i];
  cout << ans1 << " " << ans2 << endl;
}
