Problem:
 Score: 400 points    Problem Statement  To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.  He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows:   A_1 yen on the 1 -st day, A_2 yen on the 2 -nd day, ..., A_N yen on the N -th day.   In the i -th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time .   Buy stock: Pay A_i yen and receive one stock.  Sell stock: Sell one stock for A_i yen.   What is the maximum possible amount of money that M-kun can have in the end by trading optimally?      Constraints   2 \leq N \leq 80  100 \leq A_i \leq 200  All values in input are integers.         Input  Input is given from Standard Input in the following format:  N  A_1  A_2  \cdots  A_N       Output  Print the maximum possible amount of money that M-kun can have in the end, as an integer.        Sample Input 1 7
100 130 130 130 115 115 150      Sample Output 1 1685  In this sample input, M-kun has seven days of trading. One way to have 1685 yen in the end is as follows:   Initially, he has 1000 yen and no stocks.  Day 1 : Buy 10 stocks for 1000 yen. Now he has 0 yen.  Day 2 : Sell 7 stocks for 910 yen. Now he has 910 yen.  Day 3 : Sell 3 stocks for 390 yen. Now he has 1300 yen.  Day 4 : Do nothing.  Day 5 : Buy 1 stock for 115 yen. Now he has 1185 yen.  Day 6 : Buy 10 stocks for 1150 yen. Now he has 35 yen.  Day 7 : Sell 11 stocks for 1650 yen. Now he has 1685 yen.   There is no way to have 1686 yen or more in the end, so the answer is 1685 .       Sample Input 2 6
200 180 160 140 120 100      Sample Output 2 1000  In this sample input, it is optimal to do nothing throughout the six days, after which we will have 1000 yen.       Sample Input 3 2
157 193      Sample Output 3 1216  In this sample input, it is optimal to buy 6 stocks in Day 1 and sell them in Day 2 , after which we will have 1216 yen.

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    tmp = 1000
    for i in range(N-1):
        if A[i] < A[i+1]:
            s = tmp//A[i]
            tmp %= A[i]
            tmp += s * A[i+1]
    print(tmp)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
 
money = 1000
stock = 0
 
for i in range(n-1):
  if a[i+1] > a[i]:
    stock = money // a[i]
    money = money - stock*a[i] + stock*a[i+1]
 
print(money)

Solution (Python):
def d_road_to_millionaire():
    N = int(input())
    A = [int(i) for i in input().split()]

    money = 1000
    stock = 0
    for i in range(N - 1):
        stocks = money // A[i] if A[i] < A[i + 1] else 0
        money += (A[i + 1] - A[i]) * stocks
    return money

print(d_road_to_millionaire())

Solution (Python):
N = int(input(""))
a = input("").split(" ")
a = [int(i) for i in a]
m = 1000
list_ = []

for j in range(0, N-1):
    if a[j] < a[j + 1]:
        n = m // a[j]
        k = (a[j + 1] - a[j]) * n
        m = m + k

print(m)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
mode = 0
money = 1000
kabu = 0
for i in range(N):
  if i == 0:
    if A[i+1] > A[i]:
      kabu += 1000//A[i]
      money -= kabu*A[i]
      mode = 1
    else:
      continue
  elif i == N-1:
    money += kabu*A[i]
  else:
    if mode == 1:
      if A[i] >= A[i-1]:
        if A[i] > A[i+1]:
          money += kabu*A[i]
          kabu = 0
          mode = 0
        else:
          continue
    else:
      if A[i] < A[i+1]:
        kabu += money//A[i]
        money -= kabu*A[i]
        mode = 1
      else:
        continue
print(money)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]

ans = 1000

