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 int long long int
#define main signed main()
#define bye return 0
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define prec(n) fixed << setprecision(n)
#define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl
#define clr(x, a) memset(x, a, sizeof(x))

#define sum(v) accumulate(all(v), 0)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define odd(n) ((n) % 2)
#define even(n) (!odd(n))

#define INF 1000000000
#define MOD 1000000007

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
     
using namespace std;

main {
  int n;
  for(;;) {
    cin>>n;
    if(n==0)break;
    int a=0,b=0;
    rep(i,n) {
      int c,d;
      cin>>c>>d;
      if (c>d) a+=c+d; else if (c<d) b+=c+d; else {a=c; b=d;}
     }
    cout<<a<<' '<<b<<endl;
  }
  bye;
}

C++: #include <iostream>
using namespace std;
 
int main() {
  int n, a, b, pointA, pointB;

  cin >> n;
  while(n != 0) {
    

    pointA = 0;
    pointB = 0;

    for(int i = 0; i < n; i++) {
      cin >> a >> b;
 
      if(a > b) {
        pointA += (a + b);
      } else if(a < b) {
        pointB += (a + b);
      } else {
        pointA += a;
        pointB += b;
      }
    }

    cout << pointA << ' ' << pointB << endl;
    cin >> n;
  }   
 
  return 0;
}

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

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

    int a,b,sa=0,sb=0;
    for(int i=0; i<d; i++) {
      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;
  }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n,q,s,k,h,w,r;
int a[100000];
int d[100000][20],g[20];
void BNS(int x){
	int left=0,sea=19,ran=10;
	while(true){
		sea-=ran,ran/=2;
		if(g[sea]<=x)left=max(sea,left),sea+=ran*2;
		if(!ran)break;
	}
	h=left,w=g[h];
	return;
}
int main(){
	cin>>n;
	w=1,h=0;while(w<=n)w*=2,h++;
	for(int i=0;i<n;i++){cin>>a[i];d[i][0]=a[i];}
	w=1;
	for(int i=1;i<h;i++){
		w*=2;
		for(int j=0;j<=n-w;j++)d[j][i]=min(d[j][i-1],d[j+w/2][i-1]);
	}
	w=1;for(int i=0;i<20;i++)g[i]=w,w*=2;
	cin>>q;
	for(int u=0;u<q;u++){
		scanf("%d%d",&s,&k);
		BNS(k);
		printf("%d\n",min(d[s][h],d[s+k-w][h]));
	}
	return 0;
}

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

C++: #include<iostream>

using namespace std;

int A, B, card[10000][2];

int main(){

	while(1){

		int n, i;

		cin >> n;
		if(n==0){break;}

		for(i=0; i<n; i++){
			cin >> card[i][0] >> card[i][1];
		}

		for(i=0; i<n; i++){
			if(card[i][0]==card[i][1]){
				A += card[i][0];
				B += card[i][0];
			}
			else if(card[i][0] > card[i][1]){
				A += card[i][0] + card[i][1];
			}
			else{
				B += card[i][0] + card[i][1];
			}
		}

		cout << A << ' '<< B << endl;

	}

	return 0;
}

C++: #include<iostream>

using namespace std;

int main() {
  int n;
  while(cin>>n && n!=0) {
    int pointA = 0, pointB = 0;
    int tmpA, tmpB;
    for(int i=0; i<n; i++) {
      cin>>tmpA>>tmpB;
      if(tmpA > tmpB) {
        pointA += tmpA+tmpB;
      }
      else if(tmpA < tmpB) {
        pointB += tmpA+tmpB;
      }
      else {
        pointA += tmpA;
        pointB += tmpB;
      }
    }
    cout<<pointA<<" "<<pointB<<endl;
  }
}

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

C++: #include<iostream>
#include<vector>
int main() {
	int i = 0;
	std::cin >> i;
	std::vector <int> ha, hb;
	while (i != 0) {
		int A = 0, B = 0;
		std::vector<int> a(10000), b(10000);
		for (int j = 0; j < i; ++j) {
			std::cin >> a[j] >> b[j];
		}
		for (int j = 0; j < i; ++j) {
			if (a[j] > b[j]) {
				A += (a[j] + b[j]);
			}
			else if (a[j] < b[j]) {
				B += (a[j] + b[j]);
			}
			else {
				A += a[j];
				B += b[j];
			}
		}
		ha.push_back(A);
		hb.push_back(B);
	}
	for (int j = 0; j < i; ++j) {
		std::cout << ha[j] << " " << hb[j] << std::endl;
	}
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))

//repetition//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0)break;
		int p1=0, p2=0;
		REP(i, n){
			int t1, t2;
			cin >> t1 >> t2;
			if(t1 > t2)p1+=t1+t2;
			if(t1 < t2)p2+=t1+t2;
			if(t1 == t2){
				p1 += t1;
				p2 += t2;
			}
		}
		cout << p1 << " " << p2 << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void)
{
	int n;
	int a, b;
	
	while (1){
		cin >> n;
		if (n == 0)break;
		
		a = b = 0;
		for (int i = 0; i < n; i++){
			int ca, cb;
			cin >> ca >> cb;
			if (ca > cb){
				a += ca + cb;
			}
			else if (ca == cb){
				a += ca;
				b += cb;
			}
			else {
				b += ca + cb;
			}
		}
		
		cout << a << ' ' << b << endl;
	}
	
	return (0);
}