#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
static inline int Rint() {
  struct X {
    int dig[256];
    X() {
      for (int i = '0'; i <= '9'; ++i) dig[i] = 1;
      dig['-'] = 1;
    }
  };
  static X fuck;
  int s = 1, v = 0, c;
  for (; !fuck.dig[c = getchar()];)
    ;
  if (c == '-')
    s = 0;
  else if (fuck.dig[c])
    v = c ^ 48;
  for (; fuck.dig[c = getchar()]; v = v * 10 + (c ^ 48))
    ;
  return s ? v : -v;
}
template <typename T>
static inline void cmax(T& a, const T& b) {
  if (b > a) a = b;
}
template <typename T>
static inline void cmin(T& a, const T& b) {
  if (b < a) a = b;
}
int data[100];
int line[100];
int main() {
  int n = Rint();
  int top = 0;
  int ans[2] = {0};
  for (int i = 0; i < n; ++i) {
    const int s = Rint();
    for (int j = 0; j < s; ++j) {
      line[j] = Rint();
    }
    const int half = s >> 1;
    ans[0] += accumulate(line, line + half, 0);
    ans[1] += accumulate(line + s - half, line + s, 0);
    if (s & 1) data[top++] = line[half];
  }
  sort(data, data + top);
  reverse(data, data + top);
  for (int i = 0; i < top; ++i)
    if (i % 2 == 0)
      ans[0] += data[i];
    else
      ans[1] += data[i];
  printf("%d %d\n", ans[0], ans[1]);
  return 0;
}