for i in range(n-1):
  ans += (ans//a[i])*max(0, (a[i+1]-a[i]))

print(ans)

Solution (Python):
n,*a=map(int,open(0).read().split())
x=1000
for i in range(n-1):x+=x//a[i]*max(0,a[i+1]-a[i])    
print(x)

Solution (Python):


import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
m = 1000
kabu = 0
buy = True
buy_val = 100000

for i in range(len(a)):
    if i == len(a)-1:
        m += kabu * a[i]
        kabu = 0

    elif not buy and a[i] > a[i+1]:
        m += kabu * a[i]
        kabu=0
        buy=True
    elif buy and a[i] < a[i+1]:
        kabu=int(m/a[i])
        m -= kabu * a[i]
        buy=False

print(m)

Solution (Python):
n = int(input())
a = [0]+list(map(int, input().split()))

'''
ans = 1000
for i in range(n - 1):
    x = a[i]
    y = a[i + 1]
    if x < y:
        k = ans // x
        ans %= x
        ans += k * y

print(ans)
'''

dp = [0] * (n + 10)
dp[1] = 1000
for i in range(2, n + 1):
    dp[i] = dp[i - 1]
    for j in range(1, i):
        x = dp[j] // a[j]
        y = dp[j] + (a[i] - a[j]) * x
        dp[i] = max(dp[i], y)

ans = dp[n]
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

current_money = 1000
for i in range(N-1):
    stock = 0
    if A[i] < A[i+1]:
        stock = current_money // A[i]
    current_money += (A[i+1] - A[i]) * stock

print(current_money)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

current_money = 1000
for i in range(N-1):
    stock = 0
    if A[i] < A[i+1]:
        stock = current_money // A[i]
    current_money += (A[i+1] - A[i]) * stock

print(current_money)

Solution (Python):
n = int(input())
a = list(map(int, input().split(' ')))

money = 1000
for i in range(n-1):
    stocks = 0
    if a[i] < a[i+1]:
        stocks = money//a[i]

    money += (a[i+1]-a[i])*stocks

print(money)

Solution (Python):
n = int(input())
A = [int(x) for x in input().split()]

money = 1000

kabu_c = 0

l = list()
for i in range(n-1):
    if A[i+1] - A[i] > 0:
        l.append(1)
    else:
        l.append(0)
for idx, i in enumerate(l):
    
    if i == 1 and money - A[idx] >= 0:
        kabu_c = money // A[idx]
        money = money - (kabu_c * A[idx])
    
    if i == 0:
        money = money + (kabu_c * A[idx])
        kabu_c = 0

if kabu_c > 0:
    money = money + (kabu_c * A[n-1])
print(money)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
assets = 1000               



flag = []
for n in range(N-1):
    if A[n] <= A[n+1]:      
        flag.append(1)
    else:
        flag.append(0)      
flag.append(0)              


amount = 0                  
for idx, f in enumerate(flag):      
    if f == 1:
        purchase = assets // A[idx] 
        amount += purchase
        assets -= purchase * A[idx]
    else:
        assets += amount * A[idx]
        amount = 0
    

print(assets)

Solution (Python):
N = int(input())
money = 1000
A = list(map(int, input().split()))
A.append(0)
kabu = 0
for i in range(N):
    if A[i] <= A[i+1]:
        buy = money//A[i]
        money -= buy*A[i]
        kabu += buy
    if A[i] >= A[i+1]:
        money += kabu*A[i]
        kabu = 0
print(money)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
money=1000
stock=0
for i in range(n-1):
  if A[i]<A[i+1]:
    stock=money//A[i]
    money-=stock*A[i]
    money+=stock*A[i+1]
print(money)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

prev = a[0]
mon = 1000
stc = 0

for i in range(1, n):
    
    if prev < a[i]:
        stc = mon // prev
        mon = mon - stc * prev
        mon = stc * a[i] + mon
        
    elif prev >= a [i]:
        pass
        
    prev = a[i]



print(mon)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

current = 1000
kabu = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        kabu += current // A[i]
        current = current % A[i]
    elif A[i] > A[i+1]:
        current += kabu * A[i]
        kabu = 0
else:
    current += kabu * A[-1]

print(current)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
money = 1000
kabu = 0
for i in range(n-1):
    if a[i] < a[i+1]:
        kabu = money//a[i] * a[i+1] 
        money = (money % a[i]) + kabu
print(money)

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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 pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()

    r = 1000
    t = []
    sf = True
    for i in range(n-1):
        if sf:
            if a[i] >= a[i+1]:
                continue
            t.append(a[i])
            sf = False
        else:
            if a[i] <= a[i+1]:
                continue
            t.append(a[i])
            sf = True

    if len(t) == 0:
        return r

    if t[-1] != a[-1]:
        t.append(a[-1])

    for i in range(len(t)//2):
        b = t[i*2]
        c = t[i*2 + 1]
        k = r // b
        r += (c-b) * k

    return r

print(main())

Solution (Python):
n, *a = map(int, open(0).read().split())
a += 1,
m = 1000

def groupby():
  c, res = [], []
  for i in range(n + 1):
    if a[i-1] <= a[i]:
      pass
    else:
      res += [c[0], c[-1]],
      c = []
    c += a[i],
  return res

for i, j in groupby():
  m = m // i * j + m % i
print(m)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
x=1000
for i in range(N-1):
  if A[i]<A[i+1]:
    x+=(x//A[i])*(A[i+1]-A[i])
print(x)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))

budget = 1000
stock = 0
for i in range(n-1):
    if l[i] < l[i+1]:
        budget = budget + stock * l[i]
        stock = budget // l[i]
        budget = budget % l[i]
    elif l[i] > l[i+1]:
        budget = budget + stock * l[i]
        stock = 0
else:
    budget += stock*l[-1]
    stock = 0

print(budget)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
ans = 1000
for i in range(n-1):
    x = ans // a[i]
    if a[i] < a[i+1]:
        ans -= x * a[i]
        ans += x * a[i+1]
print(ans)

Solution (Python):
_input = input
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)





