#include <bits/stdc++.h>
using namespace std;
int xf[110];
int que[110][1010], tail[110];
int main() {
  int n, s;
  int a, b;
  int i, j;
  while (cin >> n) {
    for (i = 1; i <= 100; i++) {
      tail[i] = 1;
    }
    a = 0, b = 0;
    for (i = 1; i <= n; i++) {
      cin >> s;
      while (s--) {
        int temp;
        cin >> temp;
        que[i][tail[i]] = temp;
        tail[i]++;
      }
      tail[i]--;
    }
    int t = 1;
    for (i = 1; i <= n; i++) {
      if (!(tail[i] & 1)) {
        for (j = 1; j <= tail[i] / 2; j++) a += que[i][j];
        for (; j <= tail[i]; j++) b += que[i][j];
      } else {
        for (j = 1; j <= tail[i] / 2; j++) a += que[i][j];
        xf[t] = que[i][j++];
        t++;
        for (; j <= tail[i]; j++) b += que[i][j];
      }
    }
    sort(xf + 1, xf + t + 1);
    bool flag = false;
    for (i = t; i >= 1; i--) {
      if (!flag) {
        a += xf[i];
        flag = true;
      } else {
        b += xf[i];
        flag = false;
      }
    }
    cout << a << " " << b << endl;
  }
  return 0;
}
