#include <bits/stdc++.h>   using namespace std;   vector<int> Q[123];   int stk[123];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       for (int j = 0; j < x; j++) {         int u;         scanf( %d , &u);         Q[i].push_back(u);       }     }     int cnt = 0;     int A = 0, B = 0;     for (int i = 0; i < n; i++) {       if (Q[i].size() % 2 == 1) {         stk[cnt++] = Q[i][Q[i].size() / 2];       }       for (int j = 0; j < Q[i].size() / 2; j++) A += Q[i][j];       for (int j = 0; j < Q[i].size() / 2; j++) B += Q[i][Q[i].size() - 1 - j];     }     sort(stk, stk + cnt);     for (int i = cnt - 2; i > -1; i -= 2) B += stk[i];     for (int i = cnt - 1; i > -1; i -= 2) A += stk[i];     cout << A <<     << B <<   n ;   }   