Problem:


Problem B: Moonlight Farm

ムーンライト牧場

-->

あなたは大人気webゲーム「ムーンライト牧場」に熱中している．このゲームの目的は，畑で作物を育て，それらを売却して収入を得て，その収入によって牧場を大きくしていくことである．

あなたは速く畑を大きくしたいと考えた．そこで手始めにゲーム中で育てることのできる作物を，時間あたりの収入効率にもとづいて並べることにした．

作物を育てるには種を買わなければならない．ここで作物 i の種の名前は Li ，値段は Pi でそれぞれ与えられる．畑に種を植えると時間 Ai 後に芽が出る．芽が出てから時間 Bi 後に若葉が出る．若葉が出てから時間 Ci 後に葉が茂る．葉が茂ってから時間 Di 後に花が咲く．花が咲いてから時間 Ei 後に実が成る．一つの種から Fi 個の実が成り，それらの実は一つあたりSi の価格で売れる．一部の作物は多期作であり，計 Mi 回実をつける．単期作の場合は Mi = 1で表される．多期作の作物は，Mi 回目の実が成るまでは，実が成ったあと葉に戻る．ある種に対する収入は，その種から成った全ての実を売った金額から，種の値段を引いた値である．また，その種の収入効率は，その収入を，種を植えてから全ての実が成り終わるまでの時間で割った値である．

あなたの仕事は，入力として与えられる作物の情報に対して，それらを収入効率の降順に並べ替えて出力するプログラムを書くことである．

Input

入力はデータセットの列であり，各データセットは次のような形式で与えられる．

N

L1 P1 A1 B1
C1 D1 E1 F1
S1 M1

L2 P2 A2 B2
C2 D2 E2 F2
S2 M2

...

LN PN AN BN
CN DN EN FN
SN MN

一行目はデータセットに含まれる作物の数 N である (1 ≤ N ≤ 50)．

これに続く N 行には，各行に一つの作物の情報が含まれる．各変数の意味は問題文中で述べた通りである．作物の名前 Li はアルファベット小文字のみからなる20文字以内の文字列であり，また 1 ≤ Pi , Ai , Bi , Ci , Di , Ei , Fi , Si ≤ 100, 1 ≤ Mi ≤ 5である．一つのケース内に同一の名前を持つ作物は存在しないと仮定して良い．

入力の終りはゼロを一つだけ含む行で表される．

Output

各データセットについて，各行に一つ，作物の名前を収入効率の降順に出力せよ．収入効率が同じ作物に対しては，それらの名前を辞書順の昇順に出力せよ．

各データセットの出力の後には&ldquo;#&rdquo;のみからなる1行を出力すること．

Sample Input

5
apple 1 1 1 1 1 1 1 10 1
banana 1 2 2 2 2 2 1 10 1
carrot 1 2 2 2 2 2 1 10 2
durian 1 3 3 3 3 3 1 10 1
eggplant 1 3 3 3 3 3 1 100 1
4
enoki 1 3 3 3 3 3 1 10 1
tomato 1 3 3 3 3 3 1 10 1
potato 1 3 3 3 3 3 1 10 1
onion 1 3 3 3 3 3 1 10 1
3
a 10 1 1 1 1 1 1 10 1
b 10 2 2 2 2 2 2 10 1
c 10 2 2 2 2 2 2 10 1
0

Output for the Sample Input

eggplant
apple
carrot
banana
durian
#
enoki
onion
potato
tomato
#
b
c
a
#



Sample input:
5
apple 1 1 1 1 1 1 1 10 1
banana 1 2 2 2 2 2 1 10 1
carrot 1 2 2 2 2 2 1 10 2
durian 1 3 3 3 3 3 1 10 1
eggplant 1 3 3 3 3 3 1 100 1
4
enoki 1 3 3 3 3 3 1 10 1
tomato 1 3 3 3 3 3 1 10 1
potato 1 3 3 3 3 3 1 10 1
onion 1 3 3 3 3 3 1 10 1
3
a 10 1 1 1 1 1 1 10 1
b 10 2 2 2 2 2 2 10 1
c 10 2 2 2 2 2 2 10 1
0


Sample output:
eggplant
apple
carrot
banana
durian
#
enoki
onion
potato
tomato
#
b
c
a
#

Submission status: Wrong Answer

