Problem:


A と B の 2 人のプレーヤーが， 0 から 9 までの数字が書かれたカードを使ってゲームを行う．最初に， 2 人は与えられた n 枚ずつのカードを，裏向きにして横一列に並べる．その後， 2 人は各自の左から 1 枚ずつカードを表向きにしていき，書かれた数字が大きい方のカードの持ち主が，その 2 枚のカードを取る．このとき，その 2 枚のカードに書かれた数字の合計が，カードを取ったプレーヤーの得点となるものとする．ただし，開いた 2 枚のカードに同じ数字が書かれているときには，引き分けとし，各プレーヤーが自分のカードを 1 枚ずつ取るものとする．

例えば， A，B の持ち札が，以下の入力例 1 から 3 のように並べられている場合を考えよう．ただし，入力ファイルは n + 1 行からなり， 1 行目には各プレーヤのカード枚数 n が書かれており， i + 1 行目（i = 1，2，... ，n）には A の左から i 枚目のカードの数字と B の左から i 枚目の カードの数字が，空白を区切り文字としてこの順で書かれている．すなわち，入力ファイルの 2 行目以降は，左側の列が A のカードの並びを，右側の列が B のカードの並びを，それぞれ表している．このとき，ゲーム終了後の A と B の得点は，それぞれ，対応する出力例に示したものとなる．

　入力ファイルに対応するゲームが終了したときの A の得点と B の得点を，この順に空白を区切り文字として 1 行に出力するプログラムを作成しなさい．ただし， n ≤ 10000 とする． 

 

  入力例１
   入力例２
   入力例３
 
 

333

9 19 19 1

5 45 45 5

0 81 01 8

  　

  出力例１
   出力例２
   出力例３

19 820 015 14

入力

入力は複数のデータセットからなる．n が 0 のとき入力が終了する．データセットの数は 5 を超えない．

出力

データセットごとに、A の得点と B の得点を１行に出力する．

入力例

3
9 1
5 4
0 8
3
9 1
5 4
1 0
3
9 1
5 5
1 8
0

出力例

19 8
20 0
15 14

各データセットの出力の後（Bの得点の後）に改行を入れること。

上記問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
3
9 1
5 4
0 8
3
9 1
5 4
1 0
3
9 1
5 5
1 8
0


Sample output:
19 8
20 0
15 14

Submission status: Accepted

Solution code:
# 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)

Submission status: Accepted

