#include <bits/stdc++.h>
using namespace std;
mt19937 mrand(43);
const double PI = acos((double)-1);
const double eps = 1e-5;
const long long inf0 = 1023 * 1024 * 1024;
const long long inf = inf0 * inf0;
const long long mod = 1e9 + 7;
void solve();
void scan();
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed;
  cout.precision(15);
  solve();
  return 0;
}
void solve() {
  int n;
  cin >> n;
  vector<vector<int>> a(n);
  long long a1 = 0, a2 = 0;
  vector<int> mem;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    a[i].resize(s);
    for (int& j : a[i]) cin >> j;
    for (int j = 0; j < s / 2; j++) {
      a1 += a[i][j];
    }
    reverse((a[i]).begin(), (a[i]).end());
    for (int j = 0; j < s / 2; j++) a2 += a[i][j];
    if (s & 1) mem.push_back(a[i][s / 2]);
  }
  sort((mem).rbegin(), (mem).rend());
  for (int i = 0; i < mem.size(); i++) {
    if (i & 1)
      a2 += mem[i];
    else
      a1 += mem[i];
  }
  cout << a1 << " " << a2 << '\n';
  return;
}
