#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1E9;
const long long LINF = (long long)4E18;
const long double PI = acos(-1.0);
const long double E = 2.718281828459045L;
template <typename T>
T gcd(T a, T b) {
  return (b = 0) ? abs(a) : gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
inline T mod(T a, T b) {
  return (a % b + b) % b;
}
template <typename T>
inline T sqr(T x) {
  return x * x;
}
template <typename T>
inline string toString(const T& x) {
  ostringstream os;
  os << x;
  return os.str();
}
inline long long toInt(const string& s) {
  istringstream is(s);
  long long x;
  is >> x;
  return x;
}
inline long double toDouble(const string& s) {
  istringstream is(s);
  long double x;
  is >> x;
  return x;
}
inline string toLower(string s) {
  for (typeof((s).begin()) it = (s).begin(); it != (s).end(); ++it)
    *it = tolower(*it);
  return s;
}
inline string toUpper(string s) {
  for (typeof((s).begin()) it = (s).begin(); it != (s).end(); ++it)
    *it = toupper(*it);
  return s;
}
const char DEBUG_PARAM[] = "__LOCAL_TESTING";
const char IN[] = "e.in";
const char OUT[] = "e.out";
int ntest = 1, test;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const long double EPS = 1E-9;
const long long MODULO = 1000000007LL;
int main() {
  ios_base::sync_with_stdio(false);
  int t, n, d = 0, x, t1;
  int a[1001];
  cin >> t;
  int s = 0, c = 0;
  for (int j = (1); j <= (t); j++) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> x;
      s += x;
      t1 = i * 2 - n;
      if (t1 == 1)
        a[c++] = -x;
      else if (t1 <= 0)
        d += x;
    }
  }
  sort(a, a + c);
  for (int i = 0; i < c; i += 2) d -= a[i];
  cout << d << " " << s - d;
  return 0;
}