Solution code:
while True:
  n = int(input().rstrip())
  if n == 0:
    break
  A = 0
  B = 0
  while n > 0:
    line = input().rstrip()
    a,b = map(int,line.split())
    if a == b:
      A += a
      B += b
    elif a > b:
      A += (a+b)
    else:
      B += (a+b)
    n -= 1
  print(A,B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
 n = input()
 if n == 0:
  break
 s = [0]*2
 for i in xrange(n):
  r = [int(c) for c in raw_input().split()]
  if r[0] == r[1]:
   s[0]+=r[0];s[1]+=r[1]
  elif r[0] > r[1]:
   s[0]+=sum(r)
  else:
   s[1]+=sum(r)
 print s[0],s[1]

Submission status: Accepted

Solution code:
import sys

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

if __name__ == '__main__':
  solve()

Submission status: Accepted

Solution code:

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

if __name__ == '__main__':
  solve()

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    num_a = 0
    num_b = 0
    for j in range(n):
        ta, tb = map(int,raw_input().split())
        if ta > tb:
            num_a += (ta+tb)
        elif ta < tb:
            num_b += (ta+tb)
        else:
            num_a += ta
            num_b += tb
    print "%d %d" % (num_a, num_b)

Submission status: Accepted

Solution code:
__Author__ = 'Anomino'
# coding:UTF-8


def AskUser(number) : 
    player_A, player_B = [], []
    for value in range(0, number) : 
        answer = raw_input()
        answer = answer.split( )
        player_A.append(int(answer[0]))
        player_B.append(int(answer[1]))

    return player_A, player_B
    
def CalcScore(player_A, player_B) : 
    score_A, score_B = 0, 0

    for value in range(0, len(player_A)) : 
        if player_A[value] < player_B[value] : 
            score_B = score_B + player_A[value] + player_B[value]
        elif player_A[value] > player_B[value] : 
            score_A = score_A + player_A[value] + player_B[value]
        else : 
            score_A = score_A + player_A[value]
            score_B = score_B + player_B[value]

    return score_A, score_B

if __name__ == '__main__' : 
    total_A, total_B = [], []
    number = int(raw_input())

    while number != 0 :
        player_A, player_B = AskUser(number)
        score_A, score_B = CalcScore(player_A, player_B)
        total_A.append(score_A)
        total_B.append(score_B)
        number = int(raw_input())

    for value in range(0, len(total_A)) : 
        print total_A[value], total_B[value]

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    pointA, pointB = 0, 0
    for i in range(n):
        cardA, cardB = map(int, input().split())
        if cardA == cardB:
            pointA += cardA
            pointB += cardB
        elif cardA > cardB:
            pointA += cardA + cardB
        else:
            pointB += cardA + cardB
    print(pointA, pointB)

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        break

    # ??????????????????????¨???????????????°?????????
    (a, b) = (0, 0)
    
    inputs = []

    # ???????????°???????????????
    for x in range(N):
        # ??????????????????????????????
        inputs.append(list(map(int, input().split())))

    for points in inputs:
        # ?????°?????????????????????????????°???????¨?????????????
        if points[0] == points[1]:
            a = a + points[0]
            b = b + points[1]
        elif points[0] > points[1]:
            a = a + points[0] + points[1]
        else:
            b = b + points[0] + points[1]

    # ????????????????????¨???
    print(a,b)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while 1:
    n=input()
    if n==0:break
    ascore=0
    bscore=0
    for i in xrange(n):
        a,b=map(int,raw_input().split())
        if a>b:
            ascore+=a+b
        elif a==b:
            ascore+=a
            bscore+=b
        else:
            bscore+=a+b
    print ascore,bscore

Submission status: Accepted

Solution code:
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="")

Submission status: Accepted

Solution code:
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="")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n = input()
    if n == 0:
        break
    ATen = 0
    BTen = 0
    for i in range(n):
        A, B = map(int, raw_input().split())
        if A > B:
            ATen += A + B
        elif A < B:
            BTen += A + B
        elif A == B:
            ATen += A
            BTen += B
    print ATen, BTen

Submission status: Accepted

Solution code:
def solve(N):
    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)

while True:
    N = int(input())
    if N == 0:
        break
    solve(N)

Submission status: Accepted

Solution code:
while True:

  n = int(raw_input())

  if n == 0:
   break

  A_p = B_p = 0

  for i in range(n):

    A, B = map(int, raw_input().split())

    if A > B:
      A_p += (A + B)

    elif A == B:
      A_p += A
      B_p += B

    else:
      B_p += (A + B)

  print A_p, B_p

Submission status: Accepted

Solution code:
while True:

  n = int(raw_input())

  if n == 0:
   break

  A_score = B_score = 0

  for i in range(n):

    A, B = map(int, raw_input().split())

    if A > B:
      A_score += (A + B)

    elif A == B:
      A_score += A
      B_score += B

    else:
      B_score += (A + B)

  print A_score, B_score

Submission status: Accepted

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

Submission status: Accepted

Solution code:
score = []
while True:
    n = int(raw_input())
    a = 0
    b = 0
    if n == 0:
        break
    for i in range(0, n):
        line = raw_input()
        (ta, tb) = map(int, line.strip().split())
        if ta > tb:
            a += ta + tb
        elif ta < tb:
            b += ta + tb
        elif ta == tb:
            a += ta
            b += tb
    score.append([a, b])
for (a, b) in score:
    print a, b

Submission status: Accepted

