Problem:


リーグ戦のスコアシート

スポーツの大会にはリーグ戦とトーナメント戦があります。サッカーのリーグ戦では勝・負・引分にそれぞれ点数を付け、その勝ち点で順位を競います。勝ち点はそれぞれ勝(3点)、負(0点)、引分(1点)です。 

チーム数とリーグ戦の成績を入力とし、成績の良い順(勝ち点の多い順)に並べ替え、チーム名と勝ち点を出力するプログラムを作成してください。勝ち点が同点の場合は入力順に出力してください。

Input

複数のデータセットが与えられます。各データセットは以下の形式で与えられます。

n
name1 w1 l1 d1
name2 w2 l2 d2
:
namen wn ln dn

１行目にチーム数 n (n ≤ 10) が与えられます。続く n 行にチーム i の名前 namei (20文字以内のアルファベット)、勝の数 wi、負の数 li、引分の数 di (0 ≤ wi, li, di ≤ 9) が空白区切りで与えられます。

チーム数が 0 のとき、入力の終了とします。データセットの数は 50 を超えません。

Output

データセットごとに、並べ替えたチームのリストを出力してください。i 行目に i 番目のチームの名前と勝ち点をカンマで区切って出力してください。

データセットの間に１つの空行を入れてください。

Sample Input

4
Japan 1 0 2
Egypt 1 2 0
Canada 0 2 1
Spain 2 0 1
3
India 0 2 0
Poland 1 0 1
Italy 1 0 1
0

Output for the Sample Input

Spain,7
Japan,5
Egypt,3
Canada,1

Poland,4
Italy,4
India,0



Sample input:
4
Japan 1 0 2
Egypt 1 2 0
Canada 0 2 1
Spain 2 0 1
3
India 0 2 0
Poland 1 0 1
Italy 1 0 1
0


Sample output:
Spain,7
Japan,5
Egypt,3
Canada,1

Poland,4
Italy,4
India,0

Submission status: Wrong Answer

Solution code:
first = True
while True:
    n = input()
    res = []
    if n==0:
        break
    if not first:
        print
    for i in xrange(n):
        res.append((lambda s: (3*int(s[1])+int(s[3]), s[0]))(raw_input().split()))
    res.sort(reverse=True)
    for e in res:
        print "%s,%d" % (e[1], e[0])
    first = False

Submission status: Wrong Answer

Solution code:
while True:
    n = int(input())
    if n==0:break
    d=dict()
    for _ in range(n):
        t = input().split()
        d[t[0]]=int(t[1])*3+int(t[3])*1
    print()
    for s in sorted(d.items(), key=lambda x:x[1])[::-1]:
        print(s[0]+','+str(s[1]))

Submission status: Wrong Answer

Solution code:
b=False
while True:
    n = int(input())
    if n==0:break
    d=dict()
    for _ in range(n):
        t = input().split()
        d[t[0]]=int(t[1])*3+int(t[3])*1
    if b:print()
    b=True
    for s in sorted(d.items(), key=lambda x:x[1])[::-1]:
        print(s[0]+','+str(s[1]))

Submission status: Wrong Answer

Solution code:
b=False
while True:
    n = int(input())
    if n==0:break
    d=dict()
    if b:print()
    for _ in range(n):
        t = input().split()
        d[t[0]]=int(t[1])*3+int(t[3])*1
    b=True
    for s in sorted(d.items(), key=lambda x:x[1])[::-1]:
        print(s[0]+','+str(s[1]))

Submission status: Wrong Answer

Solution code:
b=False
while True:
    n = int(input())
    if n==0:break
    d=dict()
    if b:print()
    for _ in range(n):
        t = input().split()
        d[t[0]]=int(t[1])*3+int(t[3])*1
    b=True
    for s in sorted(d.items(), key=lambda x:x[1])[::-1]:
        print('{0},{1}'.format(s[0],s[1]))

Submission status: Wrong Answer

Solution code:
b=False
while True:
    n = int(input())
    if n==0:break
    d=dict()
    if b:print()
    for _ in range(n):
        t = input().split()
        d[t[0]]=int(t[1])*3+int(t[3])*1
    b=True
    for s in sorted(d.items(), key=lambda x:x[1])[::-1]:
        print('{0},{1}'.format(s[0],s[1]))
    print()

