#include <bits/stdc++.h>
using namespace std;
int main() {
  int numofpiles;
  cin >> numofpiles;
  int ceilshare = 0;
  int jiroshare = 0;
  vector<int> pileconfig;
  vector<int> remaining;
  while (numofpiles--) {
    int n;
    cin >> n;
    pileconfig.clear();
    for (int i = 0; i < n; i++) {
      int var;
      cin >> var;
      pileconfig.push_back(var);
    }
    if (n % 2 == 0) {
      for (int i = 0; i < n / 2; i++) ceilshare += pileconfig[i];
      for (int i = n / 2; i < n; i++) jiroshare += pileconfig[i];
    } else if (n % 2 != 0) {
      for (int i = 0; i < (n - 1) / 2; i++) ceilshare += pileconfig[i];
      for (int i = (n + 1) / 2; i < n; i++) jiroshare += pileconfig[i];
      remaining.push_back(pileconfig[n / 2]);
    }
  }
  int flag = 0;
  sort(remaining.begin(), remaining.end());
  for (int i = remaining.size() - 1; i >= 0; i--) {
    if (flag == 0) {
      ceilshare += remaining[i];
      flag = 1;
    } else if (flag == 1) {
      jiroshare += remaining[i];
      flag = 0;
    }
  }
  cout << ceilshare << " " << jiroshare << "\n";
}
