#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &a) {
  T w = 1;
  a = 0;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') w = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) a = (a * 10) + (ch - '0');
  a *= w;
}
template <typename T>
inline void ckmax(T &a, T b) {
  a = a > b ? a : b;
}
template <typename T>
inline void ckmin(T &a, T b) {
  a = a < b ? a : b;
}
priority_queue<int> q;
int main() {
  int n;
  read(n);
  int Ansa = 0, Ansb = 0;
  for (int i = 1; i <= n; ++i) {
    int xx, vis;
    read(xx);
    if (xx & 1) {
      for (int j = 1; j <= xx / 2; ++j) {
        read(vis);
        Ansa += vis;
      }
      read(vis);
      q.push(vis);
      for (int j = xx / 2 + 2; j <= xx; ++j) {
        read(vis);
        Ansb += vis;
      }
    } else {
      for (int j = 1; j <= xx / 2; ++j) {
        read(vis);
        Ansa += vis;
      }
      for (int j = xx / 2 + 1; j <= xx; ++j) {
        read(vis);
        Ansb += vis;
      }
    }
  }
  int flag = 0;
  while (!q.empty()) {
    int x = q.top();
    q.pop();
    if (flag) Ansb += x;
    if (!flag) Ansa += x;
    flag ^= 1;
  }
  printf("%d %d", Ansa, Ansb);
}
