//hdu1171
void solve()
{
for(int i=1;i<=n;i++)
{
for(int j=W;j>=w[i];j--)
{
dp[j]=max(dp[j],dp[j-w[i]]+val[i]);
}
}
}
void solve1()
{
for(int i=1;i<=n;i++)
{
for(int j=INF;j>=val[i];j--)
{
dp[j]=max(dp[j],dp[j-val[i]]+val[i]);
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=0;
//cin>>t;
while(cin>>n&&n>0)
{
//cin>>n;
sum=0;
memset(dp,0,sizeof(dp));
memset(val,0,sizeof(val));
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
sum+=a[i]*b[i];
}
int num=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=b[i];j++)
{
val[++num]=a[i];
}
}
n=num;
INF=sum/2;
solve1();
cout<<sum-dp[INF]<<" "<<dp[INF]<<endl;
}
return 0;
}