#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
struct data {
  int num;
  int init;
};
bool byNum(const data &left, const data &right) { return left.num > right.num; }
bool descend(const int &left, const int &right) { return left > right; }
data total[105];
pair<int, int> pile[105];
int sisa[105], card[105];
int main(void) {
  int temp, n, i, j;
  scanf("%d", &n);
  for (i = 0; i <= n - 1; i++) {
    scanf("%d", &card[i]);
    sisa[i] = 0;
    for (j = 0; j <= card[i] / 2 - 1; j++) {
      scanf("%d", &temp);
      pile[i].first += temp;
    }
    if (card[i] % 2) {
      scanf("%d", &temp);
      sisa[i] = temp;
    }
    for (j = 0; j <= card[i] / 2 - 1; j++) {
      scanf("%d", &temp);
      pile[i].second += temp;
    }
    total[i].num = pile[i].first + sisa[i] + pile[i].second;
    total[i].init = i;
  }
  sort(total, total + n, byNum);
  sort(sisa, sisa + n, descend);
  long long a = 0, b = 0;
  for (i = 0; i <= n - 1; i++) {
    a += pile[total[i].init].first;
    b += pile[total[i].init].second;
  }
  for (i = 0; i <= n - 1; i++) {
    if (i % 2)
      b += sisa[i];
    else
      a += sisa[i];
    if (!sisa[i]) break;
  }
  cout << a << " " << b << endl;
  return 0;
}
