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

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

dp = [[0, 0] for _ in range(n+1)]

dp[0] = [(1000, 0), (1000, 0)]

for i in range(n):
    kabuka = a[i]
    money = max(dp[i][0][0], dp[i][1][0] + kabuka * dp[i][1][1])
    num_kabu = money // kabuka
    num_amari = money % kabuka
    dp[i+1] = [(money, 0), (num_amari, num_kabu)]


print(dp[-1][0][0])

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

print(ans)

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

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

ans = []

is_up = False
is_down = False
for i in range(n):
    if i == 0:
        ans.append(a[i])
        continue
    if is_up:
        if a[i - 1] <= a[i]:
            continue
        else:
            ans.append(a[i - 1])
            is_up = False
            is_down = True
    elif is_down:
        if a[i - 1] >= a[i]:
            continue
        else:
            ans.append(a[i - 1])
            is_up = True
            is_down = False
    else:
        if a[i - 1] < a[i]:
            is_up = True
        elif a[i - 1] > a[i]:
            is_down = True
ans.append(a[-1])

res = 1000
money = 1000
stock = 0
ans.append(-1)

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

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

Solution (Python):

n, *a = map(int, open(0).read().split())
c = 1000
for i in range(1, n):
    if a[i] > a[i - 1]:
        c = c // a[i - 1] * a[i] + c % a[i - 1]
print(c)

Solution (Python):
import sys, math
import io, os

from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write('\n'.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')

from fractions import Fraction

INF = float('inf')
mod = int(1e9)+7



n=int(data())
a=mdata()
k=1000
s=0
for i in range(n):
    if i>0 and a[i]>a[i-1]:
        k+=s*a[i]
        s=0
    if i<n-1 and a[i]<a[i+1]:
        s=k//a[i]
        k=k%a[i]
k+=s*a[-1]
out(k)

Solution (Python):
n=int(input())
gold=1000
kabu=0
lst=list(map(int,input().split()))
for i in range(n-1):
    if lst[i]<lst[i+1]:
        tmp,gold=divmod(gold,lst[i])
        kabu+=tmp
    if lst[i]>lst[i+1]:
        gold+=kabu*lst[i]
        kabu=0
gold+=kabu*lst[-1]
print(gold)

Solution (Python):


from sys import stdin, stdout
 
def input():
    return stdin.readline().strip()

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

yen = 1000
stocks = 0

for i in range(len(A)):
    if i < len(A)-1 and A[i+1] > A[i]:
        
        new_stocks = yen // A[i]
        stocks += new_stocks
        yen -= new_stocks*A[i]
    if i == len(A)-1 or A[i+1] < A[i]:
        
        yen += stocks*A[i]
        stocks = 0

print(yen)

Solution (Python):
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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


def main():
	N = int(input())
	A = getlist()
	B = []
	B.append(A[0])
	for i in range(1, N - 1):
		if A[i - 1] >= A[i] and A[i] >= A[i + 1]:
			pass
		if A[i - 1] <= A[i] and A[i] <= A[i + 1]:
			pass
		else:
			B.append(A[i])

	B.append(A[-1])
	M = len(B)
	
	money = 1000
	kabu = 0
	for i in range(M - 1):
		if B[i] < B[i + 1]:
			kabu += int(money // B[i])
			money %= B[i]
		else:
			money += kabu * B[i]
			kabu = 0

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


if __name__ == '__main__':
	main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n = readint()
a = readints()


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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque, defaultdict


from collections import Counter

from itertools import accumulate,combinations,permutations,product

from heapq import heapify,heappop,heappush

from functools import reduce,lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): 
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    

    N = int(input())
    
    A = tuple(map(int, input().split())) 
    
    
    cur=1000
    curk=0
    for i,a in enumerate(A):
        if i==N-1:
            cur+=a*curk
            curk=0
            continue

        if a<=A[i+1]:
            x=cur//a
            curk+=x
            cur-=x*a
        else:
            cur+=a*curk
            curk=0
    print(cur)





if __name__ == "__main__":
    main()

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

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

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

money = 1000
stock = 0
for i in range(N):
    if i == 0:
        if As[0] < As[1]:
            stock = money // As[0]
            money %= As[0]
    elif i == N - 1:
        money += As[i] * stock
        stock = 0
    else:
        if As[i-1] >= As[i] and As[i+1] >= As[i]:
            stock += money // As[i]
            money %= As[i]
        elif  As[i-1] <= As[i] and As[i+1] <= As[i]:
            money += As[i] * stock
            stock = 0

print(money)

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

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

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))
now=1000
for i in range(0,len(b),2):
  bb=now//b[i]
  now-=bb*b[i]
  now+=bb*b[i+1]
