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,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'
    
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase

read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()



show_flg=False
show_flg=True

ans=0


n=I()
a=LI()
p=a[0]

x=1000
t=0
s=0
for i in range(n):
    if p<a[i]:
        s=x//p
        
        x+=s*(a[i]-p)
    
    p=a[i]
    
print(x)

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]:
        q, r = divmod(money, A[i])
        money = r + q * A[i + 1]
print(money)

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


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

money = 1000
book = 0
for i in range(1, N):
  if A[i] > A[i - 1]:
    book2 = int(money / A[i - 1])
    book += book2
    money -= book2 * A[i - 1]
  elif A[i] < A[i - 1]:
    money += book * A[i - 1]
    book = 0
  

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

Solution (Python):
n = raw_input()
q = 1000
ais = map(int, raw_input().split())

for u,v in zip(ais,ais[1:]):
	if v > u:
		s = q / u
		q %= u
		q += s * v
print q

Solution (Python):
import sys

sys.setrecursionlimit(1000000)

import bisect
import math
import collections
import heapq


def solve(N, As):
    diffs = [As[i] - As[i - 1] for i in range(1, N)]
    own = 0
    money = 1000
    for i in range(N - 1):
        if own == 0 and diffs[i] > 0:
            k = (money // As[i])
            own = k
            money -= k * As[i]
        elif own > 0 and diffs[i] < 0:
            money += own * As[i]
            own = 0

    if own > 0:
        money += own * As[-1]
    return money



if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

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



dp[0] = 1000
dp[1] = 1000
for start in range(1, n):
    for end in range(start+1, n+1):
        if a[end] - a[start] > 0:
            cnt = dp[start] // a[start]
            money = dp[start] + (a[end] - a[start]) * cnt
            dp[end] = max(dp[end], money)
        else:
            dp[end] = max(dp[end], dp[start])
print(dp[-1])

Solution (Python):
N  = int(input())
A = list(map(int, input().split()))
kabu, money, tmp = 0, 1000, 0

for i in range(N - 1):
    if not kabu and A[i] < A[i + 1]:
        tmp = A[i]
        money, kabu = money % tmp, money // tmp
    elif kabu and A[i] > A[i + 1]:
        money += kabu * A[i]
        kabu = 0

if kabu:
    money += max(tmp, A[-1]) * kabu

print(money)

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

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

Solution (Python):
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N = iRaw()
    As = isRaw()
    isUP=[False]*N
    lastDifVal=As[-1]
    for n in range(N-1,0,-1):
        
        if As[n]!=As[n-1]:
            lastDifVal=As[n]
            isUP[n-1] = lastDifVal>As[n-1]
    money = 1000
    stock = 0
    for n in range(N):
        a = As[n]
        if isUP[n]:
            stock += money//a
            money = money%a
        else:
            money +=stock*a
            stock=0
    
    print(money+stock*As[-1])

main()

Solution (Python):
import heapq
t = 1
def max(a,b):
	if a > b:
		return a
	return b
while t > 0:
	t -= 1
	
	n = int(input())
	v = list(map(int,input().strip().split()))[0:n]
	m = 1000
	i = 0
	while i < n:
		j = i
		
		while j+1 < n and v[j+1] >= v[j]:
			j += 1
		x = m//v[i]
		m = m%v[i]
		temp = x*v[j]
		m += temp
		
		i = j+1
		
	print(m)

Solution (Python):
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

dp = [1000] * (N + 1)

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

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

now=1000
kabu=0
for i in range(n):
    ud=-1
    for j in range(i+1,n):
        if a[i]<a[j]:
            ud=1
            break
        elif a[i]>a[j]:
            ud=0
            break
    if ud==1:
        kabu+=now//a[i]
        now-=now//a[i]*a[i]
    elif ud==0:
        now+=kabu*a[i]
        kabu=0
    
print(now+kabu*a[-1])

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

s = 0
m = 1000
for i in range(n-1):
  if a[i] < a[i+1]:
    tmp = m // a[i]
    s += tmp
    m -= tmp * a[i]
  else:
    m += s * a[i]
    s = 0
m += s * a[n-1]
s = 0
print(m)

Solution (Python):



def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    la = rli()
    m = 1000
    s = 0
    ans = 1000
    for i in range(n-1):
        if s > 0:
            if la[i] <= la[i+1]:
                continue
            m += s*la[i]
            s = 0
        else:
            if la[i] >= la[i+1]:
                continue
            s = m//la[i]
            m -= s*la[i]
        ans = max(ans, m+s*la[i])
    ans = max(ans, m+s*la[n-1])
    print(ans)
        



if __name__ == '__main__':
    main()

Solution (Python):
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def iif(n): return [int(input()) for _ in range(n)]
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    mod = 1000000007
    
    n = ii()
    A = lmi()

    m = 1000
    for i in range(n-1):
        if A[i] < A[i+1]:
            cnt = m // A[i]
            m += (A[i+1] - A[i]) * cnt

    print(m)

    return

main()

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

B=[]
T=[]
if A[0]<A[1]:
    st=ans//A[0]
    ans%=A[0]
for i in range(1,N-1):
    if A[i-1]<=A[i] and A[i]>=A[i+1]: 
        ans+=A[i]*st
        st=0
    
    elif A[i-1]>=A[i] and A[i]<=A[i+1]: 
        st+=ans//A[i]
        ans%=A[i]


if st>0:
    ans+=st*A[-1]
print(ans)

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

        cur=a[i]
print(money)

Solution (Python):
def buy(my_money, A, count):
    return my_money%A, count + my_money//A

def sell(my_money, A, count):
    return my_money + A*count, 0

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

now = 1000  
kabu = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        now, kabu = buy(now, A[i], kabu)
    else:
        now, kabu = sell(now, A[i], kabu)

now, kabu = sell(now, A[N-1], kabu)

print(now)

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

buy=[]
i=0
while(i<=n-2):
    if A[i]<A[i+1]: 
        buy.append(i)
    i=i+1
money=1000
stock=0
for i in buy:
    
    count=money//A[i]
    money=money-count*A[i]
    stock=stock+count
    
    rieki=stock*A[i+1]
    money=money+rieki
    stock=0
print(money)

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


now = 1000
kabu = 0
amari = 1000

for i, a in enumerate(A):
    now = max(kabu*a+amari, now)
    kabu = now//a
    amari = now-a*kabu

print(now)

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

L = []

for i in range(N - 1):
  if A[i] < A[i + 1]:
    L.append(i)
    s = i + 1
    break
else:
  print(1000)
  exit()

f = True
for i in range(s, N - 1):
  if f and A[i] > A[i + 1]:
    L.append(i)
    f = False
  elif not f and A[i] < A[i + 1]:
    L.append(i)
    f = True

ans = 1000
f = True
for i in L:
  if f:
    k = ans // A[i]
    ans -= A[i] * k
    f = False
  else:
    ans += k * A[i]
    f = True

if not f:
  ans += k * A[-1]

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))