Solution code:
resultss = []
while True:
    N = int(input())
    if N == 0:
        break
       
    B = [list(map(str, input().split())) for _ in range(N)]
    results = []
    for i in range(N):
        A = []
        name = B[i][0]
        B[i][0] = B[i][1]
        for j in range(10):
            A.append(int(B[i][j]))
            
        if A[-1] == 1:
            time = A[2] + A[3] + A[4] + A[5] + A[6]
            money = A[7] * A[8]
            res = money - A[1]
            res /= time
            
        else:
            time = A[2] + A[3] + A[4] + A[5] + A[6] + (A[5] + A[6]) * (A[-1] - 1)
            money = A[7] * A[8] * A[-1]
            res = money - A[1]
            res /= time
            
        results.append([res, name])
        
    tmp = results[0][0]
    flag =False
    for i in range(len(results)):
        if results[i][0] != tmp:
            flag = True
      
    if flag:
        results.sort()
    else:
        results = sorted(results, key=lambda x: x[1], reverse=True)
    resultss.append(results)
    
for i in range(len(resultss)):
    for j in range(len(resultss[i])):
        print(resultss[i][-j-1][1])
    print('#')

Submission status: Wrong Answer

Solution code:
resultss = []
while True:
    N = int(input())
    if N == 0:
        break
       
    B = [list(map(str, input().split())) for _ in range(N)]
    results = []
    for i in range(N):
        A = []
        name = B[i][0]
        B[i][0] = B[i][1]
        for j in range(10):
            A.append(int(B[i][j]))
            
        if A[-1] == 1:
            time = A[2] + A[3] + A[4] + A[5] + A[6]
            money = A[7] * A[8]
            res = money - A[1]
            res /= time
            
        else:
            time = A[2] + A[3] + A[4] + A[5] + A[6] + (A[5] + A[6]) * (A[-1] - 1)
            money = A[7] * A[8] * A[-1]
            res = money - A[1]
            res /= time
            
        results.append([res, name])
        
      
    results.sort()
    
    for i in range(len(results)-1):
        if results[i][0] == results[i+1][0]:
            tmp =  results[i+1][1]
            results[i+1][1] =  results[i][1]
            results[i][1] = tmp
        
    resultss.append(results)
    
for i in range(len(resultss)):
    for j in range(len(resultss[i])):
        print(resultss[i][-j-1][1])
    print('#')

Submission status: Wrong Answer

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

#LPABCDEFSM
#0123456789

while 1:
    N = int(raw_input())
    if N==0: break
    crop = [raw_input().split() for i in range(N)]
    for i in range(N): crop[i][1:] = map(int, crop[i][1:])
    ef = []
    for i in range(N):
        com = (crop[i][-3]*crop[i][-1])*crop[i][-2]-crop[i][1]
        t = sum(crop[i][1:7])
        for j in range(crop[i][-1]-1):
            t += sum(crop[i][5:7])
        ef.append([-com/float(t), crop[i][0]])
    ef.sort()
    for i in range(N): print ef[i][1]
    print '#'

Submission status: Wrong Answer

Solution code:
while True:
    amount = int(input())

    if amount == 0:
        break

    efficiency_list = []

    for _ in range(amount):
        crop = input().split()
        time = sum(map(int, crop[2:7]))

        M = int(crop[9])
        if M > 1:
            for _ in range(1, M):
                time += int(crop[5]) + int(crop[6])

        fruits = M * int(crop[7])
        efficiency = (fruits * int(crop[8]) - int(crop[1])) / time

        efficiency_list.append(tuple([crop[0], efficiency]))
    print(*efficiency_list)

    efficiency_list.sort(key=lambda x:(-x[1], x[0]))

    for element in efficiency_list:
        print(element[0])
    print("#")

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(k):
        p,a,b,c,d,e,f,s,m = map(int,k[1:])
        t = a + b + c + (d + e) * (m - 1)
        u = f * s * m - p
        return (-u / t, k[0])

    while True:
        n = I()
        if n == 0:
            break

        a = [LS() for _ in range(n)]
        b = [f(c) for c in a]
        b.sort()
        for u,l in b:
            rr.append(l)
        rr.append('#')

    return '\n'.join(map(str, rr))


print(main())

Submission status: Wrong Answer

