#include <bits/stdc++.h>
using namespace std;
int main() {
  int pilesnr;
  cin >> pilesnr;
  int Cielsdeck = 0;
  int Jirosdeck = 0;
  multiset<int> oddPile;
  for (int i = 0; i < pilesnr; ++i) {
    int decksize, middle;
    cin >> decksize;
    middle = decksize / 2;
    if (decksize % 2 == 0) {
      for (int j = 0; j < middle; ++j) {
        int card;
        cin >> card;
        Cielsdeck += card;
      }
      for (int j = middle; j < decksize; ++j) {
        int card;
        cin >> card;
        Jirosdeck += card;
      }
    } else {
      int card;
      for (int j = 0; j < middle; ++j) {
        cin >> card;
        Cielsdeck += card;
      }
      cin >> card;
      oddPile.insert(card);
      for (int j = middle + 1; j < decksize; ++j) {
        cin >> card;
        Jirosdeck += card;
      }
    }
  }
  bool Cturn = true;
  for (multiset<int>::reverse_iterator it = oddPile.rbegin();
       it != oddPile.rend(); ++it) {
    if (Cturn) {
      Cielsdeck += *it;
      Cturn = false;
    } else {
      Jirosdeck += *it;
      Cturn = true;
    }
  }
  cout << Cielsdeck << " " << Jirosdeck << endl;
  return 0;
}
