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

Solution code:
def main():
    sum_a = 0
    sum_b = 0
    while True:
        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()

Submission status: Wrong Answer

Solution code:
n=input()
a,b=[0,0]
for i in range(n):
    ai,bi=map(int,raw_input().split())
    if ai>bi:
        a+=ai+bi
    elif ai<bi:
        b+=ai+bi
    else:
        a+=ai
        b+=bi
print a,b

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = 0
b = 0

n = int(raw_input())

while n > 0:
    for _ in range(n):
        t_a, t_b = map(int, raw_input().split())
        if t_a > t_b:
            a += t_a + t_b
        elif t_a < t_b:
            b += t_a + t_b
        else:
            a += t_a
            b += t_b
    print "%d %d" % (a, b)
    n = int(raw_input())

Submission status: Wrong Answer

Solution code:
#! -*- coding:utf-8 -*-

import sys

n = 0
a_score = 0
b_score = 0
results = []
for line in sys.stdin:
    line = line.rstrip()
    sp_line = map(int, line.split(" "))
    if len(sp_line) == 1:
        if sp_line[0] == 0:
            for a,b in results:
                print "%s %s" % (a, b)
        else:
            results.append((a_score, b_score))
            a_score = 0
            b_score = 0
    else:
        a, b = sp_line
        if a > b:
            a_score += a+b
        if b > a:
            b_score += a+b
        if a == b:
            a_score += a
            b_score += b

print "%s %s" % (a_score, b_score)

Submission status: Wrong Answer

Solution code:
n=input()
d=0
e=0
for a in range(1, n+1):
	b,c=map(int,raw_input().split())
 	if b>c:
 		d=d+b+c
 	elif b<c:
 		e=e+b+c
	else:
 		d=d+c
 		e=e+c
print "%d %d" %(d,e)

Submission status: Wrong Answer

Solution code:
d=0
e=0
while True:
	n=input()
	if n==0:
		break
	else:
		for a in range(1, n+1):
			b,c=map(int,raw_input().split())
 			if b>c:
 				d=d+b+c
 			elif b<c:
 				e=e+b+c
			else:
 				d=d+c
 				e=e+c
print "%d %d" %(d,e)

Submission status: Wrong Answer

Solution code:
d=0
e=0
while True:
	n=input()
	if n==0:
		break
	else:
		for a in range(1, n+1):
			b,c=map(int,raw_input().split())
 			if b>c:
 				d=d+b+c
 			elif b<c:
 				e=e+b+c
			else:
 				d=d+c
 				e=e+c
 		print "%d %d" %(d,e)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

num_a = 0
num_b = 0
for i 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: Wrong Answer

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


def AskUser() : 
    # Ask to User players number and each player's score
    number = int(raw_input())
    
    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__' : 
    player_A, player_B = AskUser()
    score_A, score_B = CalcScore(player_A, player_B)

    print score_A, score_B

Submission status: Wrong Answer

Solution code:
n = int(input())
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(A,B)

Submission status: Wrong Answer

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

Solution code:
while True:
  try:
    n = int(raw_input())

  except EOFError:
    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: Wrong Answer

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

Submission status: Wrong Answer

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__':
    N = int(input())
    ab = []

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

    a, b = _resulting(ab)
    print(a, b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
roop = int(raw_input())
A = 0
B = 0
for i in xrange(roop):
	s = raw_input().rstrip().split(" ")
	cardA = int(s[0])
	cardB = int(s[1])
	if cardA>cardB:A+=(cardA+cardB)
	else: B+=(cardA+cardB)
print A,B

Submission status: Wrong Answer

Solution code:
while True:
	A = 0
	B = 0
	roop = int(raw_input())
	if roop<=0:break
	for i in xrange(roop):
		s = raw_input().rstrip().split(" ")
		cardA = int(s[0])
		cardB = int(s[1])
		if cardA>cardB:A+=(cardA+cardB)
		else: B+=(cardA+cardB)
	print A,B

Submission status: Wrong Answer

Solution code:
#coding: utf-8

n = int(input())
s = [list(map(int, input().split(' '))) for i in range(n)]

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

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

Submission status: Wrong Answer

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]
        else:
            A_result += A_cards[i]
            B_result += B_cards[i]
    print('{} {}'.format(A_result, B_result))

Submission status: Wrong Answer

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[1] < ans[0]:
                b += ans [0] + ans[1]
            else:
                a += ans[0]
                b += ans[1]
            n -= 1
        print a, b
        
    
if __name__ == '__main__':
    calc()

Submission status: Wrong Answer

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]
                print 'a', a
            elif ans[0] < ans[1]:
                b += ans [0] + ans[1]
                print 'b', b
            else:
                a += ans[0]
                b += ans[1]
            print a, b
            n -= 1
        print a, b
        
    
if __name__ == '__main__':
    calc()

Submission status: Wrong Answer

