Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

k_y = [1000]

for i in range(n):
	genkin_list = [ hk * a[i] + hy for hk,hy in enumerate(k_y) ]  #所持株、金
	genkin_list_max = max(genkin_list)
	max_index = genkin_list.index(genkin_list_max)
	k_y = [ genkin_list_max - a[i] * j for j in range(genkin_list_max // a[i]+1 ) ]
	
print( k_y[0] )


Fixed submission:
n = int(input())
a = list(map(int,input().split()))

k_y = [1000]
yen = 1000
resyen = 1000
kabu_max = 0
for i in range(n):
	#株を売り払うケース
	newyen = max( yen, kabu_max * a[i] + resyen)
	
	#株を最大買うケース
	kabu_max_new = max( kabu_max + resyen // a[i], yen // a[i] )
	if kabu_max_new == yen // a[i]:
		if kabu_max_new == kabu_max + resyen // a[i]:
			resyen = max( yen % a[i], resyen % a[i])
		else:
			resyen = yen % a[i]
	
	yen = newyen
	kabu_max = kabu_max_new
	#print(kabu_max,yen,resyen)
print( yen )

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

k_y = [1000]

for i in range(n):
	genkin_list = [ hk * a[i] + hy for hk,hy in enumerate(k_y) ]  #所持株、金
	genkin_list_max = max(genkin_list)
	max_index = genkin_list.index(genkin_list_max)
	
	k_y = [ a[i]*(max_index-hk)+k_y[max_index] for hk,hy in enumerate(k_y) ]
	k_y2 = [ genkin_list_max - a[i] * x for x in range( len(k_y), genkin_list_max // a[i]+1 ) ]
	k_y = k_y + k_y2
print( k_y[0] )


Fixed submission:
n = int(input())
a = list(map(int,input().split()))

k_y = [1000]
yen = 1000
resyen = 1000
kabu_max = 0
for i in range(n):
	#株を売り払うケース
	newyen = max( yen, kabu_max * a[i] + resyen)
	
	#株を最大買うケース
	kabu_max_new = max( kabu_max + resyen // a[i], yen // a[i] )
	if kabu_max_new == yen // a[i]:
		if kabu_max_new == kabu_max + resyen // a[i]:
			resyen = max( yen % a[i], resyen % a[i])
		else:
			resyen = yen % a[i]
	
	yen = newyen
	kabu_max = kabu_max_new
	#print(kabu_max,yen,resyen)
print( yen )

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

k_y = [1000]

for i in range(n):
	genkin_list = [ hk * a[i] + hy for hk,hy in enumerate(k_y) ]  #所持株、金
	genkin_list_max = max(genkin_list)
	max_index = genkin_list.index(genkin_list_max)
	
	k_y = [ a[i]*(max_index-hk)+k_y[max_index] for hk,hy in enumerate(k_y) ]
	#print(  len(k_y), genkin_list_max // a[i] )
	for x in range( len(k_y), genkin_list_max // a[i]+1 ):
		k_y.append( genkin_list_max - a[i] * x )
	#print(k_y)
print( k_y[0] )


Fixed submission:
n = int(input())
a = list(map(int,input().split()))

k_y = [1000]
yen = 1000
resyen = 1000
kabu_max = 0
for i in range(n):
	#株を売り払うケース
	newyen = max( yen, kabu_max * a[i] + resyen)
	
	#株を最大買うケース
	kabu_max_new = max( kabu_max + resyen // a[i], yen // a[i] )
	if kabu_max_new == yen // a[i]:
		if kabu_max_new == kabu_max + resyen // a[i]:
			resyen = max( yen % a[i], resyen % a[i])
		else:
			resyen = yen % a[i]
	
	yen = newyen
	kabu_max = kabu_max_new
	#print(kabu_max,yen,resyen)
print( yen )

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

k_y = [1000]
k_y_new = [ 1000 ]
for i in range(n):
	for hk,hy in enumerate(k_y): #所持株、金
		kk = 0#想定所持株数
		while True:
			genkin = (hk - kk) * a[i] + hy
			
			if genkin < 0 :
				break
			else:
				if kk >= len(k_y_new):
					k_y_new.append( genkin )
				else:
					k_y_new[kk] = max(k_y_new[kk], genkin)
				kk = kk + 1
		#print( k_y_new )
	k_y = [y for y in k_y_new]
print( k_y_new[0] )



Fixed submission:
n = int(input())
a = list(map(int,input().split()))

k_y = [1000]
yen = 1000
resyen = 1000
kabu_max = 0
for i in range(n):
	#株を売り払うケース
	newyen = max( yen, kabu_max * a[i] + resyen)
	
	#株を最大買うケース
	kabu_max_new = max( kabu_max + resyen // a[i], yen // a[i] )
	if kabu_max_new == yen // a[i]:
		if kabu_max_new == kabu_max + resyen // a[i]:
			resyen = max( yen % a[i], resyen % a[i])
		else:
			resyen = yen % a[i]
	
	yen = newyen
	kabu_max = kabu_max_new
	#print(kabu_max,yen,resyen)
print( yen )

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

from collections import defaultdict
k_y = defaultdict(int)
k_y[0] = 1000

#for hk,hy in k_y.items(): #所持株、金
#	print(hk,hy)

k_y_new = [ vvv for vvv in k_y.values()]
for i in range(n):
	for hk,hy in k_y.items(): #所持株、金
		kk = 0#想定所持株数
		while True:
			genkin = (hk - kk) * a[i] + hy
			
			if genkin < 0 :
				break
			else:
				if kk >= len(k_y_new):
					#print('add',genkin)
					k_y_new.append( genkin )
				else:
					#print('repl',k_y_new[kk], genkin)
					k_y_new[kk] = max(k_y_new[kk], genkin)
				kk = kk + 1
		#print( k_y_new )
	k_y = {x:y for x,y in enumerate(k_y_new)}
print( k_y_new[0] )


Fixed submission:
n = int(input())
a = list(map(int,input().split()))

k_y = [1000]
yen = 1000
resyen = 1000
kabu_max = 0
for i in range(n):
	#株を売り払うケース
	newyen = max( yen, kabu_max * a[i] + resyen)
	
	#株を最大買うケース
	kabu_max_new = max( kabu_max + resyen // a[i], yen // a[i] )
	if kabu_max_new == yen // a[i]:
		if kabu_max_new == kabu_max + resyen // a[i]:
			resyen = max( yen % a[i], resyen % a[i])
		else:
			resyen = yen % a[i]
	
	yen = newyen
	kabu_max = kabu_max_new
	#print(kabu_max,yen,resyen)
print( yen )