#include <bits/stdc++.h>
using namespace std;
int a[101], mid;
int main() {
  int n, ans1 = 0, ans2 = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    if (!(k % 2)) {
      int K = k / 2;
      for (int j = 1; j <= K; j++) {
        int m;
        cin >> m;
        ans1 += m;
      }
      for (int j = K + 1; j <= k; j++) {
        int m;
        cin >> m;
        ans2 += m;
      }
    } else {
      int K = k / 2;
      for (int j = 1; j <= K; j++) {
        int m;
        cin >> m;
        ans1 += m;
      }
      cin >> a[++mid];
      for (int j = K + 2; j <= k; j++) {
        int m;
        cin >> m;
        ans2 += m;
      }
    }
  }
  sort(a + 1, a + 1 + mid);
  for (int i = mid; i >= 1; i -= 2) {
    ans1 += a[i];
    ans2 += a[i - 1];
  }
  cout << ans1 << " " << ans2 << endl;
  return 0;
}
