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):
n = int(input())
a = list(map(int, input().split()))
ans = 1000
stock = 0
for i, num in enumerate(a):
  if i == n-1:
    ans += stock*num
  else:  
    if num > a[i+1]:
      ans += stock*num
      stock = 0
    elif num < a[i+1]:
      stock += ans//num
      ans %= num
    else:
      continue
print(ans)

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

M = 1000
S = 0

i = 0
while True:
    while A[i] >= A[i+1]:
        i += 1
        if i == N - 1:
            print(M)
            exit()
    
    C = M // A[i]
    M -= A[i] * C
    S += C

    while A[i] <= A[i+1]:
        i += 1
        if i == N - 1:
            M += S * A[N-1]
            print(M)
            exit()
    
    M += A[i] * S
    S = 0

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


ans=1000

cnt=0
for i in range(1, n):
    if a[i] > a[i - 1]:
        b[i] -= 1
        b[i-1]+=1

for i in range(n):
    if b[i]==1:
        cnt+=ans//a[i]
        ans-=cnt*a[i]
    elif b[i]==-1:
        ans+=cnt*a[i]
        cnt=0

print(ans)

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

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

anow=0
anxt=0

m=1000
s=0

for i in range(n-1):
    if A[i+1]>A[i]:
        s+=m//A[i]
        m-=A[i]*(m//A[i])
    elif A[i+1]<A[i]:
        m+=A[i]*s
        s=0

m+=A[n-1]*s
print(m)

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

cash = 1000
stock = 0

for a, b in zip(A[:-1], A[1:]):
    if a <= b:
        n = int(cash / a)
        cash -= n * a
        stock += n
    else:
        cash += stock * a
        stock = 0

cash += stock * A[-1]
print(cash)

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
ans=1000
dp=[0]
for i in range(N-1):
  if A[i]<A[i+1]:
    dp.append(1)
  else:
    dp.append(0)
o=len(dp)
dp.append(0)
for i in range(o):
  if dp[i]==1 and dp[i+1]==0:
    dp[i]=2
  if dp[i]==0 and dp[i+1]==1:
    dp[i]=-1
p=0
for i in range(N):
  if dp[i]==-1:
    p=ans//A[i]
    ans=ans%A[i]
  if dp[i]==2:
    ans+=A[i]*p
    p=0
print(ans)

Solution (Python):
N=int(input())
l=list(map(int,input().split()))
l2=[]
for i in range(N-1):
   if l[i+1]-l[i]>0:
      l2.append("p")
   elif l[i+1]-l[i]==0:
      l2.append("n")
   else:
      l2.append("m")
money=1000
kabu=0
for i in range(N-1):
   if kabu==0 and l2[i]=="p":
      kabu+=money//l[i]
      money-=(money//l[i])*l[i]
   elif kabu!=0 and l2[i]=="m":
      money+=l[i]*kabu
      kabu=0
if kabu>0:
   money+=kabu*l[-1]
print(money)

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

Solution (Python):
import sys
from io import StringIO
import unittest


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    stock = 0
    money = 1000

    for i in range(1, len(a)):
        add_stock = 0
        
        if a[i - 1] < a[i]:
            add_stock = money // a[i - 1]
            money -= add_stock * a[i - 1]
            stock += add_stock
        elif a[i - 1] > a[i]:
            money += a[i - 1] * stock
            stock = 0

    print(money + stock * a[-1])


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """7
100 130 130 130 115 115 150"""
        output = """1685"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """6
200 180 160 140 120 100"""
        output = """1000"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """2
157 193"""
        output = """1216"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

Solution (Python):
import math
import collections
import bisect
from collections import deque
from copy import copy, deepcopy


def main():
    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)


if __name__ == '__main__':
    main()

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

Solution (Python):
N = int(input())
A = input().split()
for i in range(N):
  A[i] = int(A[i])
money = 1000
stock = 0

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

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
po="n"
pr=A[0]
T=[]
for i in range(1,N):
    if po=="n":
        if pr<A[i]:
            T.append(["Kai",A[0]])
            po="UP"
            pr=A[i]
        else:
            po="DWN"
            pr=A[i]
    elif po=="UP":
        if pr<=A[i]:
            pr=A[i]
        else:
            T.append(["Uri",pr])
            po="DWN"
            pr=A[i]+0
    elif po=="DWN":
        if pr>=A[i]:
            pr=A[i]
        else:
            T.append(["Kai",pr])
            po="UP"
            pr=A[i]
if po=="UP":
    T.append(["Uri",pr])


Money=1000
Kabu=0
for i in range(len(T)):
    if T[i][0]=="Kai":
        Kabu+=Money//T[i][1]
        Money%=T[i][1]
    else:
        Money+=Kabu*T[i][1]
        Kabu=0
print(Money)

Solution (Python):
import math
import sys
from itertools import permutations
input = sys.stdin.readline

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

flag=True
cur=1000
st=0
for i in range(N-1):
    if flag and arr[i+1]>arr[i]:
        st=cur//arr[i]
        cur-=st*arr[i]
        flag=False
    elif (not flag) and arr[i+1]<arr[i]:
        cur+=st*arr[i]
        st=0
        flag=True

cur+=st*arr[N-1]
print(cur)

Solution (Python):
n,*a=map(int,open(0).read().split())
ans=1000
for i,j in zip(a,a[1:]):
    if i<j:
        ans+=ans//i*abs(i-j)
print(ans)

Solution (Python):
N = int(input())
sp_list = list(map(int, input().split()))
stock = 0
money = 1000
for i in range(N-1):
    p_today = sp_list[i]
    p_tomorrow = sp_list[i+1]
    if p_tomorrow > p_today:
        stock += money // p_today
        money -= p_today * (money // p_today)
    if p_tomorrow < p_today:
        money += p_today * stock
        stock = 0

money += sp_list[N-1] * stock

print(money)

Solution (Python):
LI = lambda: list(map(int, input().split()))

N = int(input())
A = LI()


def main():
    ans = 1000
    k = 0
    for i in range(N - 1):
        if A[i] == A[i + 1]:
            continue
        if A[i] > A[i + 1]:
            ans += k * A[i]
            k = 0
        else:
            x = ans // A[i]
            ans -= x * A[i]
            k += x
    ans += k * A[-1]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
As = list(map(int, input().split()))
kabu = 0
money = 1000
buy = True
prev = 1 << 50
for i, a in enumerate(As):
    if buy: 
        if prev < a:
            
            
            kabu += money // prev
            money -= kabu * prev
            buy = False
    else:
        if prev > a:
            
            
            buy = True
            money += kabu * prev
            kabu = 0
    prev = a

print(money+kabu*a)

Solution (Python):


import copy
import random
import bisect 
import fractions 
import math
import sys
import collections
from decimal import Decimal 

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

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()

tmp = 1000
stocks = 0
for i in range(N - 1):
    if A[i] < A[i + 1]: 
        new_stocks = tmp // A[i]
        stocks += new_stocks
        tmp -= new_stocks * A[i]
    else:
        tmp += stocks * A[i]
        stocks = 0
tmp += stocks * A[-1]
print(tmp)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
slst = []
llst = []
stmp = 201
ltmp = 0
for i in a:
    if stmp >= i:
        stmp = i
    else:
        slst.append(stmp)
        stmp = i

for i in reversed(a):
    if ltmp <= i:
        ltmp = i
    else:
        llst.insert(0, ltmp)
        ltmp = i

total = 1000
for i in range(len(slst)):
    cnt = total // slst[i]
    total -= (slst[i] * cnt)
    total += (llst[i] * cnt)

print(total)

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

A = list(map(int, input().split())) + [0]

total = 1000
stock = 0

if A[0] < A[1]:
    stock = total // A[0]
    total -= stock * A[0]

for i in range(1, N):
    if A[i] > A[i+1] and stock != 0:
        total += stock*A[i]
        stock = 0
    if A[i] < A[i+1] and stock == 0:
        stock = total//A[i]
        total -= stock*A[i]

print(total)

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]:
        money += stock * A[i]
        stock = 0
    elif A[i] < A[i + 1]:
        stock += money // A[i]
        money %= A[i]
money += stock * A[N - 1]
print(money)

Solution (Python):
n=int(input(""))
aa=input("").split(" ")
lista=[]
for i in aa:
    lista+=[int(i)]
s=1000
a=0
for i in range(n-1):
    tt=lista[i]
    t=lista[i+1]-tt
    
    if(t>0):
        a+=s//tt
        s%=tt
    elif(t<0):
        
        s+=tt*a
        a=0
s+=a*lista[n-1]
print(s)

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

p = 1000
s = 0

for i, j in zip(A, A[1:]):
  if i < j:
    d, m = divmod(p, i)
    s += d
    p = m
  elif i > j:
    p += s * i
    s = 0

if s != 0:
  p += s * A[-1]

print(p)

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

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
money = 1000
stock = 0
mi = min(A)
last = -1
for i, (a, b) in enumerate(zip(A, A[1:])):
    if a > b:
        if stock > 0:
            money += stock * a
            stock = 0
            last = money
    elif a < b:
        stock += money // a
        money %= a

now = money + stock * A[-1]


print(max(last, now))

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]:
    kabu=money//a[i]
    money=money+(a[i+1]-a[i])*kabu