Solution code:
while 1:
	n = input()
	if n == 0: break
	ans = []
	for i in range(n):
		inp = raw_input().split()
		L = inp[0]
		P,A,B,C,D,E,F,S,M = map(int,inp[1:])
		ans.append([L,(M*S-P)*1.0/(A+B+C+(D+E+F)*M)])
	ans = sorted(sorted(ans), key = lambda x:x[1], reverse = True)
	for k,v in ans: print k
	print "#"

Submission status: Accepted

Solution code:
resultss = []
while True:
    N = int(input())
    if N == 0:
        break
       
    B = [list(map(str, input().split())) for _ in range(N)]
    results = []
    for i in range(N):
        A = []
        name = B[i][0]
        B[i][0] = B[i][1]
        for j in range(10):
            A.append(int(B[i][j]))
            
        if A[-1] == 1:
            time = A[2] + A[3] + A[4] + A[5] + A[6]
            money = A[7] * A[8]
            res = money - A[1]
            res /= time
            
        else:
            time = A[2] + A[3] + A[4] + A[5] + A[6] + (A[5] + A[6]) * (A[-1] - 1)
            money = A[7] * A[8] * A[-1]
            res = money - A[1]
            res /= time
            
        results.append([res, name])
        
      
    results = sorted(results, key=lambda x: x[1], reverse = True)
    
    results = sorted(results, key=lambda x: x[0])
        
    resultss.append(results)
    
for i in range(len(resultss)):
    for j in range(len(resultss[i])):
        print(resultss[i][-j-1][1])
    print('#')

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    while True:
        N = int(input())
        if N == 0:
            break
        L = []
        for i in range(N):
            l, p, a, b, c, d, e, f, s, m = input().split()
            L.append(
                [
                    l,
                    int(p),
                    int(a),
                    int(b),
                    int(c),
                    int(d),
                    int(e),
                    int(f),
                    int(s),
                    int(m),
                ]
            )
        income_efficiency = []
        for l in L:
            value = (l[7] * l[9]) * l[8] - l[1]
            need_time = (l[2] + l[3] + l[4]) + (l[5] + l[6]) * l[9]
            income_efficiency.append([l[0], value / need_time])

        income_efficiency.sort(key=lambda x: x[0])
        [
            print(ie[0])
            for ie in sorted(income_efficiency, key=lambda x: x[1], reverse=True)
        ]
        print("#")

Submission status: Accepted

Solution code:
from operator import itemgetter
while 1:
	N = int(raw_input())
	if N == 0:
		break
	produce = []
	for i in range(N):
		inputs = raw_input().split(" ")
		name = inputs[0]
		p,a,b,c,d,e,f,s,m = map(int,inputs[1:])
		time = (a + b + c) + (d + e) * m
		value = f * s * m - p
		produce.append((-1.0 * value / time, name))
	produce.sort(key=itemgetter(0,1))
	for pro in produce:
		print pro[1]
	print "#"

Submission status: Accepted

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

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n = input()
            if n == 0:
                break
            data = []
            for i in range(n):
                line = raw_input()
                l = line.split()[0]
                p, a, b, c, d, e, f, s, m = map(int, line.split()[1:])
                efficiency = 1.0 * (f * s * m - p) / (a + b + c + m * (d + e))
                data.append((efficiency, l))
            data.sort(key=lambda x: (-x[0], x[1]))
            for d in data:
                print d[1]
            print '#' 
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Accepted

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

#LPABCDEFSM
#0123456789

while 1:
    N = int(raw_input())
    if N==0: break
    crop = [raw_input().split() for i in range(N)]
    for i in range(N): crop[i][1:] = map(int, crop[i][1:])
    ef = []
    for i in range(N):
        com = (crop[i][-3]*crop[i][-1])*crop[i][-2]-crop[i][1]
        t = sum(crop[i][2:7])
        for j in range(crop[i][-1]-1):
            t += sum(crop[i][5:7])
        ef.append([-com/float(t), crop[i][0]])
    ef.sort()
    for i in range(N): print ef[i][1]
    print '#'

Submission status: Accepted

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

while True:
    N = int(input())
    if N == 0:
        break
    crops = {}
    for i in range(N):
        L,P,A,B,C,D,E,F,S,M = map(lambda x: int(x) if x.isnumeric() else x,input().split())
        time = A+B+C
        for _ in range(M):
            time += D + E
        crops[L] = (M*F*S - P) / time

    for key,value in sorted(crops.items(), key = lambda c: (-c[1],c[0])):
        print(key)
    print('#')

Submission status: Accepted

