#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p1 = 0, p2 = 0;
  cin >> n;
  int mid[1000], index = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a % 2 == 0) {
      for (int j = 1; j <= (a / 2); j++) {
        int t;
        cin >> t;
        p1 += t;
      }
      for (int j = 1; j <= (a / 2); j++) {
        int t;
        cin >> t;
        p2 += t;
      }
    } else {
      for (int j = 1; j <= (a / 2); j++) {
        int t;
        cin >> t;
        p1 += t;
      }
      cin >> mid[index++];
      for (int j = 1; j <= (a / 2); j++) {
        int t;
        cin >> t;
        p2 += t;
      }
    }
  }
  sort(mid, mid + index);
  for (int i = index - 1; i >= 0; i--) {
    if (((index - 1) % 2 == 0 && i % 2 == 0) ||
        ((index - 1) % 2 == 1 && i % 2 == 1))
      p1 += mid[i];
    else
      p2 += mid[i];
  }
  cout << p1 << " " << p2 << endl;
  return 0;
}
