#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v;
int a[1000];
long long ansl = 0, ansr = 0;
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int m;
    scanf("%d", &m);
    for (int j = 0; j < m; ++j) scanf("%d", &a[j]);
    for (int j = 0; j < m / 2; ++j) ansl += a[j], ansr += a[m - j - 1];
    if (m % 2) v.push_back(a[m / 2]);
  }
  sort(v.begin(), v.end());
  for (int i = v.size() - 1, j = 0; i >= 0; --i, ++j)
    if (j % 2)
      ansr += v[i];
    else
      ansl += v[i];
  cout << ansl << ' ' << ansr << endl;
}
int main() {
  solve();
  return 0;
}