print(now)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
A = [k for k, g in groupby(A)]
A = [300]+A+[0]
money = 1000
kabu = 0
for i in range(1, len(A)-1):
    if A[i-1] > A[i] < A[i+1]:  
        n = money//A[i]
        money -= A[i]*n
        kabu += n
    if A[i-1] < A[i] > A[i+1]:  
        money += kabu*A[i]
        kabu = 0
print(money)

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

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

print(money)

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

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

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

m=1000

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

print(m)

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

s = 1000
j = 0

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

s += j * a[n-1]
j = 0

print(s)

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

    if A[i+1]<A[i]:
        m += s*A[i]
        s = 0

print(m)

Solution (Python):
N = int(input())
A_s = list(map(int, input().split()))
is_up = []
for i, A in enumerate(A_s):
    if i == len(A_s)-1:
        break
    if A_s[i+1] >= A_s[i]:
        is_up.append(True)
    else:
        is_up.append(False)
wallet = 1000
stocks = 0
for i, A in enumerate(A_s):
    if i == len(A_s)-1:
        wallet += stocks * A
        stocks = 0
        break
    if is_up[i]:
        stocks += wallet // A
        wallet = wallet % A
    else:
        wallet += stocks * A
        stocks = 0


print(wallet)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
m = 1000
x = []
tnp = [a[0]]
for i in range(1,n):
    if (a[i-1]>a[i]):
        x.append(tnp)
        tnp = [a[i]]
    else:
        tnp.append(a[i])
x.append(tnp)

ans = 1000
for i in range(len(x)):
    if (len(x[i])>1):
        ans = ans%min(x[i]) + ans//min(x[i])*max(x[i])
        
print(ans)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
money = 1000
for i in range(N-1):
    if A[i+1] < A[i] :
        continue
    else:
        money = money//A[i] *A[i+1] + money%A[i]
print(money)

Solution (Python):
import sys

N = int(input())

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

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

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

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

print(m)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
T = [0]*N
kane = 1000
kabu = 0
for i in range(N-1):
    now = A[i]
    next = A[i+1]
    if now<next:
        ko = kane//now
        kane += -1*ko*now
        kabu += ko
    elif now>next:
        kane += kabu*now
        kabu = 0

kane += kabu*next
print(kane)

