Go: package main

import (
	"fmt"
)

// Game is one game.
type Game struct {
	pointA, pointB int
}

func main() {
	var n int
	game := &Game{0, 0}
	fmt.Scanf("%d", &n)
	for n != 0 {
		game.initGame()
		game.execGame(n)
		game.printResult()
		fmt.Scanf("%d", &n)
	}
}

func (game *Game) execGame(n int) {
	var a, b int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
		fmt.Scanf("%d", &b)
		switch {
		case a == b:
			game.pointA += a
			game.pointB += b
		case a > b:
			game.pointA += a + b
		case b > a:
			game.pointB += a + b
		}
	}
}

func (game *Game) initGame() {
	game.pointA = 0
	game.pointB = 0
}

func (game *Game) printResult() {
	fmt.Println(game.pointA, game.pointB)
}

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)

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

Python: while True:
    num = int(input())
    if num == 0:
        break
    else:
        numa = 0
        numb = 0
        for j in range(num):
            a,b = input().split(" ")
            if int(a) > int(b):
                numa += int(a) + int(b)
                continue
            if int(a) < int(b):
                numb += int(a) + int(b)
                continue
            if int(a) == int(b):
                numa += int(a)
                numb += int(b)
                continue
    print(str(numa) + " " + str(numb))

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 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
        elif a<b:
            bp+=a+b
        elif a==b:
            ap+=a
            bp+=b
    print(ap,bp)

Python: while True:
    card_num = int(input())
    if(card_num == 0):
        break
    a = 0
    b = 0
    for i in range(card_num):
        comp = input()
        if(int(comp[0]) == int(comp[2])):
            a += int(comp[0])
            b += int(comp[0])
        elif(int(comp[0]) > int(comp[2])):
            a += int(comp[0]) + int(comp[2])
        elif(int(comp[0]) < int(comp[2])):
            b += int(comp[0]) + int(comp[2])
    print(str(a)+' '+ str(b))

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

Python: Score = []

while True:
    A,B = 0,0
    n = int(input())
    if n == 0:
        break
    else:
        for i in range(n):
            a,b = list(map(int,input().split()))
            if a > b:
                A += a+b
            elif a < b:
                B += a+b
            elif a == b:
                A += a
                B += b
        Score.append([A,B])

for i in range(len(Score)):
    print(str(Score[i][0]) + " " + str(Score[i][1]))

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[0] += A
            score[1] += B
        else:
            score[A < B] += A+B
    print(*score)

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

Python: import sys
f = sys.stdin

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

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

Python: while True:
    n = int(input())
    if n == 0:break
    sumA = sumB = 0
    for i in range(n):
        c = list(map(int,input().split()))
        if c[0]==c[1]:
            sumA = sumA+c[0]
            sumB = sumB+c[1]
        else:
            sumA = sumA + (c[0]+c[1] if c[0]>c[1] else 0)
            sumB = sumB + (c[0]+c[1] if c[1]>c[0] else 0)
    print(sumA, sumB)

Python: def judge_game_set(game_num):
    a_point, b_point = 0, 0
    for _ in range(game_num):
        a_point, b_point = judge_game(a_point, b_point)
    print(a_point, b_point, sep=' ')

def judge_game(a_point, b_point):
    a_card, b_card = map(int, input().split(' '))

    if a_card > b_card:
        a_point += (a_card + b_card)
    elif a_card < b_card:
        b_point += (a_card + b_card)
    else:
        a_point += a_card
        b_point += b_card

    return a_point, b_point

def judge_game_sets():
    game_num = int(input())
    while game_num != 0:
        judge_game_set(game_num)
        game_num = int(input())

if __name__ == '__main__':
    judge_game_sets()

Python: import fileinput

input = fileinput.input()

while True:
    n = int(next(input).strip())
    if not n: break
    t = [0, 0]
    for _ in range(n):
        [a, b] = map(int, next(input).strip().split())
        if a == b:
            t[0] += a
            t[1] += b
        else:
            t[a < b] += a + b
    print(' '.join(map(str, t)))

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

Python: while 1:
	x = int(input())
	if x == 0:
		break
	else:
		a = 0
		b = 0
		for i in range(x):
			abStr = input().split(" ")
			ab = (int(abStr[0]), int(abStr[1]))
			if ab[0] < ab[1]:
				b += ab[0] + ab[1]
			elif ab[0] > ab[1]:
				a += ab[0] + ab[1]
			else:
				a += ab[0]
				b += ab[1]
		print(str(a) + " " + str(b))