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

Python: def run(infile, outfile):
	n = int(infile.readline())
	if n == 0:
		break
	foo(infile,outfile,n)

def foo(infile, outfile, n):
	ax = 0 #a's point
	bx = 0
	for i in range(n):
		a , b = infile.readline().split()
		a = int(a)
		b = int(b)
		if a > b:
			ax += (a + b)
		elif b > a:
			bx += (a + b)
		else:
			assert False
	print >> outfile, ax , bx

if __name__ == "__main__":
	import sys
	run(sys.stdin, sys.stdout)

Python: while True:
    n = int(input())
    if n == 0:
        break
    
    sum_a = 0
    sum_b = 0
    
    for i in range(n):
        a,b = map(int, raw_input().split())
        
        if a > b:
            sum_a = sum_a + a + b
        elif a < b:
            sum_b = sum_b + a + b
        elif a == b:
            sum_a = sum_a + a
            sum_b = sum_b + b

    print(sum_a,sum_b)

Python: n = input()
a_cnt = 0
b_cnt = 0
for i in range(n) :
    arr = input().split(" ")
    num = [int(m) for m in arr]
    if num[0] > num[1] :
        a_cnt += sum(num)
    elif num[1] > num[0] :
        b_cnt += sum(num)
    else :
        a_cnt += num[0]
        b_cnt += num[0]
print(f"{a_cnt} {b_cnt}")

Python: while 1:
    n = int(input())
    scoreA = 0
    scoreB = 0

    if n == 0: break

    for i in range(n):

        A,B = map(int, input().split())

        if A > B:
            scoreA += A + B
        elif A < B :
            scoreB += A + B
        elif A == B:
            scoreA += A
            scoreB += B

    print(scoreA,scoreB)

Python: while True:
    n = int(input())
    if n == 0:
        break
    score = [0, 0]
    for _ in range(n):
        A, B = map(int, input().split())
        if A == B:
            score += [A, B]
        else:
            score[A > B] += A+B
    print(*score)

Python: # coding: utf-8
# Here your code !

while 1:
    a = 0
    b = 0
    n = int(input())
    if n == 0:
        break
    else:
        e = [[int(i) for i in input().split()] for i in range(n)] 
        for i in e:
            if i[0] > i[1]:
                a += sum(i)
            elif i[1] > i[0]:
                b += sum(i)
            else:
                a += i[0]
                b += i[1]
        print(a,b)

Python: n = int(input())
while n > 0:
    A = 0
    B = 0
    for i in range(n):
        a,b = [int(j) for j in input().split(" ")]
        if a > b:
            A += (a+b)
        elif b > a:
            B += (a+b)
        else:
            A += a
            B += b
    print(A,B,sep=" ")
    n = int(input())

Python: while 1:
 a=b=0;n=int(input())
 if n==0:break
 for i in[0]*n:
  s,t=map(int,input().split())
  if s<t:b+=s
  else:a+=s
  if s>t:a+=t
  else:b+=t
 print(a,b)

Python: while True:
    n = int(input())
    if n == 0:
        break
    A = B = 0
    for i in range(n):
        a, b = map(int, input().split())
        if a > b:
            A += a + b
        elif a < b:
            B += a + b
        else:
            A += a
            B += b
    print(A, B)

Python: while True:
    card_num = int(input())
    if(card_num == 0):
        break
    a = 0
    b = 0
    for i in range(card_num):
        comp = input()
        if(int(comp[0]) == int(comp[2])):
            a += int(comp[0])
            b += int(comp[0])
        elif(int(comp[0]) > int(comp[2])):
            a += int(comp[0]) + int(comp[2])
        elif(int(comp[0]) < int(comp[2])):
            b += int(comp[0]) + int(comp[2])
    print(str(a)+' '+ str(b) + '\n')

Python: while True:
    n = int(input())
    if n == 0:
        break
    a, b = 0, 0
    for _ in range(n):
        ca, cb = map(int, input().split())
        a += ca + cb if ca > cb else ca if ca == cb else 0
        b += ca + cb if ca < cb else cb if ca == cb else 0
    print(a, b)