Solution code:
while True:
    amount = int(input())

    if amount == 0:
        break

    efficiency_list = []

    for _ in range(amount):
        crop = input().split()
        time = sum(map(int, crop[2:7]))

        M = int(crop[9])
        if M > 1:
            for _ in range(1, M):
                time += int(crop[5]) + int(crop[6])

        fruits = M * int(crop[7])
        efficiency = (fruits * int(crop[8]) - int(crop[1])) / time

        efficiency_list.append((crop[0], efficiency))

    efficiency_list.sort(key=lambda x:(-x[1], x[0]))

    for element in efficiency_list:
        print(element[0])
    print("#")

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if not N: break
    seeds = []
    for i in range(N):
        plant = input().split()
        name, price = plant[0], int(plant[1])
        seed_to_leaf, leaf_to_fruit = sum(map(int, plant[2:5])), sum(map(int, plant[5:7]))
        num_per, sold, mult = int(plant[7]), int(plant[8]), int(plant[9])
        seeds.append((-(num_per * sold * mult - price) / (seed_to_leaf + leaf_to_fruit * mult), name))
    for _, name in sorted(seeds):
        print(name)
    print('#')

Submission status: Accepted

Solution code:
while True:
  N = int(raw_input())
  if N==0: break
  dic = {}
  for _ in xrange(N):
    L,P,A,B,C,D,E,F,S,M = raw_input().split()
    cost = int(P)
    time = int(A)+int(B)+int(C)+int(D)+int(E)+(int(D)+int(E))*(int(M)-1)
    profit = int(F) * int(S) * int(M)
    if float((profit-cost))/float(time) not in dic:
      dic[float((profit-cost))/float(time)] = []
    dic[float((profit-cost))/float(time)].append(L)
  for k,v in sorted(dic.items(), reverse=True):
    for name in sorted(v):
      print name
  print "#"

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0: break
    mem = []
    for i in range(N):
        l,p,a,b,c,d,e,f,s,m = map(lambda x:int(x) if x[0].isdigit() else x, input().split())
        time = a+b+c+(d+e)*m
        income = f*m*s - p
        mem.append((-income/time, l))
    for e,name in sorted(mem):
        print(name)
    print('#')

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(k):
        p,a,b,c,d,e,f,s,m = map(int,k[1:])
        t = a + b + c + (d + e) * m
        u = f * s * m - p
        return (-u / t, k[0])

    while True:
        n = I()
        if n == 0:
            break

        a = [LS() for _ in range(n)]
        b = [f(c) for c in a]
        b.sort()
        for u,l in b:
            rr.append(l)
        rr.append('#')

    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    ans = []
    for i in range(n):
        l,p,a,b,c,d,e,f,s,m = input().split()
        p,a,b,c,d,e,f,s,m = map(int,[p,a,b,c,d,e,f,s,m])
        sum = s*f*m-p
        sum /= (a+b+c+d+e+(m-1)*(d+e))
        ans.append([l,sum])
    ans.sort(key = lambda x: x[0])
    ans.sort(key = lambda x: -x[1])
    for i in ans:
        print(i[0])
    print("#")

Submission status: Accepted

Solution code:
import sys
import collections

n = -1
while True:
    if n != -1:
        print '#'
    n = int(sys.stdin.readline())
    if n == 0:
        break
    
    result = []
    for i in xrange(n):
        read = raw_input().split()
        L = read[0]
        P, A, B, C, D, E, F, S, M = map(int, read[1:])
        time = A + B + C + (D + E) * M
        profit = F * M * S - P
        result.append((float(profit) / time, L))
    result.sort(key = lambda x: (-x[0], x[1]))
    for r in result:
        print r[1]

Submission status: Accepted

Solution code:
while True:
    n=input()
    if n==0:break
    R=[]
    for i in range(n):
        T=raw_input().split()
        L=T[0]
        P,A,B,C,D,E,F,S,M=map(int,T[1:])
        t=A+B+C+(D+E)*M
        m=F*S*M-P
        R.append((-m/float(t),L))
    for i in sorted(R):
        print i[1]
    print "#"

Submission status: Accepted

Solution code:
while 1:
	n = input()
	if n == 0: break
	ans = []
	for i in range(n):
		inp = raw_input().split()
		L = inp[0]
		P,A,B,C,D,E,F,S,M = map(int,inp[1:])
		ans.append([L,(M*F*S-P)*1.0/(A+B+C+(D+E)*M)])
	ans = sorted(sorted(ans), key = lambda x:x[1], reverse = True)
	for k,v in ans: print k
	print "#"