Solution code:
try:
    while True:
        n = 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 c + " " + d
except:
    None

Submission status: Wrong Answer

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
        elif A < B:
            score["B"] += B
        else:
            score["A"] += A
            score["B"] += B
    print(score["A"], score["B"])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
array_first = []
array_second = []

input_str = input()

while True:
    turns = int(input_str)

    if turns == 0:
        break

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

score_first = 0
score_second = 0

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

print(score_first, ' ', score_second)

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n = int(input())
        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]))
    except EOFError:
        exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = 0
b = 0
n = input()
i = 0
while i != n:
    set = raw_input().split()

    if int(set[0]) == int(set[1]):
        a += int(set[0])
        b += int(set[0])                 
      
    elif int(set[0]) > int(set[1]):
        a += int(set[0])
        a += int(set[1])

    else:
        b += int(set[0])
        b += int(set[1])

    i += 1

print a,b

Submission status: Wrong Answer

Solution code:
a = 0
b = 0
n = input()
i = 0
while i != n:
    set = raw_input().split()

    if int(set[0]) == int(set[1]):
        a += int(set[0])
        b += int(set[0])                 
      
    elif int(set[0]) > int(set[1]):
        a += int(set[0])
        a += int(set[1])

    else:
        b += int(set[0])
        b += int(set[1])

    i += 1

print a,b
print

Submission status: Wrong Answer

Solution code:
a = 0
b = 0
n = input()
i = 0
if n != 0:
    while i != n:
        set = raw_input().split()

        if int(set[0]) == int(set[1]):
            a += int(set[0])
            b += int(set[0])                 
      
        elif int(set[0]) > int(set[1]):
            a += int(set[0])
            a += int(set[1])

        else:
            b += int(set[0])
            b += int(set[1])

        i += 1

    print a,b
else:
    n=0

Submission status: Wrong Answer

Solution code:
a = 0
b = 0
n = input()
i = 0
if n != 0:
    while i != n:
        set = raw_input().split()
        set[0] = int(set[0])
        set[1] = int(set[1])

        if set[0] == set[1]:
            a += set[0]
            b += set[1]

        elif set[0] > set[1]:
            a += ( set[0] + set[1] )
        else:
            b += ( set[0] + set[1] )

        i += 1

    print a,b
else:
    n=0

Submission status: Wrong Answer

Solution code:
import string
a = 0
b = 0
n = input()
i = 0
if n != 0:
    while i != n:
        set = raw_input().split()
        set[0] = int(set[0])
        set[1] = int(set[1])

        if set[0] == set[1]:
            a += set[0]
            b += set[1]

        elif set[0] > set[1]:
            a += ( set[0] + set[1] )
        else:
            b += ( set[0] + set[1] )

        i += 1

    print a,b
else:
    n=0

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
n=int(raw_input())
pa,pb=0,0
a,b=[0]*n,[0]*n
for i in range(n):
    a[i],b[i] = map(int,raw_input().split())

ab=zip(a,b)
for a,b in ab:
    if a<b:
        pb+=(a+b)
    elif a>b:
        pa+=(a+b)
    else:
        pa,pb=pa+a,pb+b

print pa, pb

Submission status: Wrong Answer

Solution code:
import sys

n = int(sys.stdin.readline())

score_a = 0
score_b = 0

for i in range(n):
    a, b = map(int, sys.stdin.readline().strip().split())
    
    if a < b:
        score_b += b + a
    elif a > b:
        score_a += a + b
    else:
        score_a += a
        score_b += b

print score_a, score_b

Submission status: Wrong Answer

Solution code:
n = input()

player1 = 0
player2 = 0
for i in range(n):
    line = map(int, raw_input().split())
    if line[0] > line[1]:
        player1 += sum(line)
    elif line[0] == line[1]:
        player1 += line[0]
        player2 += line[1]
    else:
        player2 += sum(line)
print "%d %d" % (player1, player2)

Submission status: Wrong Answer

Solution code:
# coding: utf8

import sys

for line in sys.stdin:
    cols = unicode(line, 'utf8').split(u' ')
    
    if len(cols) == 1:
        i = 0
        n = int(cols[0])
        
        if n == 0: 
            break
        
        score_a, score_b = 0, 0
        continue
    
    if i == n:
         print score_a, score_b
         continue
         
    a, b = int(cols[0]), int(cols[1])
    
    if a < b:
        score_b += (a + b)
    elif a == b:
        score_a += a
        score_b += b
    else:
        score_a += (a + b)
        
    i += 1

Submission status: Wrong Answer

Solution code:
ap=bp=0
for i in range(input()):
	a,b=map(int,raw_input().split())
	if a>b:ap+=a+b
	elif a<b:bp+=a+b
	else:ap+=a;bp+=b
print ap,bp

Submission status: Time Limit Exceeded

