#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void gmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
  if (a > b) a = b;
}
int ans1, ans2, n, x, mid[1010], k;
int main() {
  int ans1 = 0;
  int ans2 = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x % 2 == 0) {
      for (int j = 1; j <= x; j++) {
        cin >> k;
        if (j <= x / 2)
          ans1 += k;
        else
          ans2 += k;
      }
    } else {
      for (int j = 1; j <= x; j++) {
        cin >> k;
        if (j <= x / 2)
          ans1 += k;
        else if (j == (x >> 1) + 1)
          mid[i] = k;
        else
          ans2 += k;
      }
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n - i; j++)
      if (mid[j] < mid[j + 1]) swap(mid[j], mid[j + 1]);
  for (int i = 1; i <= n; i++)
    if (i & 1)
      ans1 += mid[i];
    else
      ans2 += mid[i];
  cout << ans1 << " " << ans2;
}
