#include"stdio.h"
#include"string.h"
#include"stdlib.h"
int main()
{
int n,v[60],m[110];
int c1[250010],c2[250010];
while(scanf("%d",&n),n>0)
{
memset(v,0,sizeof(v));
memset(m,0,sizeof(m));
int sum=0;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&v[i],&m[i]);
sum+=v[i]*m[i];
}
memset(c1,0,sizeof(c1));
memset(c1,0,sizeof(c2));
c1[0]=1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=sum;j++)
{
for(int k=0;k+j<=sum&&k<=v[i]*m[i];k+=v[i])
{
c2[j+k]+=c1[j];
}
}
for(int i=0;i<=sum;i++)
{
c1[i]=c2[i];
c2[i]=0;
}
}
for(int i=sum/2;i>=0;--i)
{
if(c1[i]!=0)
{
printf("%d %d\n",sum-i,i);
break;
}
}
}
//system("pause");
return 0;
}