#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<vector<int>> card(n);
  int f = 0;
  int s = 0;
  for (int i = 0; i < n; i++) {
    int sz;
    cin >> sz;
    card[i].resize(sz);
    for (auto &t : card[i]) {
      cin >> t;
    }
  }
  multiset<int> uu;
  for (int i = 0; i < n; i++) {
    if (card[i].size() % 2 == 0) {
      for (int j = 0; j < (int)card[i].size(); j++) {
        if (j < (int)card[i].size() / 2) {
          f += card[i][j];
        } else {
          s += card[i][j];
        }
      }
    } else {
      for (int j = 0; j < (int)card[i].size(); j++) {
        if (j < (int)card[i].size() / 2) {
          f += card[i][j];
        } else if (j == (int)card[i].size() / 2) {
          uu.insert(card[i][j]);
        } else {
          s += card[i][j];
        }
      }
    }
  }
  int tmp = 0;
  while (!uu.empty()) {
    if (tmp % 2 == 0) {
      f += *uu.rbegin();
    } else {
      s += *uu.rbegin();
    }
    uu.erase(--uu.end());
    tmp++;
  }
  cout << f << ' ' << s;
}
