Go: package main

import "fmt"

func main() {
	for {
		var a, b, n int
		fmt.Scanf("%d", &n)

		if n == 0 {
			return
		}

		for i := 0; i < n; i++ {
			var cardA, cardB int
			fmt.Scanf("%d %d", &cardA, &cardB)

			if cardA > cardB {
				a += cardA + cardB
			} else if cardB > cardA {
				b += cardA + cardB
			} else {
				a += cardA
				b += cardB
			}
		}

		fmt.Println(a, b)
	}
}

C++: // cardgame.cpp
#include <iostream>
using namespace std;

int main(){
	int g,h;
	cin >> g;
	for(h=0;h<g;h++){
		int n=0;
		int i,j;
		int a[10000], b[10000];
		int a_point=0, b_point=0;
		cin >> n;
		for(i=0;i<n;++i){
				cin >> a[i];
				cin >> b[i];
		}
		for(j=0;j<n;++j){
			if(a[j]>b[j])
				a_point+=(a[j]+b[j]);
	        else if(a[j]<b[j])
				b_point+=(a[j]+b[j]);
			else if(a[j]==b[j]){
				a_point+=a[j];
				b_point+=b[j];
			}
		}
		cout << a_point << " " << b_point << endl;
	}
	return 0;	
}

C++: #include <stdio.h>

int main(void)
{

	int n;
	while(1){
		int n;
		int a=0,b=0;
		int ac,bc;

		scanf("%d", &n);
		if(n == 0)
		break;
		for(int i = 0; i < n; i++){
			
			scanf("%d %d", &ac,&bc);
			if(ac > bc)
				a += (ac + bc);
			else if(ac < bc)
				b += (ac + bc);
			else {
				a += ac;
				b += bc;
			}
		}
		printf("%d %d\n", a,b);

	}
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;

int main(){
  int n;
  while(cin >> n){
    if(n==0)break;

    int A = 0, B = 0, a, b;
    for(int i=0;i<n;i++){
      cin >> a >> b;
      if(a > b) A += a+b;
      else if(a < b) B += a+b;
      else A += a, B += b;
    }

    cout << A << " " << B << endl;
  }
}

C++: #include<iostream>
using namespace std;
int main() {
	int n,a,b,c,d;
	for(int i=0;i<5;i++){
		c=0;
		d=0;
		cin>>n;
		if(n==0){
			break;
		}
		for(int y=0;y<n;y++){
			cin>>a>>b;
			if(a>b){
				c=c+a+b;
			}else if(b>a){
				d=d+a+b;
			}else{
				c=c+a;
				d=d+b;
			}
		}
		cout<<c<<" "<<d<<endl;
	}
return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;

int main(){
	int a[10002],b[10002],i;
	int A=0,B=0,n;
	cin>>n;
	while(n!=0){
		for(i=0;i<n;i++){
			cin>>a[i]>>b[i];
		}
		for(i=0;i<n;i++){
			if(a[i]>b[i]){
				A+=(a[i]+b[i]);
			}else if(a[i]<b[i]){
				B+=(a[i]+b[i]);
			}else{
				A+=a[i];B+=b[i];
			}
		}
		cout<<A<<' '<<B<<endl;
		cin>>n;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0) break;
		int a,b,sa=0,sb=0;
		rep(i,0,n){
			cin>>a>>b;
			if(a>b) sa+=a+b;
			else if(a<b) sb+=a+b;
			else{
				sa+=a; sb+=b;
			}
		}
		o(sa<<" "<<sb);
	}
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <map>
using std::vector;
using std::sort;

int main(){
	int n;
	scanf("%d",&n);
	while( n > 0 ){
		int x=0, y=0;
		for(int i=0;i<n;++i){
			int tx, ty;
			scanf("%d%d",&tx,&ty);
			if( tx == ty )
				x+=tx, y+=tx;
			else
				tx>ty?x+=tx+ty:y+=tx+ty;
		}
		printf("%d %d\n", x, y);
		scanf("%d",&n);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define int long long

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))
#define upp(a,b) upper_bound(all(a),(b))
#define fill(i,n) memset(i,n,sizeof(i))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;



signed main() {
    IOS();
    int N;
    while(cin>>N){
        if(N==0)break;
        int A=0,B=0;
        int a,b;
        rep(i,0,N){
            cin>>a>>b;
            if(a>b)A+=a+b;
            else if(a<b)B+=a+b;
            else{
                A+=a;
                B+=b;
            }
        }
        cout<<A<<" "<<B<<endl;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    




















































    return 0;
}

C++: #include<bits/stdc++.h>
#define ll long long
using namespace std;
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  int n;
  while(cin>>n,n){
    int a[100001],b[100001];
    for(int i=0;i<n;i++){
      cin>>a[i]>>b[i];
    }
    ll ansa=0,ansb=0;
    for(int i=0;i<n;i++){
      if(a[i]>b[i])ansa+=a[i]+b[i];
      else if(a[i]==b[i])ansa+=a[i],ansb+=b[i];
      else ansb+=a[i]+b[i];
    }
    cout<<ansa<<" "<<ansb<<endl;
  }
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int n;
    while (cin >> n){
        if(n==0)
            break;
        int x,y;
        int a=0;
        int b=0;
        for(int i=0;i<n;i++){
            cin >> x >> y;
            if(x>y)
                a+=x+y;
            if(x<y)
                b+=x+y;
            if(x==y){
                a+=x;
                b+=y;
            }
        }
        cout << a << " " << b << endl;
    }
}

C++: #include <cstdio>
#include <iostream>
using namespace std;

int main()
{
    int n;
    while(cin >> n && n) {
        int a, b, c, d;
        for(int i=0; i < n; ++i) {
            cin >> c >> d;
            if (c > d) a += c+d;
            else if (d > c) b += c+d;
            else a += c, b += d;
        }

        printf("%d %d\n", a, b);
    }

    return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main(){
	int n;
	int sa, sb;
	int a, b;
	while (1){
		cin >> n;
		if (n == 0){
			break;
		}
		for (int i = 0; i < n; i++){
			cin >> a >> b;
			if (a>b){
				sa = sa + a + b;
			}
			else if (a < b){
				sb = sb + a + b;
			}
			else{
				sa = sa + a;
				sb = sb + b;
			}
		}
		cout << sa << " "<< sb<<endl;

	}
}

C++: #include<iostream>
using namespace std;
int main(){
	  int n,a,b,A,B;
  while(1){
	  cin>>n;
    if(n==0)break;
	 A=0;
	B=0;
      for(int i = 0; i < n;i++){
       cin>>a>>b;
	  if(a < b){  
	   B+=a+b;
	  }
	  else if(a > b){
	   A+=a+b;
	  }
	   else{
	   A+=a;
	  B+=b;
	  }
  }
	  cout<<A<<" "<<B<<endl;
}
return 0;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<long long,int> P;
static const int INF=1<<24;

int n;
int a[10100],b[10100];

int main(){
	while(cin>>n,n){
		rep(i,n){
			cin>>a[i]>>b[i];
		}
		ll ans1=0,ans2=0;
		rep(i,n){
			if(a[i]<b[i]){
				ans2+=a[i]+b[i];
			}
			else if(a[i]==b[i]){
				ans1+=a[i];
				ans2+=b[i];
			}
			else{
				ans1+=a[i]+b[i];
			}
		}
		cout<<ans1<<" "<<ans2<<endl;
	}
	return 0;
}