Buggy python submission (verdict: Runtime Error):
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')

n = I()
a = LI()
ans = 1000
kabu = 0
vs = list(Counter(a).keys())
i = 0
m = len(vs)
# 極小値で売る、極大値で買う
while i < m:
    if 0 < i < m - 1:
        if vs[i-1] > vs[i] < vs[i+1]:
            # 買う
            ans, kabu = ans % vs[i], ans // vs[i]
            # print(i, ans, kabu)

        elif vs[i-1] < vs[i] > vs[i+1]:
            # 売る
            ans, kabu = ans + vs[i] * kabu, 0
            # print(i, ans, kabu)
    else:
        if i == 0:
            if vs[i] < vs[i+1]:
                # 買う
                ans, kabu = ans % vs[i], ans // vs[i]
                # print(i, ans, kabu)
        else:
            if vs[i - 1] < vs[i]:
                # 売る
                ans, kabu = ans + vs[i] * kabu, 0
                # print(i, ans, kabu)
    i += 1
# print(i)

print(ans)


Fixed submission:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')

n = I()
a = LI()
ans = 1000
for i in range(n - 1):
    kabu = 0
    if a[i] < a[i+1]:
        # 出来るだけ買う
        kabu = ans // a[i]
    # 買った株があれば i + 1日目 に売る
    if kabu > 0:
        ans += (a[i + 1] - a[i]) * kabu
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')

n = I()
a = LI()
ans = 1000
kabu = 0
vs = list(Counter(a).keys())
i = 0
m = len(vs)
# 極小値で売る、極大値で買う
while i < m:
    if 0 < i < m - 1:
        if vs[i-1] > vs[i] < vs[i+1]:
            # 買う
            ans, kabu = ans % vs[i], ans // vs[i]
            print(i, ans, kabu)

        elif vs[i-1] < vs[i] > vs[i+1]:
            # 売る
            ans, kabu = ans + vs[i] * kabu, 0
            # print(i, ans, kabu)
    else:
        if i == 0:
            if vs[i] < vs[i+1]:
                # 買う
                ans, kabu = ans % vs[i], ans // vs[i]
                # print(i, ans, kabu)
        else:
            if vs[i - 1] < vs[i]:
                # 売る
                ans, kabu = ans + vs[i] * kabu, 0
                # print(i, ans, kabu)
    i += 1
# print(i)

print(ans)


Fixed submission:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')

n = I()
a = LI()
ans = 1000
for i in range(n - 1):
    kabu = 0
    if a[i] < a[i+1]:
        # 出来るだけ買う
        kabu = ans // a[i]
    # 買った株があれば i + 1日目 に売る
    if kabu > 0:
        ans += (a[i + 1] - a[i]) * kabu
print(ans)