#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n, m, x;
  cin >> n;
  int s1(0), s2(0);
  vector<int> v;
  for (int i = 0; i < n; ++i) {
    cin >> m;
    for (int j = 0; j < m; ++j) {
      cin >> x;
      if (m % 2) {
        if (j == m / 2)
          v.push_back(x);
        else if (2 * j < m)
          s1 += x;
        else
          s2 += x;
      } else {
        if (2 * j < m)
          s1 += x;
        else
          s2 += x;
      }
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); ++i)
    if (i % 2)
      s2 += v[v.size() - 1 - i];
    else
      s1 += v[v.size() - 1 - i];
  cout << s1 << " " << s2 << "\n";
  return 0;
}