Submission status: Wrong Answer

Solution code:
b=False
while True:
    n = int(input())
    if n==0:break
    d=dict()
    if b:print()
    b=True
    for _ in range(n):
        t = input().split()
        d[t[0]]=int(t[1])*3+int(t[3])*1
    for s in sorted(d.items(), key=lambda x:x[1])[::-1]:
        print('{0},{1}'.format(s[0],s[1]))

Submission status: Wrong Answer

Solution code:
b=False
while True:
    n = int(input())
    if n==0:break
    d=dict()
    if b:print()
    b=True
    for _ in range(n):
        line = input().split()
        tmp = int(line[1])*3+int(line[3]*1)
        if tmp in d:
            d[tmp].append(line[0])
        else:
            d[tmp] = []
            d[tmp].append(line[0])
    for k, vs in sorted(d.items(), key=lambda x: x[0])[::-1]:
        for v in vs:
            print('{0},{1}'.format(k, v))

Submission status: Wrong Answer

Solution code:
while 1:
	n=input()
	if n==0:break
	m=[raw_input().split() for i in range(n)]
	p={}
	for t in m:
		p[t[0]] = 3*int(t[1])+1*int(t[2])
	for k,v in sorted(p.items(),key=lambda x:x[1])[::-1]:
		print "%s,%d"%(k,v)
	print ""

Submission status: Wrong Answer

Solution code:
while 1:
	n=input()
	if n==0:break
	m=[raw_input().split() for i in range(n)]
	p={}
	for t in m:
		p[t[0]] = 3*int(t[1])+1*int(t[3])
	for k,v in sorted(p.items(),key=lambda x:x[1])[::-1]:
		print "%s,%d"%(k,v)
	print ""

Submission status: Wrong Answer

Solution code:
c=0
while 1:
	n=input()
	if n==0:break
	if c>0:print "" 
	m=[raw_input().split() for i in range(n)]
	p={}
	for t in m:
		p[t[0]] = 3*int(t[1])+1*int(t[3])
	for k,v in sorted(p.items(),key=lambda x:x[1])[::-1]:
		print "%s,%d"%(k,v)
	c+=1

Submission status: Wrong Answer

Solution code:
n=input()
while 1:
	m=[raw_input().split() for i in range(n)]
	p={}
	for t in m:
		p[t[0]] = 3*int(t[1])+1*int(t[3])
	for k,v in sorted(p.items(),key=lambda x:x[1])[::-1]:
		print "%s,%d"%(k,v)
	n=input()
	if n==0:break
	print

Submission status: Wrong Answer

Solution code:
n=input()
while 1:
	p={}
	for i in range(n):
		t=raw_input().split()
		p[t[0]] = [3*int(t[1])+1*int(t[3]),i]
	for k,v in sorted(p.items(),key=lambda x:x[1])[::-1]:
		print "%s,%d"%(k,v[0])
	n=input()
	if n==0:break
	print

Submission status: Accepted

Solution code:
f=0
while 1:
  n=input()
  if n==0: break
  if f>0: print
  N=[""]*n
  C=[0]*n
  for i in range(n):
    s=raw_input()
    p=s.index(" ")
    N[i]=s[:p]
    a,b,c=map(int,s[p+1:].split(" "))
    C[i]=(i,a*3+c)
  C=sorted(C,key=lambda x:(-x[1],x[0]))
  for e in C: print "".join([N[e[0]],",",str(e[1])])
  f=1

Submission status: Accepted

Solution code:
f=0
while 1:
  n=input()
  if n==0: break
  if f>0: print
  C=[()]*n
  for i in range(n):
    s=raw_input()
    p=s.index(" ")
    a,b,c=map(int,s[p+1:].split(" "))
    C[i]=(i,a*3+c,s[:p])
  C=sorted(C,key=lambda x:(-x[1],x[0]))
  for e in C: print e[2]+","+str(e[1])
  f=1

Submission status: Accepted

