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++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int n, a, b;

int main() {
    while (cin >> n) {
        if (n == 0) break;
        int A = 0, B = 0;
        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;
    }
    return 0;
}

C++: #include <stdio.h>

int N ;
int a ;
int b ;
int point[2] ;

void init ( ) ;

int main ( )
{
	while ( scanf ( "%d" , &N ) == 1 && N ) {
		init ( ) ;
		for ( int i = 0 ; i < N ; i++ ) {
			scanf ( "%d %d" , &a , &b ) ;
			if ( a > b ) {
				point[0] += ( a + b ) ;
			}
			else if ( a == b ) {
				point[0] += a ;
				point[1] += b ;
			}
			else {
				point[1] += ( a + b ) ;
			}
		}
		printf ( "%d %d\n" , point[0] , point[1] ) ;
	}
	return 0 ;
}

void init ( )
{
	point[0] = point[1] = 0 ;
}

C++: #include <iostream>
using namespace std;
int main(){
	while(1){
	int n; cin >> n ;
	if(n==0) break;
	int suma=0;int sumb=0;
	for(int i=0;i<n;i++){
		int a,b; cin >> a >> b ;
		if(a>b) suma+=a+b;
		else if(b>a) sumb+=a+b;
		else suma+=a,sumb+=b;
	};
	cout << suma << ' ' << sumb << '\n' ;
	};
}

C++: #include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <cstdio>
#include <string.h>
using namespace std;

#define FOR(i, n) for(int i = 0; i < n; i++)
#define bit(i) static_cast<bitset<8> >(i)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long>PLL;
typedef queue<int> QI;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int> > minpq;

struct edge{int to, cost;};

void begin(){cin.tie(0); ios::sync_with_stdio(false);};
int gcd(int a, int b){if(a%b==0){return(b);}else{return(gcd(b,a%b));}};
int lcm(int m, int n){if((0 == m)||(0 == n)){return 0;} return ((m / gcd(m, n)) * n);};
unsigned long long comb(long n, long m){unsigned long long c = 1; m = (n - m < m ? n - m : m);
    for(long ns = n - m + 1, ms = 1; ms <= m; ns ++, ms ++){c *= ns; c /= ms;} return c;};

// ワーシャルフロイド法
void warshallFloyd(int d[100][100], int n){
    for(int k = 0; k < n; ++k)
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                if(d[i][k] != -1 && d[k][j] != -1){
                    if(d[i][j] == -1){
                        d[i][j] = d[i][k] + d[k][j];
                    }else{
                        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                    }
                }
};


// d:隣接行列  n:グラフのサイズ  s:始点  dist:始点からの距離が入る配列
void dijkstra(int d[1000][1000], int n, int s, int dist[1000]){
    FOR(i, n) dist[i] = -1;
    dist[s] = 0;
    priority_queue<PII, vector<PII>, greater<PII> > q;
    q.push(PII(0, s));
    while (!q.empty()) {
        PII p = q.top(); q.pop();
        int i = p.second;
        if(dist[i] < p.first) continue;
        for(int j = 0; j < n; j++){
            if(d[i][j] == -1) continue;
            if(dist[j] == -1){
                dist[j] = dist[i] + d[i][j];
                q.push(PII(dist[j], j));
            }else if(dist[j] > dist[i] + d[i][j]){
                dist[j] = dist[i] + d[i][j];
                q.push(PII(dist[j], j));
            }
        }
    }
};

// 線分の交差判定
bool isCross(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){
    // 並行な場合
    int m = (x2-x1)*(y4-y3)-(y2-y1)*(x4-x3);
    if(m == 0) return false;
    // 媒介変数の値が0より大きく1以下なら交差する、これは問題の状況によって変わるかも。
    double r =(double)((y4-y3)*(x3-x1)-(x4-x3)*(y3-y1))/m;
    double s =(double)((y2-y1)*(x3-x1)-(x2-x1)*(y3-y1))/m;
    return (0 < r && r <= 1 && 0 < s && s <= 1);
};

/**
 * start
 * @author yoshikyoto
 */
void solve(int n){
    int sumA = 0, sumB = 0, a, b;
    FOR(i, n){
        cin >> a >> b;
        if(a > b){
            sumA += a + b;
        }else if(a < b){
            sumB += a + b;
        }else{
            sumA += a;
            sumB += b;
        }
    }
    cout << sumA << " " << sumB << endl;
}

int main(int argc, const char * argv[]){
    while(true){
        int n;
        cin >> n;
        if(n == 0) return 0;
        solve(n);
    }
}

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

int main () {
    int n, i,A,B, resa =0, resb =0;
    while(cin >> n,n){
        for(i=0;i<n;i++){
           　cin >> A >> B;
             (A > B)? resa +=A:resb+=B;
             if(A==B) {resa += A; resb +=B};
        }
　　　　cout << resa << " " << resb << endl;
    }
}

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

int main()
{	
	int n, a, b;

	cin >> n;
	
	while (n > 0) {
		a = 0;
		b = 0;

		for (int i = 0; i < n; i++) {
			int pa, pb;
			cin >> pa >> pb;

			if (pa > pb)
				a += pa + pb;
			else if (pa < pb)
				b += pa + pb;
			else {
				a += pa;
				b += pb;
			}
		}
		cout << a << " " << b << endl;

		cin >> n;
	}

	return 0;
}

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

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

C++: 
int main(void){
  int n,a,b;
  int score[2];

  while(1){
    scanf("%d",&n);
    if(!n) break;
    score[0]=score[1]=0;
    while(n--){
      scanf("%d%d",&a,&b);
      if(a<b){
        score[1] += a+b;
      }
      else if(a>b){
        score[0] += a+b;
      }
      else{
        score[0] += a;
        score[1] += b;
      }
    }
    printf("%d %d\n",score[0],score[1]);
  }

  return 0;
}

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

int n, a, b, ca, cb;

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