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
from math import factorial

MOD = 10 ** 9 + 7
INF = float('inf')

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

mny = 1000
m = A[0]
for i in range(1, N):
    if A[i] < m:
        m = A[i]
    if A[i] > m:
        if i == N-1:
            num = mny // m
            mny += num * (A[i] - m)
        elif A[i+1] <= A[i]:
            num = mny // m
            mny += num * (A[i] - m)
            m = A[i+1]

print("{}".format(mny))

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
INF=float('inf')
dp=[-INF]*(n+1)
dp[0]=1000

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

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

a.append(0)

money = 1000
h = a[0]
l = a[0]

for i in a:
  if h < i:
    h = i
  elif h > i and h > l:
    money = money//l * h + money%l
    h = l = i
  elif h > i:
    h = i
  if l > i:
    l = i

print(money)

Solution (Python):
n = int(input())
ls = list(map(int,input().split()))
mon = 1000
beet = 0
p = []
m = []
if ls[1]-ls[0] > 0:
    beet += int(mon//ls[0])
    mon -= ls[0]*int(mon//ls[0])
    be = True
else:
    be = False
for i in range(n-1):
    if ls[i] < ls[i+1]:
        if be == False:
            beet += int(mon//ls[i])
            mon -= ls[i]*int(mon//ls[i])
            be = True
    if ls[i] > ls[i+1]:
        if be == True:
            mon += ls[i] * beet
            beet = 0
            be = False
if beet > 0:
    mon += beet*ls[-1]
print(mon)

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

flag = [-1]*n
t = 0
for i in range(n-1):
  if t == 0:
    if a[i] < a[i+1]:
      flag[i] = 0
      t = 1
  elif t == 1:
    if a[i+1] < a[i]:
      flag[i] = 1
      t = 0

if t == 1:
  for i in range(n-1, -1, -1):
    if flag[i] == 0:
      flag[i] == -1
      break
    if a[i] < a[i-1]: continue
    flag[i] = 1
    break
    
ans = 1000
s = 0
for i in range(n):
  if flag[i] == 0:
    s = ans//a[i]
    ans %= a[i]
  elif flag[i] == 1:
    ans += s*a[i]
    s = 0
print(ans)

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

def main(n,a):
    m = 1000
    f = 0
    for i in range(n):
        if i>0:
            if a[i]>a[i-1]:
                m += f*a[i]
                f = 0
        if i<n-1:
            if a[i]<a[i+1]:
                f += m//a[i]
                m %= a[i]
    if f!=0:
        m += f*a[i-1]
    print(m)
            

if __name__=="__main__":
    n,a = getval()
    main(n,a)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
m = 1000
stock = 0
for i in range(N-1):
    if A[i] < A[i+1]:
        stock = m//A[i]
        m = m%A[i] + stock*A[i+1]      
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]:
        q, x = divmod(x, A[i])
        x += q*A[i+1]
print(x)

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

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

buy = 201
ans = 1000
for i in range(n):
    if al[i] < buy:
        buy = al[i]

    elif al[i] > buy:
        ans = ans//buy*al[i] + ans%buy
        buy = al[i]
    

print(int(ans))

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

flag = 0
y = 1000

for i in range(1,N):
    if A[i-1] < A[i] and flag == 0:
        x = y//A[i-1]
        y = y % A[i-1]
        flag = 1
    if (A[i-1] > A[i]) and flag == 1:
        y = y + A[i-1]*x
        flag = 0
    if flag == 1 and i == N-1:
        y = y + A[i]*x

print(y)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A = [1000] + A + [0]

ans = 1000
stock = 0

for i, a in enumerate(A):
    if i > 0 and i < N + 1:
        if A[i-1] >= a and A[i+1] >= a:
            stock += ans // a
            ans -= a * (ans // a)

        if A[i-1] <= a and A[i+1] <= a:
            ans += stock * a
            stock = 0
        
print(ans)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    A = LI()
    
    
    DP = [defaultdict(int) for _ in range(N+1)]
    DP[0][0] = 1000
    for i in range(N):
        for j,money in DP[i].items():
            
            DP[i+1][j] = max(DP[i+1][j], money)
            
            DP[i+1][0] = max(DP[i+1][0], money + j*A[i])

        
        remain = DP[i][0]%A[i]
        buy = DP[i][0]//A[i]
        DP[i+1][0+buy] = max(DP[i+1][0+buy], remain)
    ans = DP[-1][0]
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    a = LI()

    money = 1000
    mn, mx = a[0], a[0]
    up = True

    for price in a:
        if mx <= price:
            up = True
            mx = price
        else:
            if up:
                money = money//mn * mx + money%mn
            up = False
            mn, mx = price, price

    money = money//mn * mx + money%mn
    
    print(money)
            

main()

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
num = 1000
flag = True
flag2 = True
for i in range(1,N):
  if a[i-1]<a[i] and flag == True:
    mi = a[i-1]
    ma = a[i]
    flag = False
  elif a[i-1]<a[i] and flag == False:
    ma = a[i]
  elif a[i-1]>a[i] and flag == False:
    num = (num//mi)*ma+(num%mi)
    flag = True
  if i == N-1 and flag == False:
    num = (num//mi)*ma+(num%mi)
print(num)

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

groups = []
prev = A[0]
for i in range(1,n):
    if A[i] != prev:
        groups.append(prev)
        prev = A[i]
groups.append(prev)

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

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

money += stock*groups[-1]

print(money)

Solution (Python):


a=int(input())






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

now=1000
buy=0
sell=0
kabu=0
for i in range(a-1):
    if f[i]<f[i+1]:
        if now>=f[i]:
            buy=now//f[i]
            now=now-buy*f[i]
            kabu=buy
            buy=0
    if f[i]>f[i+1] :
        if kabu>=1:
            sell=kabu
            now=now+sell*f[i]
            kabu=0
            sell=0
    if f[i]==f[i+1]:
        continue
now = now+f[-1]*kabu
print(now)

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
a = l()
sum = 1000

for i in range(n-1):
    if a[i] > a[i+1]:
        xx = a[cnt:i+1]
        b = sum//min(xx)
        sum += (max(xx)-min(xx))*b
        cnt = i+1

xx = a[cnt:]
b = sum//min(xx)
sum += (max(xx)-min(xx))*b

print(sum)

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

Solution (Python):


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

dp=[[[0,1000],[0,1000]] for i in range(N+1)]


def wa(lis,a):
    return lis[0]*a+lis[1]

for i in range(N):
    
    dp[i+1][0]=dp[i][0] if wa(dp[i][0],A[i])>=wa(dp[i][1],A[i]) else [0,dp[i][1][0]*A[i]+dp[i][1][1]]
    
    dp[i+1][1]=dp[i][1] if wa(dp[i][1],A[i])>wa(dp[i][0],A[i]) else [dp[i][0][1]//A[i],dp[i][0][1]-dp[i][0][1]//A[i]*A[i]]
    
    
print(dp[-1][0][-1])

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

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

print(ans)

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

money = 1000
stock = 0
for i in range(N-1):
  for j in range(i+1, N):
    if A[i] > A[j]:
      money += stock * A[i]
      stock = 0
      break

    if A[i] < A[j]:
      stock += money // A[i]
      money -= A[i] * (money // A[i])
      break

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

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

if __name__=='__main__':
    main()

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

if __name__=='__main__':
    main()

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

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

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


dp = [1000] + [0] * (N-1)
for i in range(1, N):
    dp[i] = dp[i-1]

    for j in range(i):
        
        max_unit = dp[j] // A[j]
        
        money = dp[j] + (A[i]-A[j])*max_unit
        dp[i] = max(money, dp[i])

print(dp[-1])

Solution (Python):


N = int(input())
A = [int(_) for _ in input().split()]

dp = [1000]
K = [0]
C = [0]

for i in range(N):
    k, c = divmod(dp[-1], A[i])
    v = dp[-1]
    for j in range(i+1):
        u = K[j] * A[i] + C[j]
        v = max(u, v)
    K.append(k)
    C.append(c)
    dp.append(v)
print(dp[-1])

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

for i in range(1,n):
    tmp = dp[i-1]
    for j in range(i):
        k = dp[j]//a[j]
        m = dp[j]-a[j]*k
        tmp = max(tmp,m + a[i] * k)
    dp[i] = tmp

print(dp[n-1])

Solution (Python):
N=int(input())
A=[int(a) for a in input().split()]
dp=[-1 for _ in range(N)]
dp[0]=1000
for i in range(1,N):
    tmp=dp[i-1]
    for j in range(i):
        K=dp[j]//A[j]
        res=dp[j]-K*A[j]
        tmp=max(tmp,res+A[i]*K)
    dp[i]=tmp
print(dp[-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]:
		Stock = Stock + (Money//A[i])
		Money = Money % A[i]
	elif A[i] > A[i+1]:
		Money = Money + Stock * A[i]
		Stock = 0

ans = Money + Stock * A[i+1]
print(ans)

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

money = 1000
stock = 0
for day in range(N-1):
    today_price = A[day]
    tommorow_price = A[day+1]
    if today_price < tommorow_price:
        div,mod = divmod(money, today_price)
        stock += div
        money = mod
    elif today_price > tommorow_price:
        money += today_price * stock
        stock = 0
money += A[N-1] * stock
print(money)

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

cash = 1000

for buy, sell in zip(a, a[1:]):
    if buy >= sell:
        continue
    stock, cash = divmod(cash, buy)
    cash += stock * sell

print(cash)

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

buy, sell = [], []
for i in range(n):
    if a[i] < a[i+1] and len(buy) - len(sell) == 0:
        buy.append(i)
    if len(buy) - len(sell) == 1 and a[i] > a[i+1]:
        sell.append(i)

cash = 1000
for i, j in zip(buy, sell):
    stock, rest = divmod(cash, a[i])
    cash = stock * a[j] + rest

print(cash)

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

dp = [0]*(N+1)
dp[0] = 1000

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

print(dp[-1])

Solution (Python):
n,*A=map(int,open(0).read().split());m=1000
for x,y in zip(A,A[1:]):m+=m//x*(y-x)*(x<y)
print(m)

Solution (Python):
n,*A=map(int,open(0).read().split());m=1000
for x,y in zip(A,A[1:]):
  if x<y:m=m//x*y+m%x
print(m)

Solution (Python):
from sys import stdin
inp = lambda : stdin.readline().strip()

n= int(inp())
prices = [int(x) for x in inp().split()]

money= 1000
buy = -1
if prices[0] <=money: 
    buy = prices[0]
for i in range(1, len(prices)):
    if prices[i] > prices[i - 1]:
        if buy != -1:
            money = money%buy + (money//buy)*prices[i]
            buy = prices[i]
    else:
        if prices[i] < buy and prices[i] < money:
            buy = prices[i]
print(money)

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

money = 1000
num_stock = 0
for a, b in zip(A, A[1:]):
    if a < b:
        cnt, money = divmod(money, a)
        num_stock += cnt
    elif a > b:
        money += num_stock * a
        num_stock = 0
money += num_stock * A[-1]
print(money)

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

dp = [0] * (n + 1000)
dp[0] = 1000

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

Solution (Python):



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

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














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


from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
A = readInts()

ans = 1000
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):
n = int(input())
a = list(map(int, input().split()))

dp = [0]*(n+1)
dp[0] = 1000

for i in range(1, n):
    dp[i] = dp[i-1]
    for j in range(i):
        stock = dp[j]//a[j]
        cost = dp[j]+(a[i]-a[j])*stock
        dp[i] = max(dp[i], cost)
print(dp[n-1])

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

ret = 1000
for i in range(1, n):
  if A[i] - A[i - 1] > 0:
    ret = A[i] * (ret // A[i - 1]) + ret % A[i - 1]

print(ret)

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

ret = 1000
prev = A[0]
for i in range(1, n):
  if A[i] - prev > 0:
    ret = A[i] * (ret // prev) + ret % prev
  if A[i] != prev:
    prev = A[i]

print(ret)

Solution (Python):
N = int(input())
kabu = [int(i) for i in input().split()]
money = 1000
hoji = 0

for i in range(N-1):
    if kabu[i] < kabu[i+1] and not hoji:
        hoji = money//kabu[i]
        money = money - hoji*kabu[i]
    if kabu[i] > kabu[i+1] and hoji:
        money = money + hoji*kabu[i]
        hoji = 0
if hoji:
    money = money + hoji*kabu[i+1]
print(money)

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

m = 1000
s = 0
for i in range(N):
    if i == N-1 or A[i] > A[i+1]: 
        m += s * A[i]
        s = 0
    elif A[i] < A[i+1]:
        x = m // A[i]
        s += x
        m -= x * A[i]
print(m)

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

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

N = int(input())
A = list(map(int, input().split()))
dp = [0]*(N+1)
dp[0] = 1000

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

print(dp[N])

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):
        dp[i]=max(dp[i],(dp[j]//a[j])*a[i]+dp[j]%a[j])
print(dp[n-1])

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
nums = []
nums.append(a[0])
for i in range(1, n):
    if a[i] != a[i-1]:
        nums.append(a[i])
    else:
        continue
val = nums[0]
maxs = []
for j in range(1, len(nums)):
    if nums[j] > val:
        maxs.append(j)
    else:
        pass
    val = nums[j]
pos = 0
money = 1000
for idx in maxs:
    minVal = min(nums[pos:idx])
    stocks = money // minVal
    money = money - minVal * stocks + nums[idx] * stocks
    pos = idx
print(money)

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

stock=0
money=1000
d=-1
for i in range(len(A)-1):
	if A[i+1]-A[i]>0 and d==-1:
		'''kau'''
		stock=money//A[i]
		money=money%A[i]
		d=1
	elif A[i+1]-A[i]<0 and d==1:
		'''uru'''
		money+=A[i]*stock
		stock=0
		d=-1
	
if stock!=0:
	money += A[-1]*stock
	stock=0
print(money)

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

Solution (Python):
n=int(input())
list=[[0]*n]
list=input().split()
for i in range(n):
  list[i]=int(list[i])

yen=1000
stock=0
keikou=0
for i in range(1,n):
  if list[i]-list[i-1]<=0:
    keikou+=1
if keikou!=n-1:
  for t in range(1,n):
    if list[t]-list[t-1]>=0:
      stock+=int(yen/list[t-1])
      yen-=list[t-1]*int(yen/list[t-1])
      yen+=list[t]*stock
      stock=0
print(yen)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
f=-1
for i in a:
  if b[-1]<i:
    if f==1:b[-1]=i
    else:
      b.append(i)
      f=1
  if b[-1]>i:
    if f==-1:b[-1]=i
    else:
      b.append(i)
      f=-1
if f==-1:del b[-1]
if len(b)==0:exit(print(1000))
ans=1000
for i in range(0,len(b),2):
  bb=ans//b[i]
  ans-=bb*b[i]
  ans+=bb*b[i+1]
print(ans)

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

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

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


tmp = list(map(int, input().split()))
arr = [tmp[0]]
for i in range(1, n):
    if arr[-1] != tmp[i]:
        arr.append(tmp[i])


money, stock = 1000, 0
for i in range(1, len(arr)):
    if arr[i - 1] < arr[i]:
        
        buy, money = divmod(money, arr[i - 1])
        stock += buy
        
        money += stock * arr[i]
        stock = 0

print(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):
import sys
input = sys.stdin.readline




'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''


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

Solution (Python):

n = int(input())
arr = list(map(int, input().split()))
arr2 = []
cur = arr[0] if arr[0] < arr[1] else 10**10
f = 1
for i in range(1, n):
    if f == 1:
        
        if cur < arr[i]:
            arr2.append(cur)
            f *= -1
    else:
        
        if cur > arr[i]:
            arr2.append(cur)
            f *= -1
    cur = arr[i]
if f == -1:
    arr2.append(cur)
ans = 1000
stock = 0
for i, a in enumerate(arr2):
    if i % 2 == 0:
        
        stock = ans // a
        ans %= a
    else:
        
        ans += stock * a
        stock = 0
print(ans)

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

money=1000
pos = 1
kabu = 0

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
c = 1000  
s = 0  
up = False
for i in range(n-1):
    if A[i] < A[i+1]:
        if not up:
            s, c = divmod(c, A[i])
            up = True
            
    elif A[i] > A[i+1]:
        if up:
            c += s * A[i]
            s = 0
            up = False
            
    else:
        pass
else:
    c += s * A[-1]
print(c)

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

money=1000
best = money
pos = 1
kabu = 0


if A[0]<=A[1]:
    kabu = money//A[0]
    money -= kabu*A[0]
    pos=0
else:
    pos=1


for i in range(1,N):
    if pos==0:
        if A[i-1]>=A[i]:
            money+=kabu*A[i-1]
            kabu=0
            pos=1
    elif pos==1:
        if A[i-1]<A[i]:
            kabu = money//A[i-1]
            money -= kabu*A[i-1]
            pos=0
            
    best = max(best,money+kabu*A[i])
            
print(best)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
A.append(0)
L=[0]*N
L[0]=1000



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

Solution (Python):
days = int(input())
price = list(map(int,input().split()))
money = 1000
stock = 0

for i in range(days - 1):
  if price[i] < price[i + 1]:
    new = (money // price[i])
    stock += new
    money -= (new * price[i])
    
  else:
    money += stock * price[i]
    stock = 0

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

Solution (Python):
import sys
input = sys.stdin.readline
INF = 10**18
def li():
    return [int(x) for x in input().split()]

N = int(input())
A = [INF] + li()
M = 1000
K = 0

for i in range(1,N+1):
    if i == N:
        sell_cnt = K
        K = 0
        M += sell_cnt * A[i]
        break
    if A[i+1] > A[i] and A[i] <= A[i-1]:
        buy_cnt = M // A[i]
        K += buy_cnt
        M -= buy_cnt * A[i]
    elif A[i+1] < A[i] and A[i] >= A[i-1]:
        sell_cnt = K
        K = 0
        M += sell_cnt * A[i]

print(M)

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

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

is_rising = False
money = 1000
stock = 0

for i in range(N - 1):
    if i == 0:
        if A_li[0] < A_li[1]:
            
            stock = money // A_li[0]
            money -= A_li[0] * stock
            is_rising = True
    else:
        if is_rising:
            if A_li[i] > A_li[i + 1]:
                
                money += A_li[i] * stock
                stock = 0
                is_rising = False
        else:
            if A_li[i] < A_li[i + 1]:
                
                stock = money // A_li[i]
                money -= A_li[i] * stock
                is_rising = True
    if i + 1 == N - 1:
        
        money += A_li[i+1] * stock
        stock = 0

print(money)

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

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    m = 1000
    k = 0

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

    print(m)

main()

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()))

kabu = 0
yen = 1000

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

if kabu > 0:
  yen += A[-1] * kabu
  kabu = 0

print(yen)

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

money = 1000
s = 0
for i in range(N - 1):
    
    
    money += s * A[i]
    s = 0

    if A[i] < A[i + 1]:
        s = money // A[i]
        money %= A[i]

    

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