#include <bits/stdc++.h>
using namespace std;
priority_queue<int> Q;
int ans1 = 0, ans2 = 0;
int n;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int m;
    cin >> m;
    for (int j = 1; j <= m; ++j) {
      int allah;
      cin >> allah;
      if (j <= m / 2)
        ans1 += allah;
      else {
        if (m % 2 && j == m / 2 + 1)
          Q.push(allah);
        else
          ans2 += allah;
      }
    }
  }
  bool cur = 0;
  while (Q.size()) {
    if (!cur)
      ans1 += Q.top();
    else
      ans2 += Q.top();
    cur = !cur;
    Q.pop();
  }
  cout << ans1 << " " << ans2 << endl;
}
