#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int c[120][120],ct[120],n;
int ccc[120],Ciel,Jiro,cnt;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",ct+i);
int p1=ct[i]/2-1,p2=ct[i]-ct[i]/2;
for(int j=0;j<ct[i];j++)
{
scanf("%d",&c[i][j]);
if(j<=p1)
Ciel+=c[i][j];
else if(j>=p2)
Jiro+=c[i][j];
else ccc[cnt++]=c[i][j];
}
}
sort(ccc,ccc+cnt);
for(int i=cnt-1;i>=0;i--)
{
if((cnt-i)%2) Ciel+=ccc[i];
else Jiro+=ccc[i];
}
printf("%d %d\n",Ciel,Jiro);
return 0;
}
/**
* Created by ckboss on 14-10-7.
*/
import java.util.*;
public class FoxandCardGame {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int[][] pile = new int[n+10][111];
int[] qiang = new int[n+10];
int qn=0;
int SumA=0,SUM=0;
for(int i=1;i<=n;i++){
pile[i][0]=in.nextInt();
for(int j=1;j<=pile[i][0];j++){
pile[i][j]=in.nextInt();
SUM+=pile[i][j];
if(j<=pile[i][0]/2) SumA+=pile[i][j];
}
if(pile[i][0]%2==1){
qiang[qn++]=pile[i][pile[i][0]-pile[i][0]/2];
}
}
Arrays.sort(qiang,0,qn);
for(int i=qn-1,j=0;i>=0;i--,j++){
if(j%2==0)
SumA+=qiang[i];
}
System.out.println(SumA+" "+(SUM-SumA));
}
}