print(money)

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 += (ans//a[i]) * (a[i+1] - a[i])
    
print(ans)

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
slst = []
llst = []
stmp = 201
ltmp = 0
for i in a:
    if stmp >= i:
        stmp = i
    else:
        slst.append(stmp)
        stmp = i

for i in reversed(a):
    if ltmp <= i:
        ltmp = i
    else:
        llst.insert(0, ltmp)
        ltmp = i

total = 1000
for i in range(len(slst)):
    cnt = total // slst[i]
    total -= (slst[i] * cnt)
    total += (llst[i] * cnt)

print(total)

Solution (Python):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    M = 1000
    S = 0
    A.append(0)

    for i in range(N):
        if A[i] < A[i+1]:
            s_new = M // A[i]
            S += s_new
            M -= s_new * A[i]
        elif A[i] > A[i+1]:
            M += S * A[i]
            S = 0
    print(M)


if __name__ == '__main__':
    main()

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]-A[i])

print(money)

Solution (Python):

import sys,math,collections,itertools
input = sys.stdin.readline

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

cashe = 1000
stake = 0

a =[]
for i in range(N-1):
    a.append(A[i+1]-A[i])

for i in range(N-1):
    if a[i]>0:
        stake += cashe//A[i]
        cashe = cashe%A[i]
    elif a[i]==0:
        continue
    else:
        cashe += stake*A[i]
        stake = 0
