#include <bits/stdc++.h>
using namespace std;
const int maxN = 105;
int n, a[maxN], res1, res2, cnt;
bool cmp(int a, int b) { return a > b; }
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int m, x;
    scanf("%d", &m);
    if (m % 2 == 1) {
      for (int j = 1; j <= (m - 1) / 2; ++j) scanf("%d", &x), res1 += x;
      scanf("%d", &a[++cnt]);
      for (int j = (m - 1) / 2 + 2; j <= m; ++j) scanf("%d", &x), res2 += x;
    } else {
      for (int j = 1; j <= m / 2; ++j) scanf("%d", &x), res1 += x;
      for (int j = m / 2 + 1; j <= m; ++j) scanf("%d", &x), res2 += x;
    }
  }
  sort(a + 1, a + cnt + 1, cmp);
  for (int i = 1; i <= cnt; ++i)
    if (i % 2 == 1)
      res1 += a[i];
    else
      res2 += a[i];
  cout << res1 << " " << res2;
  return 0;
}
