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

Python: # coding: utf-8

while True:
	n = int(raw_input())
	if n == 0:
		break
	a = 0
	b = 0
	for i in range(n):
		cards = map(int, raw_input().split())
		if cards[0] > cards[1]:
			a += cards[0] + cards[1]
		elif cards[0] < cards[1]:
			b += cards[0] + cards[1]
		else: #cards[0] == cards[1]
			a += cards[0]
			b += cards[1]
	print("{:} {:}".format(a,b))

Python: while True:
  n = int(input())
  if n == 0:
    break
  a = 0
  b = 0
  for _ in range(n):
    s1,s2 = map(int,input().split())
    if s1 > s2:
      a += (s1 + s2)
    elif s2 > s1:
      b += (s1 + s2)
    else:
      a += s1
      b += s2
  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: if __name__ == "__main__":

    while True:
        n = int(input())
        if n == 0:
            break
        else:
            g = []
            #print(n)
            sa = sb = 0
            for i in range(n):
                a, b = map(int, input().strip("\n").split(" "))
                #print(a, b)
                if a > b:
                    sa += (a + b)
                elif b > a:
                    sb += (a + b)
                else:  # a==b
                    sa += a
                    sb += b
            print(sa,sb)
pass

Python: while True:
    n = int(input())
    if n == 0:
        break
    a_score = 0
    b_score = 0
    for i in range(0,n):
        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: 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+B
        elif A < B:
            score["B"] += A+B
        else:
            score["A"] += A
            score["B"] += B
    print(score["A"], score["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__':
    while True:
        N = int(input())
        if N != 0:
            ab = []

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

            a, b = _resulting(ab)

            print(a, b)
        else:
            break

Python: a_score, b_score = 0, 0
while(True):
  input_list = map(int, raw_input().split())
  if len(input_list) == 1 and input_list[0] == 0:
    break
  elif len(input_list) == 1 and input_list[0] != 0:
    if a_score != 0 or b_score != 0:
      print(a_score, b_score)
    a_score, b_score = 0, 0
  elif len(input_list) == 2:
    a, b = input_list
    if a > b:
      a_score += a + b
    elif b > a:
      b_score += a + b
    elif a == b:
      a_score += a
      b_score += b

Python: num_of_d = 1
while True:

    n = input()
    n = int(n)

    score_a = 0
    score_b = 0

    if n < 0 or n > 10000:
        continue
    if n == 0:
        break
    if num_of_d > 5:
        break
        
    for i in range(0, n):


        a, b = list(map(int, input().split()))
        a = int(a)
        b = int(b)

        if a > b:
            score_a += a+b
        elif a < b:
            score_b += a+b
        else :
            score_a += a
            score_b += b

    num_of_d += 1
    print('{0} {1}' .format(score_a, score_b))

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

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

    score_a = 0
    score_b = 0
    for _ in range(n):
        a, b = map(int, input().split())
        if a > b:
            score_a += a + b
        elif a < b:
            score_b += a + b
        else:
            score_a += a
            score_b += b

    print(score_a, score_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: n = input()
a_cnt = 0
b_cnt = 0
for i in range(n) :
    arr = input().split(" ")
    num = [int(n) for n 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: import sys
e=iter(sys.stdin)
while 1:
 a=b=0;n=int(e)
 if n==0:break
 for i in[0]*n:
  s,t=map(int,e.split())
  if s>t:a+=s+t
  elif s<t:b+=s+t
  else:a+=s;b+=t
 print(a,b)

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
    print(a,b)

Python: def main():
    while True:
        N = int(input())
        if N == 0:
            return
        ap, bp = 0, 0
        for i in range(N):
            a, b = map(int, input().split())
            if a > b:
                ap += a + b
            elif a < b:
                bp += a + b
            else:
                ap += a
                bp += b

        print(ap, bp)


if __name__ == '__main__':
    main()

Python: while True:
    row_num = int(input().strip())
    if row_num == 0:
        break

    user1, user2 = 0, 0
    for i in range(row_num):
        cards = [int(x) for x in input().strip().split(' ')]
        if cards[0] > cards[1]:
            user1 += sum(cards)
        elif cards[0] < cards[1]:
            user2 += sum(cards)
        else:
            user1 += cards[0]
            user2 += cards[1]
    print(user1, user2)