#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
int main() {
  int N;
  scanf("%d", &N);
  int C = 0, J = 0;
  vector<int> mid;
  for (int i = 0; i < (N); i++) {
    int s;
    scanf("%d", &s);
    for (int j = 0; j < (s / 2); j++) {
      int c;
      scanf("%d", &c);
      C += c;
    }
    if (s & 1) {
      int c;
      scanf("%d", &c);
      mid.push_back(c);
    }
    for (int j = 0; j < (s / 2); j++) {
      int c;
      scanf("%d", &c);
      J += c;
    }
  }
  sort((mid).begin(), (mid).end());
  for (int i = 0; i < (((int)(mid).size())); i++) {
    (i % 2 ? J : C) += mid[((int)(mid).size()) - 1 - i];
  }
  printf("%d ", C);
  printf("%d\n", J);
}
