Buggy python submission (verdict: Runtime Error):
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

Fixed submission:
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

Buggy python submission (verdict: Runtime Error):
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 ''

Fixed submission:
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

Buggy python submission (verdict: Runtime Error):
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

Fixed submission:
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

Buggy python submission (verdict: Runtime Error):
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

Fixed submission:
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

Buggy python submission (verdict: Runtime Error):
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

Fixed submission:
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

Buggy python submission (verdict: Runtime Error):
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

Fixed submission:
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

Buggy python submission (verdict: Runtime Error):
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

Fixed submission:
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

Buggy python submission (verdict: Runtime Error):
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 ''

Fixed submission:
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