#include <bits/stdc++.h>
using namespace std;
void RD(int &x) { scanf("%d", &x); }
void RD(long long &x) { scanf("%I64d", &x); }
void RD(double &x) { scanf("%lf", &x); }
void RD(int &x, int &y) { scanf("%d%d", &x, &y); }
void RD(long long &x, long long &y) { scanf("%I64d%I64d", &x, &y); }
void RD(double &x, double &y) { scanf("%lf%lf", &x, &y); }
void RD(char *s) { scanf("%s", s); }
void RD(char &s) { scanf("%c", &s); }
void RD(string &s) { cin >> s; }
void PR(int x) { printf("%d\n", x); }
void PR(int x, int y) { printf("%d %d\n", x, y); }
void PR(long long x) { printf("%I64d\n", x); }
void PR(char x) { printf("%c\n", x); }
void PR(char *x) { printf("%s\n", x); }
void PR(string x) { cout << x << endl; }
const long long inf = 1;
const long long mod = 1LL;
vector<int> v;
int main() {
  int n, m, i, j, k, a, b;
  while (scanf("%d", &n) == 1) {
    (v.clear());
    a = b = 0;
    while (n--) {
      RD(m);
      for ((i) = 1; (i) <= (int)(m / 2); (i)++) RD(j), a += j;
      if (m & 1) RD(j), v.push_back(j);
      for ((i) = 1; (i) <= (int)(m / 2); (i)++) RD(j), b += j;
    }
    sort(v.rbegin(), v.rend());
    k = (int)v.size();
    for ((i) = 0; (i) < (int)(k); (i)++) {
      if (i & 1)
        b += v[i];
      else
        a += v[i];
    }
    printf("%d %d\n", a, b);
  }
  return 0;
}