Python: def solve():
	while 1:
		n = int(input())
		if n==0:
			break
		score_a=0
		score_b=0
		while n>0:
			(a,b)=map(int, input().split())
			if a>b:
				score_a = score_a + a + b
			elif a<b:
				score_b = score_b + a + b
			else:
				score_a = score_a + a
				score_b = score_b + b
			n = n-1
		print(score_a, score_b)

if __name__ == '__main__':
	solve()

Python: def input_n(inputfile,outputfile):
	while True:
		n = inputfile.readline()
		n = int(n)
		if n == 0:
			break
		battle(inputfile,outputfile,n)

def battle(inputfile,outputfile,n):
	apoint = 0
	bpoint = 0
	for i in range(n):
		a , b = inputfile.readline().split()
		a = int(a)
		b = int(b)
		if a > b:
			apoint += (a + b)
		elif b > a:
			bpoint += (a + b)
		else:
			apoint += a
			bpoint += b
	print >> outputfile, apoint, bpoint

if __name__ == "__main__":
	import sys
	input_n(sys.stdin,sys.stdout)

Python: import sys
d=0
for e in sys.stdin:
 c=list(map(int,e.split()))
 if len(c)>1:
  s,t=c;d=1
  if s>t:a+=s+t
  elif s<t:b+=s+t
  else:a+=s;b+=t
 else:
  if d:print(a,b)
  a=b=0

Python: def solve(n, a):
    sum_a=0
    sum_b=0
    for i in range(n):
        if a[i][0]==a[i][1]:
            sum_a+=a[i][0]
            sum_b+=a[i][1]
        elif a[i][0]>a[i][1]:
            sum_a+=(a[i][0]+a[i][1])
        else:
            sum_b+=(a[i][0]+a[i][1])
    return sum_a, sum_b


while True:
    n = int(input())
    if n==0: break
    a=[[int(i) for i in input().split()] for i in range(n)]
    ans_1, ans_2 = solve(n,a)
    print (ans_1, ans_2)

Python: for i in range(5):
	n = int(input())
	if n == 0: break
	bcnt = acnt = 0
	for j in range(n):
		a, b = map(int, input().split())
		if a > b: acnt += a + b
		elif a < b:bcnt += a + b
		else:
			acnt += a
			bcnt += b
	print(acnt, bcnt)

Python: n = int(input())
while n != 0:
    A = 0
    B = 0
    for i in range(n):
        a, b = map(int, input().split())
        if a > b:
            A += a + b
        elif a < b:
            B += a + b
        else:
            A += a
            B += b
    print('{} {}'.format(A, B))
    n = int(input())

Python: 

array_first = []
array_second = []
array_turns = []

input_str = input()

while True:
    turns = int(input_str)

    if turns == 0:
        break

    array_turns.append(turns)

    for turn in range(turns):
        input_str = input()

        first = ''
        second = ''

        flag_space = False
        for i in range(len(input_str)):
            if input_str[i] == ' ':
                flag_space = True
                continue
            if not flag_space:
                first += (input_str[i])
            else:
                second += (input_str[i])

        array_first.append(int(first))
        array_second.append(int(second))

    input_str = input()

scores_first = []
scores_second = []
passed_turns = 0

for turns in array_turns:
    score_first = 0
    score_second = 0

    for turn in range(turns):
        if array_first[turn + passed_turns] > array_second[turn + passed_turns]:
            score_first += array_first[turn + passed_turns] + array_second[turn + passed_turns]
        elif array_first[turn + passed_turns] < array_second[turn + passed_turns]:
            score_second += array_first[turn + passed_turns] + array_second[turn + passed_turns]
        else:
            score_first += array_first[turn + passed_turns]
            score_second += array_second[turn + passed_turns]

    scores_first.append(score_first)
    scores_second.append(score_second)
    passed_turns += turns

for score_f, score_s in zip(scores_first, scores_second):
    print(score_f, ' ', score_s)