Solution code:
f=0
while 1:
  n=input()
  if n==0: break
  C=[()]*n
  for i in range(n):
    s=raw_input()
    p=s.index(" ")
    a,b,c=map(int,s[p+1:].split(" "))
    C[i]=(i,a*3+c,s[:p])
  C=sorted(C,key=lambda x:(-x[1]))
  if f>0: print
  for e in C: print e[2]+","+str(e[1])
  f=1

Submission status: Accepted

Solution code:
f=0
while 1:
  n=input()
  if n==0: break
  C=[()]*n
  for i in range(n):
    s=raw_input().split(" ")
    C[i]=(i,int(s[1])*3+int(s[3]),s[0])
  C=sorted(C,key=lambda x:(-x[1]))
  if f>0: print
  for e in C: print e[2]+","+str(e[1])
  f=1

Submission status: Accepted

Solution code:
f=0
while 1:
  n=input()
  if n==0: break
  C=[()]*n
  for i in range(n):
    a,b,c,d=raw_input().split(" ")
    C[i]=(i,int(b)*3+int(d),a)
  C=sorted(C,key=lambda x:(-x[1]))
  if f>0: print
  for e in C: print e[2]+","+str(e[1])
  f=1

Submission status: Accepted

Solution code:
first = True
while True:
    n = input()
    res = []
    if n==0:
        break
    if not first:
        print
    for i in xrange(n):
        res.append((lambda s: (s[0], 3*int(s[1])+int(s[3])))(raw_input().split()))
    res.sort(cmp=lambda x, y: y[1]-x[1])
    for e in res:
        print "%s,%d" % (e[0], e[1])
    first = False

Submission status: Accepted

Solution code:
N = input()
while True:
    dic = {}
    for i in range(N):
        lis = raw_input().split()
        dic[lis[0]] = [3*int(lis[1])+int(lis[3]), N-i]
    
    for k, v in sorted(dic.items(), key=lambda x: (x[1][0], x[1][1]), reverse=True):
        print '%s,%s' % (k, v[0])

    N = input()
    if N == 0: break
    print

Submission status: Accepted

Solution code:
f=0
while 1:
    a={}
    n=int(input())
    if n==0:break
    if f:print()
    f=1
    for i in range(n):
        b=input().split()
        a[b[0]]=[int(b[1])*3+int(b[3]),-i]
    for y,z in sorted(a.items(),key=lambda x:x[1])[::-1]:
        print('%s,%d'%(y,z[0]))

Submission status: Accepted

Solution code:
b=False
while True:
    n = int(input())
    if n==0:break
    d=dict()
    if b:print()
    b=True
    for _ in range(n):
        line = input().split()
        tmp = int(line[1])*3+int(line[3]*1)
        if tmp in d:
            d[tmp].append(line[0])
        else:
            d[tmp] = []
            d[tmp].append(line[0])
    for k, vs in sorted(d.items(), key=lambda x: x[0])[::-1]:
        for v in vs:
            print('{0},{1}'.format(v, k))

Submission status: Accepted

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

import sys
import os
import math

for i, s in enumerate(sys.stdin):
    n = int(s)
    if n == 0:
        break
    elif i != 0:
        print()

    A = []

    for i in range(n):
        lst = input().split()
        name = lst[0]
        w = int(lst[1])
        l = int(lst[2])
        d = int(lst[3])
        score = 3 * w + d
        A.append((score, -i, name))
    A.sort(reverse=True)

    for a in A:
        score = a[0]
        name = a[2]
        print('{},{}'.format(name, score))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0124