Solution code:
import sys

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0: break
    sum_a = 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
        else:
            sum_a = sum_a + a
            sum_b = sum_b + b
    print(sum_a,sum_b)

Submission status: Accepted

Solution code:
while 1:
    n = int(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))

Submission status: Accepted

Solution code:
while 1:
    n = int(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(sum_a,sum_b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n=input()
    if n==0:
        break
    a,b=[0,0]
    for i in range(n):
        ai,bi=map(int,raw_input().split())
        if ai>bi:
            a+=ai+bi
        elif ai<bi:
            b+=ai+bi
        else:
            a+=ai
            b+=bi
    print a,b

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#----------------
# coding: utf-8
# Created:     20/08/2014
# Python 3+
#-----------------
import sys
#ff = open("test.txt", "r")
ff = sys.stdin

while (True) :

    n = int(ff.readline())
    if n == 0 : break

    p1 = 0
    p2 = 0

    for x in range(0, n):
        arr = list( map(int, ff.readline().split()) )
        sum = arr[0] + arr[1]

        if arr[0] == arr[1] :
            p1 += arr[0]
            p2 += arr[1]
        elif arr[0] > arr[1] :
            p1 += sum
        else :
            p2 += sum

    print("{0} {1}".format(p1, p2))

pass

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(raw_input())

while n > 0:
    a = 0
    b = 0
    for _ in range(n):
        t_a, t_b = map(int, raw_input().split())
        if t_a > t_b:
            a += t_a + t_b
        elif t_a < t_b:
            b += t_a + t_b
        else:
            a += t_a
            b += t_b
    print "%d %d" % (a, b)
    n = int(raw_input())

Submission status: Accepted

Solution code:
#! -*- coding:utf-8 -*-

import sys

n = 0
a_score = 0
b_score = 0
results = []
init = 1
for line in sys.stdin:
    line = line.rstrip()
    sp_line = map(int, line.split(" "))
    if len(sp_line) == 1:
        if init:
            init = 0
        else:
            results.append((a_score, b_score))
            a_score = 0
            b_score = 0
        if sp_line[0] == 0:
            for a,b in results:
                print "%s %s" % (a, b)

    else:
        a, b = sp_line
        if a > b:
            a_score += a+b
        if b > a:
            b_score += a+b
        if a == b:
            a_score += a
            b_score += b

Submission status: Accepted

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

Submission status: Accepted

Solution code:
i = int(raw_input())
while i:
    a_point = 0
    b_point = 0
    for count in range(i):
        a, b = map(int, raw_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,
    print b_point
    i = int(raw_input())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    n = int(input())
    if n == 0:
        break
    A, B = 0, 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 True:
	n=input()
	if n==0:
		break
	else:
		d=0
		e=0
		for a in range(1, n+1):
			b,c=map(int,raw_input().split())
 			if b>c:
 				d=d+b+c
 			elif b<c:
 				e=e+b+c
			else:
 				d=d+c
 				e=e+c
 		print "%d %d" %(d,e)

Submission status: Accepted

Solution code:
def main():
    while True:
        n = int(input())
        player1 = 0
        player2 = 0
        if n == 0:
            break

        for i in range(n):
            str = input().split()
            right = int(str[0])
            left = int(str[1])

            if right > left:
                player1 += right + left
            elif right < left:
                player2 += right + left
            else:
                player1 += right
                player2 += left

        print("{0} {1}".format(player1, player2) )


if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
while True:
    n = input()
    if n == 0:
        break
    a = []
    b = []
    sa = 0
    sb = 0
    for i in range(0, n):
        card = map(int, raw_input().split())
        a.append(card[0])
        b.append(card[1])
    for i in range(0, n):
        if a[i] > b[i]:
            sa += a[i] + b[i]
        elif a[i] < b[i]:
            sb += a[i] + b[i]
        else:
            sa += a[i]
            sb += a[i] 
    print sa, sb

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0: break
    a = b = 0
    for i in range(n):
        pa, pb = map(int, raw_input().split())
        if pa > pb:
            a += pa+pb
        elif pa == pb:
            a += pa
            b += pb
        elif pa < pb:
            b += pa+pb
    else:
        print a, b

Submission status: Accepted

Solution code:
while True:
    x = raw_input(); x = int(x);
    if x == 0: break
    sa = 0; sb = 0;
    for i in xrange(x):
        a,b = map(int, raw_input().split())
        if a < b: sb += a + b
        elif b < a: sa += a + b
        else: sa += a; sb += b;
    print sa, sb

Submission status: Accepted

Solution code:
while(1):
	count = input()
	if(count == 0):
		break
	else:
		a, b = 0, 0

		for i in range(count):
			l = map(int, raw_input().split())
			if(l[0]>l[1]):
				a += l[0]
				a += l[1]
			elif(l[0]<l[1]):
				b += l[0]
				b += l[1]
			else:
				a += l[0]
				b += l[1]

		print a,b