B = [0] * n
m = 100
for i in range(n-1,-1,-1):
    if m < A[i]:
        B[i] = 1
    m = A[i]


ans = 1000
k = 0
for i in range(n):
    if (1 <= i < n-1 and A[i-1] <= A[i] and A[i] >= A[i+1]) or (i == n-1 and A[i-1] <= A[i]):
        ans += k * A[i]
        k = 0
    if (1 <= i < n-1 and A[i-1] >= A[i] and A[i] <= A[i+1]) or (i == 0 and A[i] <= A[i+1]):
        kau = ans // A[i]
        ans -= kau * A[i]
        k += kau
print(ans)

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]:
        money+=kabu*a[i]
        kabu=0
    elif a[i]<a[i+1]:
        money+=kabu*a[i]
        kabu=money//a[i]
        money=money%a[i]
    

money+=kabu*a[n-1]

print(money)

Solution (Python):
if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    ans = 1000

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

    print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
yen = 1000
stock = 0
an = []
i = 0
while 1:
    while i <= n - 2 and a[i] >= a[i+1]:
        i += 1
    if i == n - 1:
        print(yen)
        exit()
    stock, yen = divmod(yen, a[i])
    while i <= n-2 and a[i] <= a[i+1]:
        i += 1
    stock, yen = 0, yen + a[i] * stock

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

Solution (Python):
n = int(input())
arr = list(map(int,input().split()))
c = 1000
ans = 0
for i in range(1, len(arr)):
    if arr[i] > arr[i-1]:
        st = c//arr[i-1]
        rem = c%arr[i-1]
        c = st*(arr[i]) + rem
print(c)

Solution (Python):


import sys
input=sys.stdin.readline

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

Solution (Python):
def main():

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

    v = 1000
    i = 0

    while i < N:
        while i < N-1 and A[i+1] <= A[i]:
            i += 1
        buy = A[i]
        i += 1
        while i < N-1 and A[i+1] >= A[i]:
            i += 1
        if i < N:
            sell = A[i]
            v = (v // buy) * sell + (v - v//buy * buy)
            i += 1
    return v

if __name__ == '__main__':
    print(main())