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

Python: # coding: utf-8

line = input()
while line != "0":
    gameCount = int(line)
    pointOfA = 0
    pointOfB = 0
    for count in range(gameCount):
        cardOfA, cardOfB = list(map(int, input().split(" ")))
        if cardOfA > cardOfB:
            pointOfA += cardOfA + cardOfB
        elif cardOfB > cardOfA:
            pointOfB += cardOfA + cardOfB
        else:
            pointOfA += cardOfA
            pointOfB += cardOfB
    print("{0} {1}".format(pointOfA, pointOfB))
    line = input()

Python: while True:
  n = int(input().rstrip())
  if n == 0:
    break
  A = 0
  B = 0
  while n > 0:
    line = input().rstrip()
    a,b = map(int,line.split())
    if a == b:
      A += a
      B += b
    elif a > b:
      A += (a+b)
    else:
      B += (a+b)
    n -= 1
  print(A,B)

Python: n = 1
while n!=0:
  A = 0
  B = 0
  n = int(input())
  if n == 0:
    break
  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('%d%s%d'%(A,' ',B))

Python: #----------------
# coding: utf-8
# Created:     20/08/2014
# Python 3+
#-----------------
import sys
#ff = open("test.txt", "r")
ff = sys.stdin

while (True) :

    n = int(ff.readline())
    if n == 0 : break

    p1 = 0
    p2 = 0

    for x in range(0, n):
        arr = list( map(int, ff.readline().split()) )
        sum = arr[0] + arr[1]

        if arr[0] == arr[1] :
            p1 += arr[0]
            p2 += arr[1]
        elif arr[0] > arr[1] :
            p1 += sum
        else :
            p2 += sum

    print("{0} {1}".format(p1, p2))

pass

Python: def main():
    sum_a = 0
    sum_b = 0
    while True:
        n = input()
        if n == '0':
            return 
        for i in range(int(n)):
            a,b = list(map(int, input().split()))
            if a > b:
                sum_a += a+b
            elif a < b:
                sum_b += a+b
            else:
                sum_a += a
                sum_b += b
        print(sum_a, sum_b)

if __name__ == '__main__':
    main()

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

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 idx, score in enumerate(zip(scores_first, scores_second)):
    print(score[0], score[1])

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

Python: while 1:
    n = int(input())
    if n == 0:
        break
    
    sum_a = 0
    sum_b = 0
    
    for i in range(n):
        a,b = map(int, 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: while True:
	n = int(input())
	if n == 0:
		break
	game = [[int(s) for s in input().split()] for i in range(n)]
	a,b = 0,0
	for g in game:
		if g[0] > g[1]:
			a += sum(g)
		elif g[0] < g[1]:
			b += sum(g)
		else:
			a += g[0]
			b += g[1]
	print(a,b)

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 foo(infile, outfile, n):
    ax = 0
    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 a < b:
            bx += (a + b)
        elif a == b:
            ax += a
            bx += b
        else:
            assert False
    print >> outfile, ax, bx


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


if __name__ == "__main__":
    import sys
    run(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: while True:
    N = int(input())
    if N == 0:
        break

    # ??????????????????????¨???????????????°?????????
    (a, b) = (0, 0)
    
    inputs = []

    # ???????????°???????????????
    for x in range(N):
        # ??????????????????????????????
        inputs.append(list(map(int, input().split())))

    for points in inputs:
        # ?????°?????????????????????????????°???????¨?????????????
        if points[0] == points[1]:
            a = a + points[0]
            b = b + points[1]
        elif points[0] > points[1]:
            a = a + points[0] + points[1]
        else:
            b = b + points[0] + points[1]

    # ????????????????????¨???
    print(a,b)

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

Python: while True:
	N=int(input())
	if N==0:
		break
	a,b=0,0
	for i in range(N):
		info=input().split()
		A,B=int(info[0]),int(info[1])
		if A>B:
			a+=(A+B)
		elif A<B:
			b+=(A+B)
		else:
			a+=A
			b+=B
	print(str(a)+" "+str(b))

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