#include <bits/stdc++.h>   using namespace std;   int main(void) {     long long int n, x;     cin >> n;     vector<vector<long long int> > a(n);     for (long long int i = 0; i < n; i++) {       cin >> x;       for (long long int j = 0; j < x; j++) {         long long int tp;         cin >> tp;         a[i].push_back(tp);       }     }     long long int a1 = 0, b = 0;     vector<long long int> q;     for (long long int i = 0; i < n; i++) {       long long int f = a[i].size();       if (f % 2 != 0) {         for (long long int j = 0; j < (f - 1) / 2; j++) {           a1 += a[i][j];         }         for (long long int j = (f - 1) / 2 + 1; j < f; j++) {           b += a[i][j];         }         q.push_back(a[i][(f - 1) / 2]);       } else {         for (long long int j = 0; j < f / 2; j++) {           a1 += a[i][j];         }         for (long long int j = f / 2; j < f; j++) {           b += a[i][j];         }       }     }     sort(q.begin(), q.end(), greater<long long int>());     for (long long int k = 0; k < q.size(); k++) {       if (k % 2 == 0)         a1 += q[k];       else         b += q[k];     }     cout << a1 <<     << b;   }   