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

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: import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

while(True):
    score = [0, 0]
    cards = []
    n = int(input())
    if n == 0:
        break

    for i in range(n):
        cards.append(list(map(int, input().split())))

    for i in range(n):
        if cards[i][0] > cards[i][1]:
            score[0] += sum(cards[i])
        elif cards[i][0] < cards[i][1]:
            score[1] += sum(cards[i])
        else:
            score[0] += cards[i][0]
            score[1] += cards[i][1]
    print(str(score[0]) + " " + str(score[1]))

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(1):
	n = int(input())
	if n == 0: break
	ap = 0
	bp = 0
	for i in range(n):
		a,b = map(int,input().split())
		if a > b: ap = a + b + ap
		elif a < b: bp = a + b + bp
		elif a == b: ap = a + ap; bp = b + bp
	print(ap,bp)

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 (b>a):
            B += (a+b)
        else:
            A+=a
            B+=b
    print("{} {}".format(A,B))
    n = int(input())

Python: # coding: utf-8
# Your code here!
def main():
    while True:
        sum_a = 0
        sum_b = 0
        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
    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]))

Python: import sys
for e in sys.stdin:
 a=b=0;n=int(e)
 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: 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: while True:
  A, B = 0, 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 %d'%(A,B))

Python: def evaluate_score(data):
    a_score = 0
    b_score = 0
    for a, b in data:
        if a > b:
            a_score += (a + b)
        elif b > a:
            b_score += (a + b)
        else:
            a_score += a
            b_score += b
    return a_score, b_score


if __name__ == '__main__':
    # ??????????????\???
    while True:
        data_num = int(input())
        if data_num == 0:
            break
        data = []
        for i in range(data_num):
            data.append([int(x) for x in input().split(' ')])

        # ???????????????
        a_scores, b_scores = evaluate_score(data)

        # ???????????¨???
        print('{0} {1}'.format(a_scores, b_scores))

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

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
    else:
      a_score += a
      b_score += b

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