"""
import sys
from operator import itemgetter


def solve(data):
    result = []
    for name, win, lose, draw in data:
        score = win * 3 + draw * 1
        result.append([name, score])
    result.sort(key=itemgetter(1), reverse=True)
    return result


def main(args):
    first_data_set = True
    while True:
        n = int(input())
        if n == 0:
            break
        data = []
        for _ in range(n):
            name, win, lose, draw = input().split()
            data.append([name, int(win), int(lose), int(draw)])
        result = solve(data)
        
        if first_data_set:
            first_data_set = False
        else:
            print()
        for r in result:
            print(','.join(map(str, r)))


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# Aizu Problem 00124: League Match Score Sheet
#
import sys, math, os, copy

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


first = True
while True:
    N = int(input())
    if N == 0:
        break
    if first:
        first = False
    else:
        print()
    scoresheet = []
    for n in range(N):
        s = input().split()
        team = s[0]
        won = int(s[1])
        draw = int(s[3])
        scoresheet.append([team, n, 3 * won + draw])
    scoresheet = sorted(scoresheet, key=lambda x: (-x[2], x[1]))
    for team, n, points in scoresheet:
        print("%s,%d" % (team, points))

Submission status: Accepted

Solution code:
b = False
while True:
    n = int(input())
    if n == 0:
        break
    dataset = []
    if b:
        print()
    b = True
    for _ in range(n):
        name, w, l, d = input().split()
        dataset.append((name, 3*int(w) + int(d), n-len(dataset)))
    for name, score, _ in sorted(dataset, key=lambda x: (x[1], x[2]))[::-1]:
        print(name + "," + str(score))

Submission status: Accepted

Solution code:
isPrint = False

while True:

    inputCount = int(input())

    if inputCount == 0:
        break

    if isPrint:
        print()
    else:
        isPrint = True

    matchList = []

    for lp in range(inputCount):

        name, win, lose, draw = [item for item in input().split(" ")]
        score = int(win) * 3 + int(draw)

        matchList.append([name, score])

    matchList.sort(key=lambda item: -item[1])

    for name, score in matchList:
        print(name + "," + str(score))

Submission status: Accepted

Solution code:
class Team():

    def __init__(self, a, b):
        self.name = a
        self.score = b

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

    if flag:
        print("")
    else:
        flag = True

    teams = []
    for l in range(N):
        a,b,c,d = input().split()
        team = Team(a, int(b)*3 + int(d))
        teams.append(team)

    teams = sorted(teams, key=lambda u: u.score, reverse = True)
    for l in range(len(teams)):
        print(teams[l].name,end="")
        print(",",end="")
        print(teams[l].score)

Submission status: Accepted

Solution code:
from collections import defaultdict
is_init = True
while True:
  n = int(input())
  if n == 0:
    break
  
  if is_init:
    is_init = False
  else:
    print()

  result = defaultdict(list)
  scores = set()
  for _ in range(n):
    name, w, l, d = input().split()
    score = int(w) * 3 + int(d)
    result[score].append(name)
    scores.add(score)
  
  scores = sorted(list(scores), reverse=True)
  for score in scores:
    for name in result[score]:
      print(name, score, sep=",")

Submission status: Accepted

Solution code:
# AOJ 0124 League Match Score Sheet
# Python3 2018.6.21 bal4u

f = True
while True:
	n = int(input())
	if n == 0: break
	tbl = []
	for i in range(n):
		name, w, l, d = list(input().split())
		tbl.append([name, i, 3*int(w)+int(d)])
	if f: f = False
	else: print()
	for i in sorted(tbl, key=lambda x:(-x[2],x[1])): print(i[0], ',', i[2], sep='')

Submission status: Accepted

Solution code:
n=input()
while True:
    dic={}
    for i in range(n):
        L=raw_input().split()
        dic[(-(3*int(L[1])+1*int(L[3])),i)]=L[0]
    for i in sorted(dic):
        print "%s,%d"%(dic[i],-i[0])
    n=input()
    if n==0:break
    print

Submission status: Accepted

Solution code:
def func(args):
    s,a,b,c = args
    return s,int(a)*3+int(c)

n = input()
while True:
    a = map(func,[raw_input().split() for _ in xrange(n)])
    a.sort(key=lambda x:-x[1])#stable
    print "\n".join(map(lambda (s,p):"{},{}".format(s,p),a))
    n = input()
    if n == 0:
        break
    print

Submission status: Accepted

Solution code:
n=input()
while 1:
	p={}
	for i in range(n):
		t=raw_input().split()
		p[t[0]] = [3*int(t[1])+1*int(t[3]),-i]
	for k,v in sorted(p.items(),key=lambda x:x[1])[::-1]:
		print "%s,%d"%(k,v[0])
	n=input()
	if n==0:break
	print

Submission status: Accepted

Solution code:
def getScore(d):
    return int(d[1]) * 3 + int(d[3])
    
isFirst = True

while 1:
    n = int(input())
    if n == 0:
        break
    if not isFirst:
        print()
    table = []
    for i in range(0,n):
        d = list(_ for _ in input().split())
        score = getScore(d)
        table.append((d[0],score))
    table.sort(key=lambda i:i[1],reverse=True)
    
    for n,s in table:
        print(str(n) + ',' + str(s))
    isFirst = False

Submission status: Accepted

Solution code:
f = True
while True:
    n = int(input())
    if n == 0:
        break
    T = []
    for i in range(n):
        name,w,l,d = list(input().split())
        T.append((name,i,int(w)*3+int(d)))
    if f: f = False
    else: print()
    for i in sorted(T, key = lambda x:(-x[2],x[1])):
        print(i[0],",",i[2],sep="")

Submission status: Accepted

Solution code:
import bisect
cnt = 0
while 1:
    outs = []
    outn = []
    n = int(input())
    if n == 0: break
    elif cnt > 0: print()
    names = []
    scores = []
    for i in range(n):
        line = list(input().split())
        name = line[0]
        names.append(name)
        w = line[1]
        l = line[2]
        d = line[3]
        score = 3*int(w) + int(d)
        tm = bisect.bisect_left(outs, score)
        outs.insert(tm, score)
        outn.insert(tm, name)
        #scores.append(score)
    #ind = 1
    for i,j in zip(reversed(outn),reversed(outs)):
        print(f'{i},{j}')
        #if ind != n: print()
        #ind += 1
    #t = zip(scores, names)
    #t = sorted(t,reverse=True)
    #names,scores = zip(*t)
    #ind = 0
    #for i,j in t:
        #print(f'{j},{i}',end='')
        #if ind != len(t)-1: print()
        #ind += 1

    cnt += 1

Submission status: Accepted

Solution code:
st=True
while True:
    n=int(input())
    if n==0:
        break
    if st==False:
        print()

    team={}
    for _ in range(n):
        data=input().split(" ")
        team[data[0]]=3*int(data[1])+int(data[3])
    team=team.items()
    team=sorted(team,key=lambda w:w[1],reverse=True)
    for t in team:
        print("{0},{1}".format(*t))
    st=False

Submission status: Accepted

Solution code:
a = int(input())
while True:
    s = []
    for i in range(a):
        b,c,d,e = input().split()
        c = int(c)
        e = int(e)
        s.append([c*3+e,-(i),b])
    s.sort(reverse = True)
    for z in s:
        print(z[2]+","+str(z[0]))
    a = int(input())
    if a == 0:
        break
    else:
        print()

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


class Info:
    def __init__(self,arg_name,arg_index,arg_value):
        self.name = arg_name
        self.index = arg_index
        self.value = arg_value

    def __lt__(self,another):
        if self.value != another.value:
            return self.value > another.value
        else:
            return self.index < another.index

is_First = True

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

    if is_First == False:
        print()

    table = []

    for i in range(N):
        tmp_name,win,lose,draw = map(str,input().split())
        table.append(Info(tmp_name,i,3*int(win)+int(draw)))

    table.sort()
    for i in range(N):
        print("%s,%d"%(table[i].name,table[i].value))


    is_First = False

Submission status: Accepted

Solution code:
c = 0
while True:
    c +=1
    L = []
    num = int(input())
    if num == 0:
        break
    
    for i in range(num):
        name, w, l, d = input().split()
        w = int(w)
        d = int(d)
        L.append((i,name,w*3+d))
    
    L.sort(key=lambda x: (-x[2],x[0]))
    
    if c > 1:
        print()
        
    for l in L:
        print("{},{}".format(l[1], l[2]))

Submission status: Accepted

Solution code:
f = True
while True:
    n = int(input())
    if n == 0: break
    tbl = []
    for i in range(n):
        name, w, l, d = list(input().split())
        tbl.append([name, i, 3*int(w)+int(d)])
    if f: f = False
    else: print()
    for i in sorted(tbl, key=lambda x:(-x[2],x[1])): print(i[0], ',', i[2], sep='')

Submission status: Accepted

Solution code:
first = False
while 1:
    n = int(input())
    if n == 0:
        break

    if first:
        print()
    else:
        first = True

    data = []
    for _ in range(n):
        country, win, lose, draw = map(str, input().split())
        point = int(win) * 3 + int(draw)
        data.append([country, point])

    data.sort(key=lambda item: -item[1])

    for country, point in data:
        print(country + "," + str(point))

Submission status: Accepted

Solution code:
flag = True
while True:
    n = int(input())
    if n == 0: break
    answer = {}
    for _ in range(n):
        result = input().split()
        country = result[0]
        win, lose, draw = map(int, result[1:])
        score = win * 3 + draw
        answer[country] = score
    if flag:
        flag = False
    else:
        print()
    for c, s in sorted(answer.items(), key=lambda x: -x[1]):
        print(c + ',' + str(s))

Submission status: Runtime Error

Solution code:
c = 1
while True:
    N = int(raw_input())
    if N == 0:
        break
    elif c != 1:
        print ''
     
    dic = {}
    for i in range(N):
        lis = raw_input().split()
        name = lis[0]
        lis = map(int, lis[1:])
        point = lis[0]*3 + lis[2]
        dic[name] = [point, N-i]
    
    for k, v in sorted(dic.items(), key=lambda x: (x[0][0], x[0][1]), reverse=True):
        print '%s,%s' % (k, v[0])
    c += 1

Submission status: Runtime Error

Solution code:
while True:
    N = int(raw_input())
    if N == 0:
        break
     
    dic = {}
    for i in range(N):
        lis = raw_input().split()
        name = lis[0]
        lis = map(int, lis[1:])
        point = lis[0]*3 + lis[2]
        dic[name] = [point, N-i]
    
    for k, v in sorted(dic.items(), key=lambda x: (x[0][0], x[0][1]), reverse=True):
        print '%s,%s' % (k, v[0])
    print ''

Submission status: Runtime Error

Solution code:
c = 0
while True:
    N = int(raw_input())
    if N == 0:
        break
    elif c != 0:
        print ''
        
    dic = {}
    for i in range(N):
        lis = raw_input().split()
        name = lis[0]
        lis = map(int, lis[1:])
        point = lis[0]*3 + lis[2]
        dic[name] = [point, N-i]
    
    for k, v in sorted(dic.items(), key=lambda x: (x[0][0], x[0][1]), reverse=True):
        print '%s,%s' % (k, v[0])
    c = 1

Submission status: Runtime Error

Solution code:
c = 0
while True:
    N = int(raw_input())
    if N == 0:
        break
    if c != 0:
        print ''
        
    dic = {}
    for i in range(N):
        lis = raw_input().split()
        name = lis[0]
        lis = map(int, lis[1:])
        point = lis[0]*3 + lis[2]
        dic[name] = [point, N-i]
    
    for k, v in sorted(dic.items(), key=lambda x: (x[0][0], x[0][1]), reverse=True):
        print '%s,%s' % (k, v[0])
    c = 1

Submission status: Runtime Error

Solution code:
c = 0
while True:
    N = int(raw_input())
    if N == 0:
        break
    if c != 0:
        print
        
    dic = {}
    for i in range(N):
        lis = raw_input().split()
        name = lis[0]
        lis = map(int, lis[1:])
        point = lis[0]*3 + lis[2]
        dic[name] = [point, N-i]
    
    for k, v in sorted(dic.items(), key=lambda x: (x[0][0], x[0][1]), reverse=True):
        print '%s,%s' % (k, v[0])
    c = 1

Submission status: Runtime Error

Solution code:
N = input()
while True:
    dic = {}
    for i in range(N):
        lis = raw_input().split()
        name = lis[0]
        lis = map(int, lis[1:])
        point = lis[0]*3 + lis[2]
        dic[name] = [point, N-i]
    
    for k, v in sorted(dic.items(), key=lambda x: (x[0][0], x[0][1]), reverse=True):
        print '%s,%s' % (k, v[0])

    N = input()
    if N == 0: break
    print

Submission status: Runtime Error

Solution code:
N = input()
while True:
    dic = {}
    for i in range(N):
        lis = raw_input().split()
        dic[lis[0]] = [3*int(lis[1])+int(lis[3]), N-i]
    
    for k, v in sorted(dic.items(), key=lambda x: (x[0][0], x[0][1]), reverse=True):
        print '%s,%s' % (k, v[0])

    N = input()
    if N == 0: break
    print

Submission status: Runtime Error

Solution code:
N = input()
while True:
    dic = {}
    for i in range(N):
        lis = raw_input().split()
        dic[lis[0]] = [3*int(lis[1])+int(lis[3]), N-i]
    
    for k, v in sorted(dic.items(), key=lambda x: (x[0][0], x[0][1]), reverse=True):
        print '%s,%s' % (k, v[0])

    N = input()
    if N == 0: break
    print ''

Submission status: Runtime Error

Solution code:
b=False
while True:
    n = int(input())
    if n==0:break
    d=dict()
    if b:print()
    b=True
    for _ in range(n):
        line = input().split()
        tmp = int(line[1])*3+int(line[3]*1)
        if tmp in d:
            d[tmp].append(line[0])
        else:
            d[tmp] = []
            d[tmp].append(line[0])
    for k, vs in sorted(d.items(), key=lambda x: x[0])[::-1]:
        for v in vs:
            print('%s,%d'%(k, v))

Submission status: Runtime Error

Solution code:
n=input()
while 1:
	m=[raw_input().split() for i in range(n)]
	p={}
	for t in m:
		p[t[0]] = 3*int(t[1])+1*int(t[3])
	for k,v in sorted(p.items(),key=lambda x:x[1])[::-1]:
		print "%s,%d"%(k,v)
	c+=1
	n=input()
	if n==0:break
	print

Submission status: WA: Presentation Error

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

import sys
import os
import math

for s in sys.stdin:
    n = int(s)

    A = []

    for i in range(n):
        lst = input().split()
        name = lst[0]
        w = int(lst[1])
        l = int(lst[2])
        d = int(lst[3])
        score = 3 * w + d
        A.append((score, -i, name))
    A.sort(reverse=True)

    for a in A:
        score = a[0]
        name = a[2]
        print('{},{}'.format(name, score))
    print()

Submission status: WA: Presentation Error

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

import sys
import os
import math

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    A = []

    for i in range(n):
        lst = input().split()
        name = lst[0]
        w = int(lst[1])
        l = int(lst[2])
        d = int(lst[3])
        score = 3 * w + d
        A.append((score, -i, name))
    A.sort(reverse=True)

    for a in A:
        score = a[0]
        name = a[2]
        print('{},{}'.format(name, score))
    print()

Submission status: WA: Presentation Error

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0124
"""
import sys
from operator import itemgetter