Submission status: Accepted

Solution code:
while 1:
	n = input()
	if n == 0: break
	ans = []
	for i in range(n):
		inp = raw_input().split()
		P,A,B,C,D,E,F,S,M = map(int,inp[1:])
		ans.append([inp[0],(M*F*S-P)*1.0/(A+B+C+(D+E)*M)])
	ans = sorted(sorted(ans), key = lambda x:x[1], reverse = True)
	for k,v in ans: print k
	print "#"

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    while 1:
        n=int(input())
        if n==0:break
        ans=[]
        for _ in range(n):
            l,*num=input().split()
            p,a,b,c,d,e,f,s,m=map(int,num)
            ans.append([(f*s*m-p)/(a+b+c+(d+e)*m),l])
        ans.sort(key=lambda x:(-x[0],x[1]))
        for _,l in ans:
            print(l)
        print("#")

main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve(n):
    lis = []
    for i in range(n):
        l = input().split()
        p,a,b,c,d,e,f,s,m = [int(i) for i in l[1:]]
        l = l[0]
        lis.append(((f*s*m-p)/(a+b+c+(d+e)*m),l))
    lis.sort(key = lambda x:(-x[0],x[1]))
    for i, j in lis:
        print(j)
    print("#")
    return

#Solve
if __name__ == "__main__":
    while 1:
        n = I()
        if n == 0:
            break
        solve(n)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    if n == 0:
        return False
    lpabcdefsm = [input().split() for _ in range(n)]
    ans = []
    for A in lpabcdefsm:
        l = A[0]
        p, a, b, c, d, e, f, s, m = map(int, A[1:])
        time = a + b + c + (d + e) * m
        score = f * s * m - p
        ans.append((score / time, l))
    ans.sort(key=lambda x: (-x[0], x[1]))
    for _, i in ans:
        print(i)
    print("#")
    return True


#main
if __name__ == '__main__':
    while solve():
        pass

Submission status: Accepted

Solution code:
while True:
	n=int(input())
	if n==0:
		exit()
	else:
		aa=[]
		for i in range(n):
			l,p,a,b,c,d,e,f,s,m=input().split()
			p=int(p)
			a=int(a)
			b=int(b)
			c=int(c)
			d=int(d)
			e=int(e)
			f=int(f)
			s=int(s)
			m=int(m)
			time=a+b+c+(d+e)*m
			pro=s*m*f-p
			aa.append([pro/time,l])
		aa.sort(key=lambda x:(-x[0],x[1]))
		for i in range(n):
			print(aa[i][1])
		print("#")

Submission status: Accepted

Solution code:

while True:

    N = int(input())
    ans = []

    if N == 0:
        break

    for i in range(N):

        L,P,A,B,C,D,E,F,S,M = input().split()
        P = int(P)
        A = int(A)
        B = int(B)
        C = int(C)
        D = int(D)
        E = int(E)
        F = int(F)
        S = int(S)
        M = int(M)

        time = A+B+C+(D+E)*M
        mon = S * M * F - P

        ans.append([-1 * (mon/time),L])

    ans.sort()

    for i in range(N):
        print (ans[i][1])
    print ("#")

Submission status: Accepted

