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++: // tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
inline void modAdd(int& _a, int _b, int _m) { _a = (_a + _b) % _m; }
inline void modAdd(lint& _a, lint _b, lint _m) { _a = (_a + _b) % _m; }
inline void minUpdate(int& _a, int _b) { _a = min(_a, _b); }
inline void minUpdate(lint& _a, lint _b) { _a = min(_a, _b); }
inline void maxUpdate(int& _a, int _b) { _a = max(_a, _b); }
inline void maxUpdate(lint& _a, lint _b) { _a = max(_a, _b); }

int n;

void solve() {
	int A = 0, B = 0;
	
	for_(i,0,n) {
		int a, b; 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;
}

int main() {
	while (cin >> n, n) {
		solve();
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,a,b,x=0,y=0;
  cin>>n;
  rep(i,n){
    cin>>a>>b;
    if(a==b){
      x+=a;
      y+=b;
    }
    else if(a>b)x+=(a+b);
    else if(b>a)y+=(a+b);
  }
  cout<<x<<" "<<y<<endl;
}

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

int main(){
	int a=0,b=0;
	int na,nb;
	int nc;
	cin>>nc;
	if(nc==0) return 0;
	for(int i=0;i<nc;i++){
		cin>>na>>nb;
		if(na>nb) a+=(na+nb);
		else if(na<nb) b+=(na+nb);
		else {a+=na;b+=nb;}
	}
	cout<<a<<" "<<b<<endl;
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
#include<iostream>
#include<cmath>
#include<queue>
#include<cctype>
#include<string>
#define rep(i,a,b) for(i=a;i<b;i++)
using namespace std;
int main(void)
{
	int n,i,j,k,suma,sumb,a,b;
	while(1) {
		cin>>n;if(n==0) break;
		suma=0,sumb=0;
		rep(i,0,n) {
			cin>>a>>b;
			if(a>b) suma+=a+b;
			else if(b>a) sumb+=a+b;
			else suma+=a,sumb+=b;
		}
		cout<<suma<<" "<<sumb<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define p_q priority_queue
#define MN 1000000009

int n, a, b, c, d;
int main(){
    while(cin >> n){
        if (n==0) return 0;
        c=d=0;
        for (int l=0; l<n; ++l){
            cin >> a >> b;
            if (a>b) c+=a+b;
            else if (b>a) d+=a+b;
            else {c+=a; d+=a;}
        }
        cout << c << ' ' << d << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	int n, left = 0, right = 0, stage, stage2, i;

	while(cin >> n){
		for(i = 0; i < n; i ++){
			cin >> stage >> stage2;
			if(stage > stage2) left += stage + stage2;
			else if(stage < stage2) right += stage + stage2;
			else{
				left += stage;
				right += stage2;
			}
		}
		cout << left << " " << right << endl;
	}
	return 0;
}

C++: eeee

C++: #include <iostream>
#include <vector>

int main()
{
	int n;
	int a, b;
	std::vector<int> ansa;
	std::vector<int> ansb;
	int sa;
	int sb;
	
	do {
		std::cin >> n;
		for (int i = 0; i < n; i++)
		{
			sa = 0;
			sb = 0;
			std::cin >> a >> b;
			if (a > b) {
				sa += a + b;
			}
			else if (a == b) {
				sa += a;
				sb += b;
			}
			else {
				sb += a + b;
			}
		}
		ansa.push_back(sa);
		ansb.push_back(sb);
	} while (n != 0);

	for (int i = 0; i < n; i++)
	{
		std::cout << ansa[i] << " " << ansb[i] << std::endl;
	}

	return 0;
}

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

int main(void)
{
    
    while (1){
        int n;
        scanf("%d", &n);
        if (n == 0) break;
        
        int A, B;
        int A_sum = 0, B_sum = 0;
        
        for (int i = 0; i < n; i++){
            scanf("%d %d", &A, &B);
            
            if (B < A){
                A_sum += A + B;
            }
            else if (A < B){
                B_sum += A + B;
            }
            else {
                A_sum += A;
                B_sum += B;
            }
        }
        
        printf("%d %d\n", A_sum, B_sum);
        
    }
    
    return (0);
}

C++: #include<iostream>

using namespace std;

int main() {
	int p1[10000], p2[10000], n, point1, point2, i;
	while (true) {
		point1 = 0;
		point2 = 0;
		cin >> n;
		if (n == 0) { break; }
		for (i = 0; i < n; i++) {
			cin >> p1[i] >> p2[i];
		}
		for (i = 0; i < n; i++) {
			if (p1[i] == p2[i]) {
				point1 += p1[i];
				point2 += p2[i];
			}
			else if (p1[i] > p2[i]) {
				point1 += p1[i] + p2[i];
			}
			else {
				point2 += p1[i] + p2[i];
			}
		}
		cout << point1 << ' ' << point2 << endl;
	}
	return 0;
}

C++: #include <cstdio>
int main(){
  int n;
  int data[2],sum[2]={0,0};
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d%d",&data[0],&data[1]);
    if(data[0]>data[1])
      sum[0]+=data[0]+data[1];
    else if(data[0]<data[1])
      sum[1]+=data[0]+data[1];
    else{
      sum[0]+=data[0];
      sum[1]+=data[1];
    }
  }
  printf("%d %d\n",sum[0],sum[1]);
  return 0;
}