Solution code:
while True:
	N=int(input())
	if N==0:
		break
	a,b=0,0
	for i in range(N):
		info=input().split()
		A,B=int(info[0]),int(info[1])
		if A>B:
			a+=(A+B)
		elif A<B:
			b+=(A+B)
		else:
			a+=A
			b+=B
	print(str(a)+" "+str(b))

Submission status: Accepted

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

n = int(input())

while n!=0 :
    #1??????????????¨?????????
    pointA=0
    pointB=0
    for i in range(n):
        x = list(map(int, input().split()))
        if x[0] == x[1]:
            pointA += x[0]
            pointB += x[1]
        elif x[0] > x[1]:
            pointA += x[0] + x[1]
        else:
            pointB += x[0] + x[1]
    
    print(pointA, pointB)
    n = int(input())

Submission status: Accepted

Solution code:
fin_a = []
fin_b = []
while True:
    x = int(input())
    if x == 0:
        break
    a = 0
    b = 0
    for i in range(x):
        l = list(map(int, input().split()))
        if l[0] > l[1]:
            a += l[0] + l[1]
        elif l[0] < l[1]:
            b += l[0] + l[1]
        else:
            a += l[0]
            b += l[1]
    fin_a.append(a)
    fin_b.append(b)
    
for x, y in zip(fin_a, fin_b):
    print(x, y)

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

Solution code:
n=int(input())
a_point=0
b_point=0
sum_list=[]
while(n!=0):
    list=[]
    for i in range(n):
        a,b=[int(i) for i in input().split()]
        if a>b:
            a_point+=(a+b)
        elif b>a:
            b_point+=(a+b)
        else:
            a_point+=a
            b_point+=b
    sum_list.append((a_point,b_point))
    a_point=0
    b_point=0
    n=int(input())

