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 <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int N=0;
    cin >> N;
    vector<int> A(N), B(N);
    for(int i=0; i<N; ++i) cin >> A[i] >> B[i];

    int ret_a=0, ret_b=0;
    for(int i=0; i<N; ++i) {
        if(A[i] < B[i]) {
            ret_b += A[i]+B[i];
        } else if(A[i] > B[i]) {
            ret_a += A[i]+B[i];
        } else {
            ret_a += A[i]; ret_b = B[i];
        }
    }
    cout << ret_a << " " << ret_b << endl;
}

C++: //https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0500?year=2006

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    while (cin >> n, n) {
        int sumA = 0, sumB = 0;
        for (int i = 0; i < n; ++i) {
            int a, b;
            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;
    }
    return 0;
}

/*
 *
 */

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

int main(){
	int n;
	int a[10001] , b[10001];
	int scoreA=0 , scoreB=0;
	int i;
	while(1){
		cin>>n;
		if(n==0) break;
		for(i=0 ; i<n ; i++){
			cin >> a[i] >> b[i];
			if(a[i]>b[i]){
				scoreA+=a[i]+b[i];
			} else if (a[i]<b[i]){
				scoreB+=a[i]+b[i];
			} else {
				scoreA+=a[i];
				scoreB+=b[i];
			}
		}
		cout << scoreA << " " << scoreB << endl;
	}
	return 0;
}

C++: #include<cstdio>

using namespace std;

int A=0,B=0;

int main()
{
	int n;
	while(true)
	{
		A=0,B=0;
	scanf("%d",&n);
	if(n==0)break;
	for(int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if(a>b)A+=a+b;
		else if(a==b)
		{
			A+=a;
			B+=b;
		}
		else B+=a+b;
	}
	printf("%d %d\n",A,B);
	}
	return 0;
}

C++: #include<stdio.h>
int main(void){
    int loop,a,b,c,d;
    scanf("%d",&loop);
    for(;loop--;){
        scanf("%d %d",&a,&b);
        if(a!=b){
            if(a>b){
                c+=a+b;
            }else{
                d+=a+b;
            }
        }else{
            c+=a;
            d+=b;
        }
    }
    printf("%d %d",c,d);
    return 0;
}

C++: #include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=x && x<w && 0<=y && y<h)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;

/** Problem0500 : Card Game **/
int main()
{
	int n;
	while (cin>>n, n) {
		int sa=0, sb=0;
		rep(i, n) {
			int a, b;
			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>
using namespace std;

int main()
{	
	while(true){
		int n,a[10000]={},b[10000]={},ascore=0,bscore=0;
		cin>>n;
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin>>a[i];
			cin>>b[i];
			if(a[i]>b[i]){
				ascore+=a[i]+b[i];
			}else if(a[i]<b[i]){
				bscore+=a[i]+b[i];
			}else if(a[i]==b[i]){
				ascore+=a[i];
				bscore+=b[i];
			}
		}
		cout<<ascore<<" "<<bscore<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>

using namespace std;

int main() {
	int n;
	while (true) {
		cin >> n;
		if (!n) {
			break;
		}
		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) {
				b += x + y;
			} else {
				a += x;
				b += y;
			}
		}
		cout << a << ' ' << b << endl;
	}
	return 0;
}

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

int main(){
  int n;
  int Acard,Bcard;
  int Atotal,Btotal;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>Acard>>Bcard;
    if(Acard>Bcard){
      Atotal+=Acard+Bcard;
    }else if(Bcard>Acard){
      Btotal+=Acard+Bcard;
    }else{
      Atotal+=Acard;
      Btotal+=Bcard;
    }
  }

  cout<<Atotal<<' '<<Btotal<<'\n';
  return 0;
}

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

int main() {
	int n, a, b;
	
	while(cin>>n,n) {
		a = 0;b = 0;
		for(int i=0;i<n;i++) {
			int sa, sb;
			cin>>sa>>sb;
			if(sa>sb)a+=sa+sb;
			else if(sb>sa)b+=sa+sb;
			else {
				a+=sa;
				b+=sb;
			}
		}
		cout<<a<<b<<endl;
	}
	
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int main(){
int card[20000],i,j,a=0,b=0,c=1,n;
cin>>n;
while(n!=0){
for(i=0;i<2*n;i++){
cin>>card[i];
}
for(i=0;i<2*n;i=i+2){
if(card[i]>card[c]){
a=a+card[i]+card[c];
}
else if (card[i]==card[c]){
a=a+card[i];
b=b+card[c];
}
else{
b=b+card[i]+card[c];
}
c=c+2;
}
cout<<a<<" "<<b<<endl;
c=1;
a=0;
b=0;
cin>>n;
}
return 0;
}

C++: #include <iostream>

using namespace std;

int main() {

  while(true) {
    int n;
    cin >> n;
    if(n == 0) break;
    int pa = 0, pb = 0;
    int stack = 0;
    for(int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      if(a > b) {
        pa += stack + a + b;
        stack = 0;
      }
      else if(a < b) {
        pb += stack + a + b;
        stack = 0;
      }
      else {
        stack += a + b;
      }
    }
    cout << pa << " " << pb << endl;
  }

  return 0;
}

C++: #include <iostream>

int main(void)
{
    int n;
    int a=0,b=0;
    while(true)
    {
        std::cin >> n;
        if(n==0) break;
        a=b=0;
        for(int i=0;i<n;i++)
        {
            int a1,b1;
            std::cin >> a1 >> b1;
            if(a1==b1) {a+=a1;b+=b1;}
            else if(a1>b1) {a+=a1+b1;}
            else {b+=a1+b1;}
        }
        std::cout << a << " " << b << std::endl;
    }

    return 0;
}

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

bool get_input(std::vector<int>& cards_a, std::vector<int>& cards_b)
{
	int n;
	std::cin >> n;

	if (n == 0) return false;

	cards_a.clear(), cards_b.clear();
	int card_a, card_b;
	for (int i = 0; i < n; i++) {
		std::cin >> card_a >> card_b;
		cards_a.push_back(card_a);
		cards_b.push_back(card_b);
	}
	return true;
}

void calc_and_output(std::vector<int>& cards_a, std::vector<int>& cards_b)
{
	int point_a = 0, point_b = 0;
	std::vector<int>::iterator a_itr = cards_a.begin();
	std::vector<int>::iterator b_itr = cards_b.begin();
	for (; a_itr != cards_a.end() && b_itr != cards_b.end(); a_itr++, b_itr++) {
		if (*a_itr > *b_itr) {
			point_a += (*a_itr + *b_itr);
		} else if (*a_itr < *b_itr) {
			point_b += (*a_itr + *b_itr);
		} else {
			point_a += *a_itr;
			point_b += *b_itr;
		}
	}
	std::cout << point_a << " " << point_b << std::endl;
}

int main()
{
	std::vector<int> cards_a, cards_b;
	while (get_input(cards_a, cards_b)) {
		calc_and_output(cards_a, cards_b);
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	int lim;
	
	while( cin >> lim, lim != 0){
		int a = 0, b = 0;
		while(lim-- > 0){
			int n, m;
			cin >> n >> m;
			(n == m)? a+=n, b+=m:
			(n > m)? a += n+m: b += n+m;
		}
		printf("%d %d\n", a, b);
	}
	return 0;
}