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: A_cards, B_cards = [], []
A_result, B_result = 0, 0

while True:
    n = int(input())
    
    if n == 0:
        break

    for i in range(n):
        A, B = map(int, input().split())
        A_cards.append(A)
        B_cards.append(B)
        if A_cards[i] > B_cards[i]:
            A_result += A_cards[i] + B_cards[i]
        elif A_cards[i] < B_cards[i]:
            B_result += A_cards[i] + B_cards[i]
        elif A_cards[i] == B_cards[i]:
            A_result += A_cards[i]
            B_result += B_cards[i]
    print('{} {}'.format(A_result, B_result))
    
    A_cards, B_cards = [], []
    A_result, B_result = 0, 0

Python: def main():
    while True:
        n = int(input())
        player1 = 0
        player2 = 0
        if n == 0:
            break

        for i in range(n):
            str = input().split()
            right = int(str[0])
            left = int(str[1])

            if right > left:
                player1 += right + left
            elif right < left:
                player2 += right + left
            else:
                player1 += right
                player2 += left

        print("{0} {1}".format(player1, player2) )


if __name__=="__main__":
    main()

Python: import collections
import sys

l = collections.deque(sys.stdin.readlines())
l.pop()
s = ""
while l:
    a = 0
    b = 0
    for i in range(int(l.popleft())):
        x,y = map(int, l.popleft().split())
        if x > y:
            a = a + x + y
        elif x < y:
            b = b + x + y
        else:
            a = a+x
            b = b+y
    s += str(a) + " " + str(b) + "\n"

print(s,end="")

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
        elif B > A:
            B_sum += A + B
        else:
            A_sum += A
            B_sum += B
    print(A_sum, B_sum)

Python: def main():
    while 1:
        n = 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("%s %s" %(sum_a,sum_b))
                
if __name__ == "__main__":
    main()

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

Python: # 3
# 9 1
# 5 4
# 0 8
# 3
# 9 1
# 5 4
# 1 0
# 3
# 9 1
# 5 5
# 1 8
# 0

while True:
	n = int(input())
	if n == 0:
		exit(0)
	a, b = 0, 0
	for i in range(n):
		A = list(map(int, input().split()))
		if A[0] > A[1]:
			a = a + A[0] + A[1]
		elif A[0] < A[1]:
			b = b + A[0] + A[1]
		elif A[0] == A[1]:
			a, b = a + A[0], b + A[1]
	print('{0} {1}'.format(a, b))

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

Python: while True:
    n = int(input())
    if n == 0:
        break

    a_point = 0
    b_point = 0
    for _ in range(n):
        a, b = [int(x) for x in input().split()]

        if a > b:
            a_point += a + b
        elif a < b:
            b_point += a + b
        else:
            a_point += a
            b_point += b
    print(a_point, b_point)

Python: while True:
  n = int(input())
  if n == 0:
    break
  ascore = 0
  bscore = 0
  for i in range(n):
    a,b = list(map(int,input().split()))
    if a < b:
      bscore += a + b
    elif a > b:
      ascore += a + b
    elif a == b:
      ascore += a
      bscore += b
  print(f"{ascore} {bscore}")

Python: A_cards, B_cards = [], []
A_result, B_result = 0, 0

while True:
    n = int(input())
    
    if n == 0:
        break

    for i in range(n):
        A, B = map(int, input().split())
        A_cards.append(A)
        B_cards.append(B)
        if A_cards[i] > B_cards[i]:
            A_result += A_cards[i] + B_cards[i]
        elif A_cards[i] < B_cards[i]:
            B_result += A_cards[i] + B_cards[i]
        else:
            A_result += A_cards[i]
            B_result += B_cards[i]
    print('{} {}'.format(A_result, B_result))

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("%s %s" %(sum_a,sum_b))

Python: def _resulting(ab):
    a, b = 0, 0
    for itr in ab:
        if itr[0] > itr[1]:
            a = a + (itr[0] + itr[1])
        elif itr[0] < itr[1]:
            b = b + (itr[0] + itr[1])
        else:
            a = a + itr[0]
            b = b + itr[1]
    return a, b


if __name__ == '__main__':
    N = int(input())
    ab = []

    for itr in range(0, N):
        ab.append(list(map(int, input().split())))

    a, b = _resulting(ab)
    print(a, b)

Python: while(True):
    A=[]
    B=[]
    a=int(input())
    for i in range(a):
     b,c=map(int, input().split(' '))
     d=int(b)+int(c)
     if int(b)>int(c):
        A.append(int(d))
      
     if int(b)<int(c):
         B.append(int(d))

     if int(b)==int(c):
         A.append(int(b))
         B.append(int(c))

    
    if int(a)==0:
        break
    print(sum(A),sum(B))

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


def latte():
    return int(input())

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

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: import collections
import sys

l = collections.deque(sys.stdin.readlines())
l.pop()
s = ""
while l:
    a = 0
    b = 0
    for i in range(int(l.popleft())):
        x,y = map(int, l.popleft().split())
        if x > y:
            a = a + x + y
        elif x < y:
            b = b + x + y
        else:
            a += x
            b += y
    s += str(a) + " " + str(b) + "\n"

print(s,end="")

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
        if a <= b:
            score_b += b
    print("{} {}".format(score_a, score_b))

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