#include <bits/stdc++.h>
using namespace std;
int a[107];
int le[107], ri[107];
int n;
int main() {
  while (scanf("%d", &n) != EOF) {
    int to, bo;
    to = bo = 0;
    int num = 0;
    int len = 0;
    for (int i = 0; i < n; i++) {
      le[i] = 0;
      scanf("%d", &ri[i]);
      num = ri[i] / 2;
      for (int j = 0; j < num; j++) {
        int x;
        scanf("%d", &x);
        to += x;
      }
      if (ri[i] % 2) {
        int x;
        scanf("%d", &x);
        a[len++] = x;
      }
      for (int j = 0; j < num; j++) {
        int x;
        scanf("%d", &x);
        bo += x;
      }
    }
    int swi = 0;
    sort(a, a + len);
    for (int i = len - 1; i >= 0; i--) {
      if (swi == 0) {
        swi = 1;
        to += a[i];
      } else {
        swi = 0;
        bo += a[i];
      }
    }
    printf("%d %d\n", to, bo);
  }
  return 0;
}