cashe += stake*A[-1]
print(cashe)

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

cash = 1000
stock = 0

for i in range(n-1):
    if(a[i] > a[i+1]):
        cash += stock * a[i]
        stock = 0
    elif(a[i] < a[i+1]):
        stock += cash // a[i]
        cash %= a[i]
cash += stock * a[n-1]

print(cash)

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

kane=1000
kabu=0

for i in range(n-1):
    if alist[i] > alist[i+1]:
        kane += kabu * alist[i]
        kabu = 0
    else:
        kaerukabu = kane // alist[i]
        kabu += kaerukabu
        kane -= kaerukabu * alist[i]

print(kane + kabu * alist[n-1])

Solution (Python):
n=int(input())
*a,=map(int, input().split())
upd=[1 if a[i+1]-a[i]>0 else (0 if a[i+1]-a[i]==0 else -1) for i in range(n-1)]

lastbuy=-1
lastsell=-1
now=1000
stock=0
for i in range(n-1):
    
    if upd[i]==1 and stock==0:
        lastbuy=i
        stock+=(now//a[i])
        now-=(now//a[i])*a[i]
    elif upd[i]==-1 and stock>0:
        lastsell=i
        now+=stock*a[i]
        stock=0

if stock>0:
    now+=max(a[lastbuy:])*stock
print(now)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
n_money = 1000
n_stock = 0
for i in range(N-1):
    if A[i+1] > A[i]:
        
        n_buy_stock = n_money // A[i]
        n_stock += n_buy_stock
        n_money = n_money - n_buy_stock * A[i]
    else:
        
        n_money += n_stock * A[i]
        n_stock = 0
n_money += n_stock * A[N-1]
print(n_money)

Solution (Python):
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N = II()
    A = LMIIS()
    money = 1000
    stock = 0
    for i in range(N):
        if i +1 < N and A[i] < A[i+1]:
            stock += money // A[i]
            money %= A[i]
        elif i+1 < N and A[i] > A[i+1] or i == N-1:
            money += stock * A[i]
            stock = 0
    print(money)



    
main()

Solution (Python):
import math

n=int(input())
arr=list(map(int,input().split(" ")))

cap= 1000
stocks=0
for i in range(n-1):
    if arr[i]<arr[i+1]:
        k= math.floor(cap/arr[i])
        stocks+=k
        cap-=k*arr[i]
    elif arr[i]>arr[i+1]:
        cap += stocks * arr[i]
        stocks =0
cap+=stocks*arr[-1]
print(cap)

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

ch = 0
buy = []
sell = []
for i in range(1,N):
    if ch == 0:
        if A[i-1] < A[i]:
            buy.append(A[i-1])
            ch = 1
    else:
        if A[i-1] > A[i]:
            sell.append(A[i-1])
            ch = 0
    if ch == 1 and i == N-1:
        sell.append(A[N-1])
    
ans = 1000
for i in range(len(sell)):
    kabu = ans // buy[i]
    ans %= buy[i]
    ans += kabu * sell[i]

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
m = 1000
b = []
s = []
flag = True
count = 0
while count < n - 1:
    if flag == True:
        if a[count] >= a[count + 1]:
            count += 1
        else:
            b.append(a[count])
            flag = False
    else:
        if a[count] <= a[count + 1]:
            count += 1
        else:
            s.append(a[count])
            flag = True
if len(b) > len(s):
    s.append(a[-1])
k = 0
for i in range(len(b)):
    k += m // b[i]
    m %= b[i]
    m += s[i] * k
    k = 0
print(m)

Solution (Python):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    A = LI()

    s = 0
    f = 1000
    for i in range(N-1):
        f += s * A[i]
        if A[i+1] > A[i]:
            s = f // A[i]
            f -= s * A[i]
        else:
            s = 0
    print(f+s*A[-1])

if __name__ == '__main__':
    main()

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

m=1000
n=0
flag=0
for i in range(N-1):
  if flag==1:
    m += n*A[i]
    n = 0
    flag = 0
  
  if A[i+1]>A[i]:
    buy = m//A[i]
    n += buy
    m -= buy*A[i]
    flag=1

if flag == 1:
  m += n*A[-1]
  n = 0
  flag = 0
  
print(m)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
 
def main():
    n=int(input())
    A=list(map(int, input().split()))
    yen=1000
    kabu=0
    for i in range(n-1):
        if A[i] < A[i+1]:
            kabu+=yen//A[i]
            yen=yen%A[i]
           
        elif A[i] > A[i+1]:
            yen+= kabu*A[i]
            kabu=0
    print(yen+kabu*A[n-1])


 
if __name__=='__main__':
    main()

Solution (Python):
now=1000
n=int(input())
l=list(map(int,input().split()))+[0]
m=l[0]
i=1
while i<n:
    if l[i]<m:m=l[i]
    else:
        while i<n and l[i]<l[i+1]:
            i+=1
        k=now//m
        now=now%m + k*l[i]
        m=l[i]
    i+=1
print(now)

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
    
def do():
    n=INT()
    A=LIST()
    ct=1000
    st=0
    flg=0 
    for i in range(n-1):
        if flg==0:
            if A[i]<A[i+1]:
                st=ct//A[i]
                ct=ct%A[i]
                flg=1
            else:
                pass
        else:
            if A[i]>A[i+1]:
                ct=ct+st*A[i]
                st=0
                flg=0
            else:
                pass
    ct=ct+st*A[n-1]
    print(ct)

if __name__ == '__main__':
    do()

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

Solution (Python):
N = int(input())
arr = list(map(int, input().split()))
ans = 1000
kabu = 0
flg = True
for i in range(N-1):
    if flg and arr[i] < arr[i+1]:
        tmp = ans//arr[i]
        ans -= tmp*arr[i]
        kabu += tmp
        flg = False
    if not flg and arr[i] > arr[i+1]:
        ans += kabu*arr[i]
        kabu = 0
        flg = True
print(ans+kabu*arr[-1])

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

money = 1000
kabu = 0

for i in range(0, len(a)-1):
  if a[i] > a[i+1]:
    money += kabu*a[i]
    kabu = 0
  else:
    kabu += money//a[i]
    money %= a[i]
    
money += kabu*a[-1]
print(money)

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

ny =1000
nk =0

for i in range(n-1):
    if al[i] > al[i+1]:
        if nk >0:
            ny += nk*al[i]
            nk = 0
    elif al[i] < al[i+1]:
        bk = ny // al[i]
        nk += bk
        ny -= bk*al[i]
    else:
        pass

ny += nk*al[n-1]
print(ny)

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

buy = [0] * n
sell = [0] * n

prev = 1000
for i in range(n - 1):
    if a[i+1] > a[i]:
        buy[i] += 1

    if a[i+1] < a[i]:
        sell[i] += 1

for i in range(n - 1, 0, -1):
    if a[i-1] < a[i]:
        buy[i-1] += 1

    if a[i-1] > a[i]:
        sell[i-1] += 1

kabu = 0
money = 1000
for i, e in enumerate(a):
    if buy[i] == 2:
        get = money // e
        kabu += get
        money -= get * e

    if sell[i] == 2:
        money += kabu * e
        kabu = 0

if kabu:
    money += a[-1] * kabu

print(money)

Solution (Python):
















production = True

import sys, math, collections

def input(f = 0, m = 0):

    if m > 0: return [input(f) for i in range(m)]
    else:
        l = sys.stdin.readline()[:-1]

        if f >= 10:
            u = False
            f = int(str(f)[-1])
        else: u = True

        if f == 0: p = [l]
        elif f == 1: p = list(map(int, l.split()))
        elif f == 2: p = list(map(float, l.split()))
        elif f == 3: p = list(l)
        elif f == 4: p = list(map(int, list(l)))
        elif f == 5: p = l.split()

        return p if u else p[0]

def out(l, f = 0, n = True):

    if f == 0: p = str(l)
    elif f == 1: p = " ".join(map(str, l))
    elif f == 2: p = "\n".join(map(str, l))
    elif f == 3: p = "".join(map(str, l))

    print(p, end = "\n" if n else "")

def log(*args):
    if not production:
        print("$$$", end = "")
        print(*args)

enu = enumerate
ter = lambda a, b, c: b if a else c
ceil = lambda a, b: -(-a // b)
flip = lambda a: (a + 1) & 1

def mapl(i, f = 0):

    if f == 0: return list(map(int, i))
    elif f == 1: return list(map(str, i))
    elif f == 2: return list(map(list, i))






def solve():

    n = input(11)
    a = input(1)


    y = 1000

    p = 10 ** 10

    for i in a: 
        if i > p:
            m = y // p
            y -= m * p
            y += m * i
        p = i

    out(y)

    return


solve()

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

money = 1000

buy = A[0]
sell = A[0]

for i in range(N - 1):
    if A[i] > A[i + 1]:
        if sell != 0:
            money += (money // buy) * (sell - buy)
        buy = A[i + 1]
        sell = 0
    else:
        sell = A[i + 1]

if sell != 0:
    money += (money // buy) * (sell - buy)

print(money)

Solution (Python):


"""
Created on Sat Jul 25 20:54:45 2020

@author: naoki
"""


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 = stock + money//A[i]
        money = money%A[i]
    else:
        money = money + stock*A[i]
        stock = 0

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

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]:
        Money += A[i]*Stock
        Stock = 0
    else:
        Stock += Money // A[i]
        Money %= A[i]
print(Stock*A[N-1]+Money)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
M = 1000
min_ai = A[0]
max_ai = A[0]
for i in range(1, N):
    ai = A[i]
    if max_ai > ai:
        M = M % min_ai + (M // min_ai) * max_ai
        min_ai = ai
        max_ai = ai
    else:
        max_ai = ai

M = M % min_ai + (M // min_ai) * max_ai
print(M)

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

A = [A[0]] + [b for a,b in zip(A,A[1:]) if a != b]

if len(A) < 2:
    print(1000)
    exit()

diff = [a-b for a,b in zip(A[1:],A)]
B = [A[0]] if diff[0] > 0 else []

for i,(d1,d2) in enumerate(zip(diff, diff[1:]),start=1):
    if d1*d2 < 0:
        B.append(A[i])
B.append(A[-1])
t = iter(B)
c = 1000
for a,b in zip(t,t):
    c = c//a*b + c%a

print(c)

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

base = A[0]
up = False
down = False
kouho = [base]
for i in range(1, n):
    if A[i] - A[i - 1] > 0:
        up = True
        if down:
            kouho.append(A[i - 1])
            down = False
    elif A[i] - A[i - 1] < 0:
        down = True
        if up:
            kouho.append(A[i - 1])
            up = False
kouho.append(A[-1])
if A[1] < A[0]:
    kouho = kouho[1:]

ans = 1000
num = len(kouho)
money = 1000
stock = 0
for i in range(num):
    rate = kouho[i]
    if not stock:
        stock += money // rate
        money %= rate
    else:
        money += stock * rate
        stock = 0
        ans = max(ans, money)

print(ans)

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

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

Solution (Python):






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

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

    print(amount)
main()

Solution (Python):
import sys
input = sys.stdin.readline

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

stocks = 0
money = 1000

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


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

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

p = [0 for _ in range(N)]

for i in range(1, N - 1):
    if A[i - 1] <= A[i] > A[i + 1]:
        p[i] = 1
    elif A[i - 1] >= A[i] < A[i + 1]:
        p[i] = 2

if A[0] > A[1]:
    p[0] = 1
if A[0] < A[1]:
    p[0] = 2
if A[-2] <= A[-1]:
    p[-1] = 1
if A[-2] > A[-1]:
    p[-1] = 2

res = 1000
kabu = 0

for i in range(N)[::-1]:
    if p[i] == 1:
        break
    if p[i] == 2:
        p[i] = 0

for i in range(N):
    if p[i] == 2:
        v = res // A[i]
        kabu += v
        res -= A[i] * v
    elif p[i] == 1:
        res += kabu * A[i]
        kabu = 0

print(res)

Solution (Python):
import sys
input = sys.stdin.readline

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

pre = 10**18
stock = 0
money = 1000
goup = False
for a in A:
    if a > pre:
        
        count = money//pre
        money -= count*pre
        stock += count
        goup = True
    else:
        if goup:
            money += stock*pre
            stock = 0
        goup = False
    pre = a

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

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
k = 0
m = 1000
flag = 0
for i in range(1,n):
    if flag:
        if A[i]>=A[i-1]:
            continue
        else:
            m += k*A[i-1]
            k = 0
            flag = 0
    else:
        if A[i]<=A[i-1]:
            continue
        else:
            k,m = divmod(m,A[i-1])
            flag = 1
if flag:
    m += A[-1]*k
print(m)

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

kabu = 0
money = 1000

for i in range(len(A)):
    if i == N-1:
        money += kabu * A[i]
        print(money)
        exit()
    else:
        if A[i] < A[i+1]:
            ki = money // A[i]
            kabu += ki
            money -= ki * A[i]

        else:
            money += A[i] * kabu
            kabu = 0

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

money = 1000
stock = 0

schedule = []
for i in range(n-1):
    if A[i] < A[i+1]:
        schedule.append(i)

for i in schedule:
    stock, money = divmod(money, A[i])
    money = money+stock*A[i+1]
print(money)

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

money = 1000
kabu = 0
for i in range(N-1):
    if A[i+1] > A[i]:
        kabu += money // A[i]
        money %= A[i]
    else:
        money += kabu * A[i]
        kabu = 0
money += kabu * A[-1]
kabu = 0
print(money)

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

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

money = 1000
kabu = 0

a = []

for kabuka in given_a:
    if len(a) > 0 and a[-1] == kabuka:
        continue
    else:
        a.append(kabuka)

n = len(a)

if n == 1:
    print(money)
    exit()
    
for i in range(n):
   if i == 0:
       if a[i+1] < a[i]:
           continue
       else:
           kabu += money // a[i]
           money %= a[i]
   elif i == n-1:
       money += kabu * a[i]
       kabu = 0
   else:
       if a[i-1] < a[i] and a[i] > a[i+1]:
           money += kabu * a[i]
           kabu = 0
       if a[i-1] > a[i] and a[i] < a[i+1]:
           kabu += money // a[i]
           money %= a[i]

print(money)

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