Solution code:
while(True):
	n = int(input())
	if n==0:break
	agri_list = {}
	for i in range(n):
		l,p,a,b,c,d,e,f,s,m = input().split()
		p = int(p)
		a = int(a)
		b = int(b)
		c = int(c)
		d = int(d)
		e = int(e)
		f = int(f)
		s = int(s)
		m = int(m)
		time = a + b + c + (d + e)* m
		income = s * m * f - p
		agri_list[i] = (l,income/time)
	sorted_items = sorted( agri_list.values(), key = lambda x: (-x[1],x[0]))
	for i in sorted_items:
		print(i[0])
	print("#")

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        break
    
    data = []
    for _ in range(N):
        inp = input().split()
        P, A, B, C, D, E, F, S, M = map(int, inp[1:])
        time = A + B + C + M * (D + E)
        money = M * F * S - P

        da = [inp[0], money/time]
        data.append(da)

    data.sort(key=lambda x:x[0])
    data.sort(key=lambda x:-x[1])
    for i in range(N):
        print(data[i][0])
    print('#')

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        break
    effies = {}
    for _ in range(N):
        L, P, A, B, C, D, E, F, S, M = map(str, input().split())
        P = int(P)
        A = int(A)
        B = int(B)
        C = int(C)
        D = int(D)
        E = int(E)
        F = int(F)
        S = int(S)
        M = int(M)

        spend_time = A + B + C + (D+E) * M
        earn_amount = (F*M*S)-P
        effi = earn_amount/spend_time
        effies[L] = effi

    effies = sorted(effies.items(), key=lambda x :(-x[1], x[0]))
    for i in range(len(effies)):
        print(effies[i][0])
    print("#")

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        break
    
    data = []
    for _ in range(N):
        inp = input().split()
        P, A, B, C, D, E, F, S, M = map(int, inp[1:])
        time = A + B + C + M * (D + E)
        money = M * F * S - P

        da = [inp[0], money/time]
        data.append(da)

    data.sort(key=lambda x:x[0])
    data.sort(key=lambda x:-x[1])
    for i in range(N):
        print(data[i][0])
    print('#')

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

while True:
    N = inp()
    if N == 0:
        break
    ans = []
    for i in range(N):
        L,P,A,B,C,D,E,F,S,M = input().split()
        P,A,B,C,D,E,F,S,M = map(int,[P,A,B,C,D,E,F,S,M])
        T1 = A+B+C
        T2 = D+E
        T = T1 + T2*M
        B = F*S*M - P
        x = B/T
        ans.append([-x,L])
    ans.sort()
    for azu,nyan in ans:
        print(nyan)
    print('#')

Submission status: Accepted

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

    ans = []
    for _ in range(n):
        data = list(input().split())
        name = data.pop(0)
        data = [int(d) for d in data]
        p = data[0]
        a = data[1]
        b = data[2]
        c = data[3]
        d = data[4]
        e = data[5]
        f = data[6]
        s = data[7]
        m = data[8]
        first = a + b + c + d + e
        multi = (d + e) * (m - 1)
        time = first + multi
        benefit = f * m * s - p
        ratio = benefit / time
        ans.append([name, ratio])

    ans = sorted(ans, key=lambda x: (-x[1], x[0]))
    for a in ans:
        print(a[0])

    print("#")

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if n == 0:
    break
  dic = []
  for _ in range(n):
    lst = input().split()
    l = lst.pop(0)
    p, a, b, c, d, e, f, s, m = map(int, lst)
    time = a + b + c + (d + e) * m
    prof = f * s * m - p
    dic.append((-prof / time, l))
  
  dic.sort()
  for _, name in dic:
    print(name)
  print("#")

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:
        break
    D=[]
    for i in range(n):
        l,p,a,b,c,d,e,f,s,m=input().split()
        p,a,b,c,d,e,f,s,m=map(int,(p,a,b,c,d,e,f,s,m))
        D.append(((s*f*m-p)/((d+e)*m+a+b+c),l))
    D=sorted(D,key=lambda x:(-x[0],x[1]))
    for i in range(n):
        print(D[i][1])
    print('#')

Submission status: Runtime Error

Solution code:
import numpy as np
import sys

def firster(former, latter):
	com = [str(former), str(latter)]
	com.sort()
	#print(former)
	#print(latter)
	#print(com)
	if com[0] == former:
		return 1
	return 0

def one_turn(N):
	effs = [] #name
	effs_val = {} #value
	for i in range(N):
		data = input().split()
		period = 0
		name = data[0]
		p = int(data[1])
		period = int(data[2])+int(data[3])+int(data[4])+int(data[5])+int(data[6])
		f = int(data[7])
		s = int(data[8])
		m = int(data[9])
		eff = (m*f*s-p)/(period+(m-1)*(int(data[5])+int(data[6])))
		effs_val[name] = eff
		if i == 0:
			effs.insert(0,name)
			continue
		for k in range(i):
			if effs_val[effs[k]] < eff:
				effs.insert(k,name)
				break
			elif (effs_val[effs[k]] == eff and firster(name,effs[k])):
				effs.insert(k,name)
				break
			elif k == i-1:
				effs.append(name)
		#print(effs)
	
	for l in range(N):
		print(effs[l])
		#print(effs_val[effs[l]])

N = int(sys.stdin.readline())
while N > 0:
	one_turn(N)
	print('#')
	N = int(sys.stdin.readline())
print('#')