for i in range(len(sum_list)):
    print(sum_list[i][0],sum_list[i][1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
	n = input()
	if n == 0: break

	a = 0
	b = 0
	for _ in range(n):
		a_, b_ = map(int, raw_input().split())
		sum = a_ + b_
		if a_> b_: 
			a += sum
		elif b_ > a_: 
			b += sum
		else:
			a += a_
			b += b_
	print a, b

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
while n!=0:
    a=0
    b=0
    for i in range(n):
        x,y=[int(j) for j in input().split(" ")]
        if x>y:
            a+=x+y
        elif x<y:
            b+=x+y
        else:
            a+=x
            b+=y
    print("%d %d"%(a,b))
    n=int(input())

Submission status: Accepted

Solution code:
# coding: utf-8

line = input()
while line != "0":
    gameCount = int(line)
    pointOfA = 0
    pointOfB = 0
    for count in range(gameCount):
        cardOfA, cardOfB = list(map(int, input().split(" ")))
        if cardOfA > cardOfB:
            pointOfA += cardOfA + cardOfB
        elif cardOfB > cardOfA:
            pointOfB += cardOfA + cardOfB
        else:
            pointOfA += cardOfA
            pointOfB += cardOfB
    print("{0} {1}".format(pointOfA, pointOfB))
    line = input()

Submission status: Accepted

Solution code:
while True:
    n=int(raw_input())
    if n==0:
        break

    sum_a=0
    sum_b=0

    for i in xrange(n):
        a,b = (int(x) for x in raw_input().split())
        if a>b :
            sum_a += a+b
        elif a==b:
            sum_a += a
            sum_b += b
        else:
            sum_b += a+b
    print "%d %d" % (sum_a, sum_b)

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8                                                                  

def one_game():
    n = int(input())
    if n == 0:
        return False
    
    s = [list(map(int, input().split(' '))) for i in range(n)]

    win = {True: 0, False: 0}
    for a, b in s:
        if a == b:
            win[True] += a
            win[False] += a
            continue
        win[a>b] += (a + b)

    print(win[True], win[False])
    return True


while one_game() is True:
    a = 0

Submission status: Accepted

Solution code:
# 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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def calc():
    while 1:
        n = int(raw_input())
        if n <= 0:
            break
        a = 0
        b = 0
        while n > 0:
            ans = map(int, raw_input().split())
            if ans[0] > ans[1]:
                a += ans[0] + ans[1]
            elif ans[0] < ans[1]:
                b += ans [0] + ans[1]
            else:
                a += ans[0]
                b += ans[1]
            n -= 1
        print a, b
        
    
if __name__ == '__main__':
    calc()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
	n = int(input())
	if n == 0:
		break
	game = [[int(s) for s in input().split()] for i in range(n)]
	a,b = 0,0
	for g in game:
		if g[0] > g[1]:
			a += sum(g)
		elif g[0] < g[1]:
			b += sum(g)
		else:
			a += g[0]
			b += g[1]
	print(a,b)

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def main():
    for line in sys.stdin:
        n = int(line)
        if n == 0:
            break
        else:
            A = []
            B = []
            for _ in range(n):
                hoge, fuga = map(int, input().split())
                A.append(hoge)
                B.append(fuga)

            a, b = 0, 0
            for x in range(n):
                if A[x] == B[x]:
                    a += A[x]
                    b += B[x]
                else:
                    piyo = A[x] + B[x]
                    if A[x] > B[x]:
                        a += piyo
                    else:
                        b += piyo
            print(a, b)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

i = int(input().rstrip())
point = []
k = 0
while i :
    point.append([0, 0])
    for j in range(i):
        l = list(map(int, input().rstrip().split()))
        if l[0] > l[1]:
            point[k][0] += l[0] + l[1]
        elif l[0] < l[1]:
            point[k][1] += l[0] + l[1]
        else:
            point[k][0] += l[0]
            point[k][1] += l[1]
    i = int(input().rstrip())
    k += 1
for i in range(k):
    print(point[i][0],point[i][1])

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    i = input()
    if(i == 0):
        break
    li = []
    for x in xrange(i):
        li.append(map(int,raw_input().split()))
    ascore = 0
    bscore = 0
    for i in li:
        if(i[0] > i[1]):
            ascore += sum(i)
        elif (i[0] < i[1]):
            bscore += sum(i)
        else:
            ascore += i[0]
            bscore += i[1]
    print str(ascore) + " " + str(bscore)

Submission status: Accepted

Solution code:
# coding: utf-8

data_set = input()
while(data_set > 0):
    a = 0
    b = 0
    for i in range(data_set):
        num = map(int, raw_input().split())
        if num[0] > num[1]:
            a = a + sum(num)
        elif num[0] < num[1]:
            b = b + sum(num)
        else:
            a = a + num[0]
            b = b + num[1]
    print a,b
    data_set = input()

Submission status: Accepted

Solution code:

def battle_A_B(A,B):
	A_points = 0
	B_points = 0
	for i in range(len(A)):
		A_idx = int(A[i])
		B_idx = int(B[i])
		if A_idx > B_idx:
			A_points += (A_idx+B_idx)
		elif A_idx < B_idx:
			B_points += (A_idx+B_idx)
		else:	
			A_points += A_idx
			B_points += B_idx	
	insert = str(A_points)+" "+str(B_points) #+"\n"
	insert_list.append(insert)


insert_list = []
while(1):
	num = input()
	num = num.rstrip("\n")
	num_list = num.split(" ")
	if len(num_list) == 1:
		if int(num_list[0]) == 0:
			break
		battle_num = int(num_list[0])
		A = []
		B = []
	else:
		A.append(num_list[0])
		B.append(num_list[1])
		if len(A) == battle_num:
			battle_A_B(A,B)	

for i in range(len(insert_list)):
	print(insert_list[i])

Submission status: Accepted

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

        print str(c) + " " + str(d)

except:
    None

Submission status: Accepted

Solution code:
# 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))

Submission status: Accepted

Solution code:
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"])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
e=sys.stdin
while 1:
 a=b=0;n=int(e.readline())
 if n==0:break
 for i in[0]*n:
  s,t=map(int,e.readline().split())
  if s>t:a+=s+t
  elif s<t:b+=s+t
  else:a+=s;b+=t
 print(a,b)

Submission status: Accepted

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

Submission status: Accepted

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