#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
inline void writeln(int x) {
  char buffor[21];
  register int i = 0;
  int neg = 0;
  if (x < 0) {
    neg = 1;
    x = -x;
  }
  do {
    buffor[i++] = (x % 10) + '0';
    x /= 10;
  } while (x);
  i--;
  if (neg) putchar('-');
  while (i >= 0) putchar(buffor[i--]);
  putchar('\n');
}
const int N = 110;
long long res1, res2, n;
vector<int> q;
void input() {
  cin >> n;
  res1 = 0;
  res2 = 0;
  for (int i = 1; i <= n; i++) {
    int sz;
    cin >> sz;
    for (int j = 1; j <= sz; j++) {
      int c;
      cin >> c;
      if (sz % 2 == 1 and j == sz / 2 + 1)
        q.push_back(c);
      else if (j <= sz / 2)
        res1 += c;
      else
        res2 += c;
    }
  }
}
void solve() {
  sort(q.begin(), q.end());
  int sz = (int)q.size();
  int f = 1;
  for (int i = sz - 1; i >= 0; i--) {
    if (f)
      res1 += q[i];
    else
      res2 += q[i];
    f = f ^ 1;
  }
  cout << res1 << " " << res2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  input();
  solve();
  return 0;
}
