Go: package main

import (
	"fmt"
)

// Game is one game.
type Game struct {
	pointA, pointB int
}

func main() {
	var n int
	game := &Game{0, 0}
	fmt.Scanf("%d", &n)
	for n != 0 {
		game.initGame()
		game.execGame(n)
		game.printResult()
		fmt.Scanf("%d", &n)
	}
}

func (game *Game) execGame(n int) {
	var a, b int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
		fmt.Scanf("%d", &b)
		switch {
		case a == b:
			game.pointA += a
			game.pointB += b
		case a > b:
			game.pointA += a + b
		case b > a:
			game.pointB += a + b
		}
	}
}

func (game *Game) initGame() {
	game.pointA = 0
	game.pointB = 0
}

func (game *Game) printResult() {
	fmt.Println(game.pointA, game.pointB)
}

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;
}

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

int main(){
	long long n, x, y, sumx=0, sumy=0;
	cin >> n;

	for(int i=0; i<n; i++){
		x=0,y=0;
		cin >> x >> y;
		if(x > y){
			sumx = sumx + x + y;
		}
		else if(x < y){
			sumy = sumy + x + y;
		}
		else if(x == y){
			sumx = sumx + x;
			sumy = sumy + y;
		}
	}
	
	cout << sumx << " " << sumy  << endl;
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	int n;
	while(cin>>n && n){
		int a=0,b=0;
		
		for(int i=0;i<n;i++){
			int x,y;
			cin>>x>>y;
			if(x>y)a+=x+y;
			else if(x==y){
				a+=x;b+=y;
			}
			else b+=x+y;
		}
		cout<<a<<" "<<b<<endl;
	}
	
}

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

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)

int main() {
	ios::sync_with_stdio(false);
	
	int n;
	int sa, sb, a, b;
	while(1) {
		cin >> n;
		if(!n)break;
		sa = 0;
		sb = 0;
		rep(i, n) {
			cin >> a >> b;
			if(a>b) sa += a+b;
			else if(b>a) sb += a+b;
			else {
				sa += a;
				sb += b;
			}
		}
		cout << sa << " " << sb << endl;
	}	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	int n;
	while (1)
	{
		cin >> n;
		if (n == 0)
			break;
		int as = 0, bs = 0;
		int ac, bc;
		for (int i = 0; i != n; ++i)
		{
			cin >> ac >> bc;
			if (ac == bc)
				as += ac, bs += bc;
			else if (ac > bc)
				as += ac + bc;
			else
				bs += ac + bc;
		}
		cout << as << " " << bs << endl;
	}
	return 0;
}

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