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: #!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    n = int(input())
    if n == 0:
        break
    A, B = 0, 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: 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("{0} {1}".format(A, B))
 n = int(input())

Python: #coding: utf-8                                                                  

def one_game():
    n = int(input())
    if n == 0:
        return False
    
    s = [list(map(int, input().split(' '))) for i in range(n)]

    win = {True: 0, False: 0}
    for a, b in s:
        if a == b:
            win[True] += a
            win[False] += a
            continue
        win[a>b] += (a + b)

    print(win[True], win[False])
    return True


while one_game() is True:
    a = 0

Python: while 1:
 a=b=0;n=int(input())
 if n:
  for i in[0]*n:
   s,t=map(int,input().split())
   if s>t:a+=s+t
   elif s<t:b+=s+t
   else:a+=s;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 += b
		elif a > b: A += a+b
		else:       B += a+b
	print(A, 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 True:
    n_line = input()
    if n_line == "0":
        break
    score_a, score_b = (0, 0)
    for i in range(int(n_line)):
        a, b = [int(x) for x in input().split(" ")]
        if a > b:
            score_a += a + b
        elif a < b:
            score_b += a + b
        else:
            score_a += a
            score_b += b
    print("{} {}".format(score_a, score_b))

Python: n=int(input())
while n!=0:
    a=0
    b=0
    for i in range(n):
        x,y=[int(j) for j in input().split(" ")]
        if x>y:
            a+=x+y
        elif x<y:
            b+=x+y
        else:
            a+=x
            b+=y
    print("%d %d"%(a,b))
    n=int(input())

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

Python: def solve(N):
    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)

while True:
    N = int(input())
    if N == 0:
        break
    solve(N)

Python: while True:
    x = int(input())
    if x != 0:
        resa = 0
        resb = 0
        for i in range(x):
            a, b = [int(i) for i in input().split()]
            if a > b:
                resa += a + b
            elif b > a:
                resb += a + b
            elif a == b:
                resa += a
                resb += b
        print(resa, resb)
    else:
        break

Python: while True:
    n = int(input())
    if n == 0: break
    sum_a = 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
        else:
            sum_a = sum_a + a
            sum_b = sum_b + b
    print(sum_a,sum_b)

Python: while 1:
    card_num = int(input())
    
    if card_num == 0:
        break

    pl_card = [input().split(" ") for i in range(card_num)]
    pl_l = 0
    pl_r = 0

    for i in pl_card:
        l = int(i[0])
        r = int(i[1])
        if l > r:
            pl_l = pl_l + (l+r)
        elif l < r:
            pl_r = pl_r + (l+r)
        elif l == r:
            pl_l = pl_l + l
            pl_r = pl_r + r
    print("{0} {1}".format(pl_l,pl_r))

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

Python: def main():
    while True:
        n = int(input())
        if n:
            aa,ba = 0,0
            a,b = [None]*n,[None]*n
            for i in range(n):
                a[i],b[i] = map(int, input().split())
                if a[i] > b[i]:
                    aa += (a[i]+b[i])
                elif a[i] < b[i]:
                    ba += (a[i]+b[i])
                else:
                    aa += a[i]
                    ba += b[i]
            print(aa,ba)
        else:
            break

if __name__ == '__main__':
    main()

Python: #coding: utf-8

n = int(input())
s = [list(map(int, input().split(' '))) for i in range(n)]

win = {True: 0, False: 0}
for a, b in s:
    win[a>b] += (a + b)

print(win[True], win[False])

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:a+=s+t
  elif s<t:b+=s+t
  else:a+=s;b+=t
 print(a,b)

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

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

Python: while True:
    try:
        n = int(input())
        scores = [0, 0]
        for i in range(n):
            cards = list(map(int, input().split()))
            if cards[0] > cards[1]:
                scores[0] += cards[0] + cards[1]
            elif cards[0] < cards[1]:
                scores[1] += cards[0] + cards[1]
            else:
                scores[0] += cards[0]
                scores[1] += cards[1]
        print(' '.join([str(score) for score in scores]))
    except EOFError:
        exit()

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