Solution (Python):
import bisect
import copy
import heapq
import sys
import itertools
import math
from functools import lru_cache
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    A = read_list()
    res = 1000
    l = -1
    r = -1
    for a in A:
        if l < 0:
            l = a
            continue

        if r < 0:
            if l >= a:
                l = a
            else:
                r = a
        else:
            if r <= a:
                r = a
            else:
                res += (res // l) * (r - l)
                l = a
                r = -1

    if r >= 0:
        res += (res // l) * (r - l)
    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict

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

dp = {0:1000}

for a in A:
    new_dp = defaultdict(lambda: -float('inf'))
    for stock, money in dp.items():
        new_dp[0] = max(new_dp[0], money + stock * a)
        new_dp[stock] = max(new_dp[stock], money)
        can_buy = money // a
        new_dp[stock + can_buy] = max(new_dp[stock+can_buy], money - can_buy * a)
    dp = new_dp
print(max(dp.values()))

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

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

now = 1000
prevp = A[0]
stocks = 0

ans = 1000
for i in range(1,N):
  prevp = A[i-1]
  nowp = A[i]
  if stocks == 0 and prevp < nowp:
    stocks = now // prevp
    now = now % prevp
  elif stocks > 0 and prevp > nowp:
    now += prevp * stocks
    stocks = 0
  ans = max(ans, now)
  
  
ans = max(ans, now + A[-1] * stocks)
print(ans)

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

money = 1000
for i in range(n - 1):
    if a[i+1] > a[i]:
        money = money % a[i] + money // a[i] * a[i+1]

print(money)

Solution (Python):
import sys
import math


def input():
    return sys.stdin.readline().rstrip()


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

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

    print(cash)







if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
import bisect

def main():
    n = int(input())
    A = list(map(int, input().split()))
    ans = 1000
    for i in range(1, n):
        if A[i-1] <= 1000 and A[i] > A[i-1]:
            r = ans % A[i-1]
            ans = ans // A[i-1] * A[i] + r
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
Ali = list(map(int,input().split()))
M = 1000

for i in range(N-1):
  if Ali[i] < Ali[i+1]:
    M += M//Ali[i]*(Ali[i+1]-Ali[i])
    
print(M)

Solution (Python):


import sys
read = sys.stdin.read
readline = sys.stdin.readline

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

m = 1000
s = 0

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

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
m = 1000

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

print(m)

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

money = (1000, 0)
stock = (0, 0)

for A in A_list:
	mm = money
	ms = (money[0] % A, money[0] // A)
	sm = (stock[0] + stock[1] * A, 0)
	ss = (stock[0] % A, stock[1] + stock[0] // A)
	
	if mm[0] > sm[0] or (mm[0] == sm[0] and mm[1] > sm[1]):
		money = mm
	else:
		money = sm
	
	if ms[1] > ss[1] or (ms[1] == ss[1] and ms[0] > ss[0]):
		stock = ms
	else:
		stock = ss

print(money[0])

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

tmp = 0
a_filter = []
idx = 0
while idx < len(a) - 1:
    if a[idx] < a[idx+1]:
        a_filter += [a[idx],a[idx+1]]
    idx+=1

ret = 1000
tmp = 0
for i,x in enumerate(a_filter):
    if i % 2:
        ret += tmp*x
    else:
        tmp = ret // x
        ret -= tmp * x
print(ret)

Solution (Python):


import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

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

subSeqStart = []
subSeqEnd = []

subSeqStart.append(a[0])

for i in range(N):
    if i == N-1:
        subSeqEnd.append(a[i])
        break
    if a[i] > a[i+1]:
        subSeqEnd.append(a[i])
        subSeqStart.append(a[i+1])

Money = 1000
Stock = 0
for i in range(len(subSeqStart)):
    Stock += Money // subSeqStart[i]
    Money -= Stock * subSeqStart[i]
    Money += Stock * subSeqEnd[i]
    Stock = 0
print(Money)

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

N = int(readline())
A = [None] + list(map(int, readline().split()))

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

print(dp[N])

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

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

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

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):
N = int(input())
A = list(map(int,input().split()))
M = 1000
S = 0
for i in range(N-1):
  if A[i]<A[i+1]:
    S += M//A[i]
    M = M%A[i]
  else:
    M += S*A[i]
    S = 0
M += S*A[N-1]
print(M)

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

Solution (Python):
n = int(input())
alst = list(map(int, input().split()))
lst = [[0, [0, 0]] for _ in range(n)]

lst[0][0] = 1000
lst[0][1][0] = 1000 // alst[0]
lst[0][1][1] = 1000 % alst[0]
for i, num in enumerate(alst[1:], start = 1):
    m1 = lst[i - 1][1][1] + lst[i - 1][1][0] * num
    lst[i][0] = max(lst[i - 1][0], m1)
    lst[i][1][0] = lst[i][0] // num
    lst[i][1][1] = lst[i][0] % num
    
print(lst[-1][0])

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


if __name__ == '__main__':
    resolve()

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

ans = 0
yen = 1000;kabu = 0
for i in range(n-1):
    if a[i] < a[i+1]:
        kabu += yen // a[i]
        yen %= a[i]
    else:
        yen += a[i]*kabu
        kabu = 0
yen += a[-1]*kabu
print(yen)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
g = 1000
s = 0
for i in range(1, N):
    if A[i] > A[i-1]:
        t = g // A[i-1]
        g -= t * A[i-1]
        s += t
    else:
        g += s * A[i-1]
        s = 0
print(g + s * A[-1])

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

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

Solution (Python):


import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union































def main():
    Num = Union[int, float]
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input():  return sys.stdin.readline().rstrip()
    def ii():     return int(input())
    def isp():    return input().split()
    def mi():     return map(int, input().split())
    def mi_0():   return map(lambda x: int(x)-1, input().split())
    def lmi():    return list(map(int, input().split()))
    def lmi_0():  return list(map(lambda x: int(x)-1, input().split()))
    def li():     return list(input())
    def debug(x): print(x, file=sys.stderr)
    
    
    def simulate(n, L):
        money = 1000
        stock = 0
        for i in range(n-1):
            if L[i+1] == L[i]:
                continue
            elif L[i+1] > L[i]:
                num = money // L[i]
                stock += num
                money -= num * L[i]
            else:
                money += stock * L[i]
                stock = 0
        return money + stock * L[-1]

    
    
    n = ii()
    L = lmi()
    ans = simulate(n, L)
    print(ans)

        


if __name__ == "__main__":
    main()

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

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

money = 1000
for i in range(1, N):
    if As[i] > As[i-1]:
        n = money // As[i-1]
        money = money - (As[i-1] * n) + (As[i] * n)
print(money)

Solution (Python):

import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys


buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    c = 1000
    for i in range(len(A)-1):
        if A[i] < A[i+1]:
            c = (c // A[i]) * A[i+1] + (c % A[i])

    return c


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
range = xrange
input = raw_input

n = int(input())
A = [int(x) for x in 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
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    ans = 1000
    kabu = 0
    for i in range(N-1):
        if A[i] < A[i+1]:
            kabu += ans//A[i]
            ans = ans % A[i]
        else:
            ans += kabu * A[i]
            kabu = 0
    
    print(ans+kabu*A[N-1])

if __name__ == "__main__":
    main()

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





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






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
A = IL()

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

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

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

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

A = [10000] + A + [0]
now = A[0]
for i in range(N+1):
    if A[i+1] >= A[i]:
        mo += 0
    else:
        plus = (mo // now) * (A[i]-now)
        mo += plus
        now = A[i+1]
        
print(mo)