m=input().split()
n=int(m[0])

s=list(map(int, input().split()))

day_money = [0] * n
day_money[0] = 1000

for sell_day in range(n):
	for buy_day in range(sell_day):
		day_money[sell_day] = max(day_money[buy_day], (day_money[buy_day]//s[buy_day])*s[sell_day]+day_money[buy_day]%s[buy_day])
		
		
print(day_money[n-1])

input = _input

Solution (Python):
n=int(input())
a=[float('inf')]
a+=list(map(int,input().split()))
d=[1000 for i in range(n+1)]
for i in range(1,n+1):
    d[i]=max(d[i-1],d[i-1]//a[i-1]*a[i]+d[i-1]%a[i-1])
print(d[-1])

Solution (Python):
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    deff_list = [0]
    for i in range(1,N):
        deff_list.append(As[i] - As[i-1])

    prev = 1000
    res = 1000
    for i in range(1, N):
        if deff_list[i] >= 0:
            res = (prev // As[i-1]) * As[i] + prev % As[i-1]
        
        prev = res
    
    print(res)



if __name__ == "__main__":
    resolve()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mon = 1000  
cnt = 0  
cur = A[0]
for i in range(1,len(A)):
  sec = A[i]
  
  if cur < sec:
    
    if mon > cur:
      cnt = mon//cur
      mon = mon%cur
  
  elif cur > sec:
    mon += cur * cnt
    cnt = 0
  cur = sec
if cnt > 0:
  mon += A[-1]*cnt
print(mon)

Solution (Python):
n = int(input())

a_list = list(map(int, input().split()))
dp_list = [0]*n
dp_list[0] = 1000
for i in range(1,n):
    dp_list[i] = dp_list[i-1]
    for j in range(i):
        v = int(dp_list[j]/a_list[j])
        w = dp_list[j] + (a_list[i] - a_list[j]) * v
        dp_list[i] = max(dp_list[i],w)

print(dp_list[n-1])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

money = 1000
stock = 0
for i in range(n):
    
    money += stock * a[i]
    stock = 0

    
    if i != n - 1 and a[i] < a[i + 1]:
        stock = money // a[i]
        money %= a[i]

print(money)

Solution (Python):
n=int(input())
a=[int(x) for x in input().rstrip().split()]
now=1000
cnt=0
flag=0

for i in range(n-1):
    if flag==1:
        now+=cnt*a[i]
        cnt=0
        flag=0
        if a[i]<a[i+1]:
            cnt=now//a[i]
            now=now-cnt*a[i]
            flag=1
            continue


    if a[i]<a[i+1]:
        cnt=now//a[i]
        now=now-cnt*a[i]
        flag=1

if flag==1:
    now+=cnt*a[n-1]
print(now)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
kane=1000


mini=A[0]
maxi=0
jyoutai="buy"
num=0


for i in range(1,N):
    
    if jyoutai=="buy":
        if A[i]<mini:
            mini=A[i]
        elif A[i]==mini and num>0:
            pass
        
        elif A[i]>=mini and num==0:
            num=kane//mini
            kane=kane%mini
            jyoutai="sell"
            maxi=A[i]
        
    
    elif jyoutai=="sell":
        if A[i]>maxi:
            maxi=A[i]
        elif A[i]==maxi and num==0:
            pass
        elif A[i]<=maxi and num>0:
            kane+=num*maxi
            num=0
            jyoutai="buy"
            mini=A[i]
if num>0:
    kane+=num*maxi
print(kane)

Solution (Python):
N=int(input())
ls=[int(s) for s in input().split()]
money=1000
stock=0
for i in range(N-1):
  if ls[i]<ls[i+1]:
    s=money//ls[i]
    money-=s*ls[i]
    stock+=s
  elif ls[i]>ls[i+1]:
    money+=ls[i]*stock
    stock=0
money+=ls[N-1]*stock

print(money)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter
import decimal
import re












import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
money = 1000
kabu = 0
for i in range(1,n):
    if A[i-1] < A[i]:
        kabu = money // A[i-1]
        money -= kabu * A[i-1]
        money += kabu * A[i]
        kabu = 0
    
print(money)

Solution (Python):
p = 1000
N = int(input())
A = list(map(int, input().split()))

for i in range(1, N):
    if A[i] > A[i - 1]:
        p = p // A[i - 1] * A[i] + p % A[i - 1]

print(p)

Solution (Python):
n = int(input())
A = [*map(int, input().split())] + [0]
yen, stock = 1000, 0
now = A[0]
for nxt in A[1:]:
    if now < nxt:
        stock += yen // now
        yen -= yen // now * now
    else:
        yen += stock * now
        stock = 0
    now = nxt
print(yen + stock * now)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = 0
c = 1000
for i in range(n-1):
    if a[i] < a[i+1]:
        d = c // a[i]
        b += d
        c -= d * a[i]
    elif a[i] > a[i+1]:
        c += b * a[i]
        b = 0
if b > 0:
    c += a[-1] * b
print(c)

Solution (Python):
n = int(input())
A = [*map(int, input().split())] + [0]
yen, stock = 1000, 0
nxt = A[0]
for now in A[1:]:
    now, nxt = nxt, now
    if now < nxt:
        stock += yen // now
        yen -= yen // now * now
    else:
        yen += stock * now
        stock = 0
print(yen + stock * nxt)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

yen = 1000
stocks = 0

for i in range(N):
  if i == N-1:
    yen += stocks * A[i]
    stocks = 0
    break
  
  if A[i] > A[i+1]:
    
    yen += stocks * A[i]
    stocks = 0
  else:
    
    num = yen // A[i]
    stocks += num
    yen -= A[i] * num

print(yen)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    okane = 1000

    for a, b in zip(A, A[1:]):
        if a <= b:
            q, r = divmod(okane, a)
            okane = q * b + r

    print(okane)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
ls = list(map(int, input().split()))

curr = 1000
stock = 0

for i in range(n - 1):
    if ls[i] < ls[i + 1] and curr >= ls[i]:
        stock += curr // ls[i]
        curr -= stock * ls[i]
    elif ls[i] > ls[i + 1]:
        curr += stock * ls[i]
        stock = 0 

curr += stock * ls[i + 1]
stock = 0

print(curr)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7



n = I()
A = LI()
dp = [-INF] * n
dp[0] = 1000
for i in range(1, n):
    ret = dp[i - 1]
    for j in range(i):
        ret = max(dp[j] // A[j] * A[i] + dp[j] % A[j], ret)
    dp[i] = ret


print(dp[n - 1])

Solution (Python):
N=int(input())
A=[0]*N
A=list(map(int,input().split()))
money=1000
money_temp=1000
kazu=0
ma=0
mi=float('inf')
stop=0
for i in range(0,N-1):
    money=money+A[i]*kazu
    kazu=0
    if(A[i]<A[i+1]):
        kazu=money//A[i]
        money=money-A[i]*kazu

    elif(A[i+1]<=A[i]):
        pass

money=money+A[N-1]*kazu
print(money)

Solution (Python):
def 買う(株, 金, 株価):
    買う株 = 金 // 株価
    金 = 金 - 買う株*株価
    株 += 買う株
    return 株, 金

def 売る(株, 金, 株価):
    金 = 金 + 株*株価
    株 = 0
    return 株, 金

n = int(input())
株価 = [int(i) for i in input().split()]
株価.append(-1)

株 = 0
金 = 1000

for i in range(n):
    if 株価[i] < 株価[i+1]:
        株, 金 = 買う(株, 金, 株価[i])
    else:
        株, 金 = 売る(株, 金, 株価[i])

print(金)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = 1000
cnt = 0
for i in range(0,len(a)-1):
    if a[i]<a[i+1]:
        cnt = ans//a[i]
        ans = ans-a[i]*cnt
        ans = ans+a[i+1]*cnt
print(ans)

Solution (Python):
def main():
    N=int(input())
    A=[int(_) for _ in input().split()]
    M=1000
    for i in range(N-1):
        stock = 0
        if A[i]<A[i+1]:
            stock=M//A[i]
        M+=(A[i+1]-A[i])*stock
    print(M)

main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
k = 0
ans = 1000

for i in range(n-1):
    if a[i] < a[i+1]:
        k = ans//a[i]
        ans -= a[i]*k
        ans += a[i+1]*k

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
money = 1000
kabu = 0
for i in range(n-1):
  if kabu==0:
    if a[i]<=a[i+1]:
      kabu += money//a[i]
      money %= a[i]
  else:
    if a[i]>a[i+1]:
      money += kabu*a[i]
      kabu = 0
print(money+kabu*a[-1])

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    dp = [0]*(N+1)
    dp[0] = 1000
    for i in range(1, N+1):
        for j in range(0, i-1):
            
            m = A[j]
            for k in range(j, i-1):
                m = min(m, A[k])
            dp[i] = max(dp[i], dp[j]//m * A[i-1] + dp[j] % m)
        dp[i] = max(dp[i], dp[i-1])

    print(dp[N])


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
a.append(0)
x,y=1000,0
for i in range(n):
    if a[i]>=a[i+1]:
        x+=y*a[i]
        y=0
    else:
        y+=x//a[i]
        x=x%a[i]
print(x)

Solution (Python):

n=int(input())
a=list(map(int,input().split()))
an=[]
for i in range(1,n):
    if a[i]>a[i-1]:
        an.append(a[i-1])
        if i==n-1:
            an.append(a[i])
        break
pm=0
for j in range(i+1,n):
    
    if pm==0:
        if a[j]>=a[j-1]:
            if j==n-1:
                an.append(a[j])
            continue
        else:
            an.append(a[j-1])
            pm=1
    else:
        if a[j]<=a[j-1]:
            continue
        else:
            an.append(a[j-1])
            pm=0
            if j==n-1:
                an.append(a[j])

ans=1000
k=0
for i in range(len(an)):
    if i%2==0:
        k=ans//an[i]
        ans-=k*an[i]
    else:
        ans+=k*an[i]
        k=0
print(ans)

Solution (Python):
days = int(input())
vals = [int(x) for x in input().split()]
has = 1000
for i in range(days - 1):
    if vals[i] <= vals[i+1]:
        can, has = divmod(has, vals[i])
        has += can * (vals[i+1])
print(has)

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    dp = [0]*(N+1)
    dp[0] = 1000
    for i in range(1, N+1):
        for j in range(0, i-1):
            
            dp[i] = max(dp[i], dp[j]//A[j] * A[i-1] + dp[j] % A[j])
        dp[i] = max(dp[i], dp[i-1])

    print(dp[N])


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
given_A = list(map(int, input().split()))
A = []
for kabuka in given_A:
    if len(A) > 0 and kabuka == A[-1]:
        continue
    else:
        A.append(kabuka)


if len(A) == 1:
    print(1000)
    exit()

money = 1000
stock = 0
n = len(A)
for i in range(len(A)):
    if i == 0:
        if A[i] < A[i + 1]:
            stock = money // A[i]
            money = money % A[i]
    elif i == n - 1:        
        if A[i - 1] < A[i]:
            money += stock*A[i]
            stock = 0
    else:
        if (A[i - 1] < A[i]) & (A[i] > A[i + 1]):
            money += stock*A[i]
            stock = 0
        elif (A[i - 1] > A[i]) & (A[i] < A[i + 1]):
            stock = money // A[i]
            money = money % A[i]
print(money)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
a.append(0)
x,y=1000,0
for i in range(n):
    if a[i]>a[i+1]:
        x+=y*a[i]
        y=0
    else:
        y+=x//a[i]
        x=x%a[i]
print(x+y*a[-2])

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

dp = [0] * N
dp[0] = 1000

for i in range(1, N):
    dp[i] = dp[i - 1]
    for j in range(i):
        V = dp[j] // A[j]
        W = dp[j] + (A[i] - A[j]) * V
        dp[i] = max(dp[i], W)

print(dp[N - 1])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))







ans = 1000
dp = [-1 for i in range(N)]
dp[0] = 1000

for i in range(1, N):
    m = dp[i-1]
    for j in range(i):
        stock = dp[j] // A[j]
        m = max(m, (dp[j] // A[j] * A[i] + dp[j] % A[j]))
    dp[i] = m
print(dp[N-1])

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
 
CurrentMoney = 1000

for i in range(N - 1):
    Stocks = 0
    if A[i] < A[i+1]:
        Stocks = CurrentMoney // A[i]
    CurrentMoney += (A[i + 1] - A[i]) * Stocks

print(CurrentMoney)

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    money = 1000
    for i in range(1, N):
        if A[i-1] < A[i]:
            v = money//A[i-1]  
            money %= A[i-1]  
            money += v*A[i]
    print(money)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    money = 1000
    for i in range(1, N):
        if A[i-1] < A[i]:
            v = money//A[i-1]  
            money -= v*A[i-1]
            money += v*A[i]
    print(money)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
*A, = map(int,input().split())

Y = [1000] * N

for i in range(N):
    a = A[i]
    y = Y[i]
    n = y//a
    for j in range(i+1,N):
        b = A[j]
        Y[j] = max(Y[j],y + (b-a)*n,y)

print(Y[-1])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

ans = 1000
for i in range(N-1):
    if A[i] < A[i+1]:
        ans += (A[i+1] - A[i]) * (ans // A[i])
print(ans)

Solution (Python):



n=int(input())
*a,=map(int, input().split())

yen=1000

for i in range(n-1):
    if a[i]<a[i+1]:
        yen = (yen//a[i])*a[i+1]+yen%a[i]
print(yen)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

money = 1000
for i in range(1, N):
    if A[i - 1] < A[i]:
        money = money % A[i - 1] + A[i] * (money // A[i - 1])
print(money)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
money = 1000
for i in range(n-1):
    if a[i] <= a[i+1]:
        money = money//a[i]*a[i+1] + money%a[i]
print(money)

Solution (Python):

n=int(input())
alist=list(map(int,input().split()))
m_p=alist[0]
money=int(1000%alist[0])
kabu=int(1000/alist[0])
for i in range(n):
  if m_p<alist[i]:
    m_p=alist[i]
    money+=kabu*m_p
  elif m_p>alist[i]:
    money+=kabu*m_p
    m_p=alist[i]
  else:
    continue
  kabu=int(money/m_p)
  money=int(money%m_p)
money+=kabu*m_p
print(money)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
x=1000
for i in range(N - 1):
  s = A[i]
  t = A[i +1]
  if s < t:
    k = x//s
    x %= s
    x += k*t

print(x)

Solution (Python):

N = int(input())
A = list(map(int, input().split()))

 
kabu = 0
money = 1000
for i in range(N-1):
  if A[i] < A[i+1]:
    mod,money = divmod(money , A[i])
    kabu += mod
  else:
      money = money + A[i] * kabu
      kabu = 0

money = money + A[N-1]*kabu
print(money)

Solution (Python):

N = int(input())
A = list(map(int, input().split()))


kabu = 0
money = 1000
for i in range(N-1):
  if A[i] < A[i+1]:
    mod,money = divmod(money , A[i])
    kabu += mod
  if A[i] > A[i+1]:
    money = money + A[i] * kabu
    kabu = 0

money = money + A[N-1]*kabu
print(money)

Solution (Python):
n = int(input())
arr  = list(map(int,input().split()))

current_money = 1000
for i in range(n-1):
    stocks = 0
    if (arr[i] < arr[i+1]):
        stocks = current_money//arr[i]
        current_money += (arr[i+1]-arr[i])*stocks
print(current_money)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))

money=1000

chart=[a[0]]

for kabuka in a:
    if kabuka==chart[-1]:
        continue
    else:
        chart.append(kabuka)

days=len(chart)
kabu=0

if days==1:
    print(money)
    exit()

for i in range(days):
    if i==0:
        if chart[0]<chart[1]:
            kabu=money//chart[0]
            money%=chart[0]

    elif i==days-1:
        money+=kabu*chart[i]
        kanu=0
    
    else:
        if chart[i-1]<chart[i] and chart[i]>chart[i+1]:
            money+=kabu*chart[i]
            kabu=0

        if chart[i-1]>chart[i] and chart[i]<chart[i+1]:
            kabu=money//chart[i]
            money%=chart[i]

print(money)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))

money=1000

chart=[a[0]]

for kabuka in a:
    if kabuka==chart[-1]:
        continue
    else:
        chart.append(kabuka)

days=len(chart)
kabu=0

if days==1:
    print(money)
    exit()

for i in range(days):
    if i==0:
        if chart[0]<chart[1]:
            kabu=money//chart[0]
            money%=chart[0]

    elif i==days-1:
        money+=kabu*chart[i]
        kanu=0
    
    else:
        if chart[i-1]<chart[i] and chart[i]>chart[i+1]:
            money+=kabu*chart[i]
            kabu=0

        if chart[i-1]>chart[i] and chart[i]<chart[i+1]:
            kabu=money//chart[i]
            money%=chart[i]

print(money)

Solution (Python):


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    A = list(map(int, input().split()))

    return N, A

def main(N: int, A: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 日数（2 <= N <= 80）
        A (list): i日目の株価（100 <= A_i <= 200）
    """
    
    dp = [-1 for n in range(N)]
    dp[0] = 1000
    for i in range(1, N):
        dp[i] = dp[i - 1]
        for j in range(i):
            V = dp[j] // A[j]
            W = dp[j] + (A[i] - A[j]) * V
            dp[i] = max(dp[i], W)

    
    print(dp[N - 1])

if __name__ == "__main__":
    
    N, A = get_input()

    
    main(N, A)

Solution (Python):
import numpy as np

def buy_stock(have_money, have_stock, have_stock_valuation, stock_price):
    stock_num = have_money // stock_price
    have_money -= stock_num * stock_price
    have_stock += stock_num
    have_stock_valuation += stock_num * stock_price

    return have_money, have_stock, have_stock_valuation

def sell_stock(have_money, have_stock, have_stock_valuation, stock_price):
    have_money += have_stock * stock_price
    have_stock = 0
    have_stock_valuation = 0

    return have_money, have_stock, have_stock_valuation

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    A = np.array(A)
    have_money = 1000
    have_stock = 0
    have_stock_valuation = 0
    call_status = True

    for i in range(N):

            if call_status:
                if i == N - 1:
                    continue
                if A[i] < A[i+1]:
                    have_money, have_stock, have_stock_valuation = buy_stock(have_money, have_stock, have_stock_valuation, A[i])
                    call_status = False
                if not call_status:
                    if have_stock_valuation / have_stock < A[i]:
                        have_money, have_stock, have_stock_valuation = sell_stock(have_money, have_stock, have_stock_valuation,  A[i])
                        call_status = True
            else:
                if have_stock_valuation / have_stock < A[i]:
                    have_money, have_stock, have_stock_valuation = sell_stock(have_money, have_stock, have_stock_valuation,  A[i])
                    call_status = True
                if call_status:
                    if i == N - 1:
                        continue
                    if A[i] < A[i+1] and call_status:
                        have_money, have_stock, have_stock_valuation = buy_stock(have_money, have_stock, have_stock_valuation, A[i])
                        call_status = False
            
    print(have_money)