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: # coding: utf-8
# Here your code !

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

Python: n = int(input())
while n > 0:
    A = 0
    B = 0
    for i in range(n):
        a,b = [int(j) for j in input().split(" ")]
        if a > b:
            A += (a+b)
        elif b > a:
            B += (a+b)
        else:
            A += a
            B += b
    print(A,B,sep=" ")
    n = int(input())

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

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) + '\n')

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

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

if __name__ == '__main__':
	solve()

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
	print >> outputfile, apoint, bpoint

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: def solve(n, a):
    sum_a=0
    sum_b=0
    for i in range(n):
        if a[i][0]==a[i][1]:
            sum_a+=a[i][0]
            sum_b+=a[i][1]
        elif a[i][0]>a[i][1]:
            sum_a+=(a[i][0]+a[i][1])
        else:
            sum_b+=(a[i][0]+a[i][1])
    return sum_a, sum_b


while True:
    n = int(input())
    if n==0: break
    a=[[int(i) for i in input().split()] for i in range(n)]
    ans_1, ans_2 = solve(n,a)
    print (ans_1, ans_2)

Python: for i in range(5):
	n = int(input())
	if n == 0: break
	bcnt = acnt = 0
	for j in range(n):
		a, b = map(int, input().split())
		if a > b: acnt += a + b
		elif a < b:bcnt += a + b
		else:
			acnt += a
			bcnt += b
	print(acnt, bcnt)

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('{} {}'.format(A, B))
    n = int(input())

Python: 

array_first = []
array_second = []
array_turns = []

input_str = input()

while True:
    turns = int(input_str)

    if turns == 0:
        break

    array_turns.append(turns)

    for turn in range(turns):
        input_str = input()

        first = ''
        second = ''

        flag_space = False
        for i in range(len(input_str)):
            if input_str[i] == ' ':
                flag_space = True
                continue
            if not flag_space:
                first += (input_str[i])
            else:
                second += (input_str[i])

        array_first.append(int(first))
        array_second.append(int(second))

    input_str = input()

scores_first = []
scores_second = []
passed_turns = 0

for turns in array_turns:
    score_first = 0
    score_second = 0

    for turn in range(turns):
        if array_first[turn + passed_turns] > array_second[turn + passed_turns]:
            score_first += array_first[turn + passed_turns] + array_second[turn + passed_turns]
        elif array_first[turn + passed_turns] < array_second[turn + passed_turns]:
            score_second += array_first[turn + passed_turns] + array_second[turn + passed_turns]
        else:
            score_first += array_first[turn + passed_turns]
            score_second += array_second[turn + passed_turns]

    scores_first.append(score_first)
    scores_second.append(score_second)
    passed_turns += turns

for score_f, score_s in zip(scores_first, scores_second):
    print(score_f, ' ', score_s)

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: while True:
    n = int(input())
    if n == 0:
        break
    a = 0
    b = 0
    for i in range(n):
        a1,b1 = map(int,input().split())
        if a1 > b1:
            a += a1+b1
        elif a1 < b1:
            b += a1+b1
        else:
            a += a1
            b += b1
    print(a,b)

Python: x = int(input())
score_A = 0
score_B = 0
ans = []
while x:
    for i in range(x):
        y = [int(i) for  i in input().split()]
        if y[0] > y[1]:
            score_A += sum(y)
        elif y[0] < y[1]:
            score_B += sum(y)
        else:
            score_A += y[0]
            score_B += y[1]
    ans.append([score_A,score_B])
    score_A = 0 ; score_B = 0
    x = int(input())
for i in ans:
    print(*i)

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