def solve(data):
    result = []
    for name, win, lose, draw in data:
        score = win * 3 + draw * 1
        result.append([name, score])
    result.sort(key=itemgetter(1), reverse=True)
    return result


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        data = []
        for _ in range(n):
            name, win, lose, draw = input().split()
            data.append([name, int(win), int(lose), int(draw)])
        result = solve(data)
        for r in result:
            print(','.join(map(str, r)))
        print()


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: WA: Presentation Error

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    dataset = []
    for _ in range(n):
        name, w, l, d = input().split()
        dataset.append((name, 3*int(w) + int(d), n-len(dataset)))
    for name, score, _ in sorted(dataset, key=lambda x: (x[1], x[2]))[::-1]:
        print(name + "," + str(score))

Submission status: WA: Presentation Error

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

        teams = []
        for i in range(n):
            row = input().split()
            teams.append([row[0], 0])
            s_t = 0
            for e, p in zip(row[1:], [3, 0, 1]):
                s_t += int(e) * p
            teams[i][1] = s_t
        
        for t in sorted(teams, key=lambda x: x[1], reverse=True):
            print("{},{}".format(t[0], t[1]))



if __name__ == "__main__":
    main()

Submission status: WA: Presentation Error

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

        teams = []
        for i in range(n):
            row = input().split()
            teams.append([row[0], 0])
            s_t = 0
            for e, p in zip(row[1:], [3, 0, 1]):
                s_t += int(e) * p
            teams[i][1] = s_t
        
        for t in sorted(teams, key=lambda x: x[1], reverse=True):
            print("{},{}".format(t[0], t[1]))
        print()



if __name__ == "__main__":
    main()