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())
l = list(map(int, input().split()))


dp = [-7 for _ in range(n+1)]

dp[0] = 1000


for i in range(1,n+1):
    dp[i] = dp[i-1]
    for j in range(i):
        buy = dp[j]//l[j]
        tmp = dp[j]%l[j] + buy*l[i-1]
        dp[i] = max(dp[i], tmp)

print(dp[n])

Solution (Python):
import collections
N=int(input())
A=list(map(int,input().split()))
i=0
A.insert(0,float("inf"))

buy=[0]*N
sell=[0]*N
for i in range(N-1):
    if (A[i]>=A[i+1])and(A[i+2]>=A[i+1]):
        buy[i]=1
    if (A[i]<=A[i+1])and(A[i+2]<=A[i+1]):
        sell[i]=1
kabu=0
money=1000


A=A[1:]

for i in range(N):

    if buy[i]==1:
        kabu=kabu+money//A[i]
        money=money-(money//A[i])*A[i]

    if sell[i]==1:
        money=money+kabu*A[i]
        kabu=0

    
    

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

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


if __name__ == "__main__":
    solve()

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


if __name__ == "__main__":
    solve()

Solution (Python):
_,*a=map(int,open(0).read().split());x=1000
for i,j in zip(a,a[1:]):x+=x//i*(j-i)*(j>i)
print(x)

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

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int,input().split()))
total = 1000
for i in range(n-1):
    if arr[i] < arr[i+1]:
        stocks = total // arr[i]
        total += (arr[i+1] - arr[i]) * stocks
print(total)

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

syozi = 1000
kabu = 0

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

syozi += A[-1] * kabu

print(syozi)

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

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

money += A[-1] * ticket

print(money)

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

yen = 1000
kabu_yen = 0
kabu_n = 0
last_buy = -1
for i in range(1,n+1):
    if A[i-1] < A[i]: 
        tanka = A[i-1]
        m = yen // tanka
        cost = tanka * m
        yen -= cost
        kabu_yen += cost
        kabu_n += m

    elif A[i-1] > A[i]: 
        yen += A[i-1] * kabu_n
        kabu_yen = 0
        kabu_n = 0

print(yen)

Solution (Python):

from statistics import mean, median,variance,stdev
import sys
input = sys.stdin.readline  
N = int(input())
A = list(map(int, input().split()))
monney =[-1]*N
kabu_med =median(A)
kabu_num =[-1]*N


if A[0] < A[1]:
    kabu_num[0]   = 0     +1000 //A[0]
    monney[0]     = 1000  -kabu_num[0] *A[0]
elif A[0] >= A[1]:
    kabu_num[0]   = 0
    monney[0]     = 1000

for i in range(1,N-1):
    if A[i-1] >= A[i] < A[i+1]:
        kabu_num_today =monney[i-1] //A[i]
        kabu_num[i]   = kabu_num[i-1]   +kabu_num_today
        monney[i]     = monney[i-1]     -kabu_num_today *A[i]
    elif A[i-1] <= A[i] > A[i+1]:
        kabu_num_today =kabu_num[i-1]
        kabu_num[i]   = 0
        monney[i]     = monney[i-1]     +kabu_num_today *A[i]
    elif A[i-1] <= A[i] <= A[i+1]:
        kabu_num[i]   = kabu_num[i-1]
        monney[i]     = monney[i-1]
    elif A[i-1] >= A[i] >= A[i+1]:
        kabu_num[i]   = kabu_num[i-1]
        monney[i]     = monney[i-1]


monney[N-1] =monney[N-2]     +kabu_num[N-2] *A[N-1]

print(monney[-1])

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

print(money)

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

wallet = 1000

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

print(wallet)

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

Solution (Python):

import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

shojikin = 1000
stock = 0
for i in range(N):
    if stock:
        shojikin += stock * A[i]
        stock = 0
    if i+1 < N:
        if A[i] < A[i+1]:
            q, mod = divmod(shojikin, A[i])
            stock = q
            shojikin = mod

print(shojikin)

Solution (Python):
N, *A = map(int, open(0).read().split())

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

print(cur)

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


if __name__ == "__main__":
    solve()

Solution (Python):



N = int(input())
A = list(map(int, input().split()))
mn = 1000
for i in range(N-1):
    if A[i+1]>A[i]:
        buy = mn//A[i]
        mn += buy*(A[i+1]-A[i])
print(mn)

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

money=1000
kabu=0
for i in range(N-1):
  if alist[i]<alist[i+1]:
    
    k=money//alist[i]
    kabu+=k
    money-=k*alist[i]
  elif alist[i]>alist[i+1]:
    
    money+=alist[i]*kabu
    kabu=0

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

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

high = 1000
kabu = 1000 // A[0]
amar = 1000 - kabu * A[0]

for i in range(1, N):
    res = amar + kabu * A[i]
    if res > high:
        high = res
    if A[i] < max(A[i:]):
        kabu = high // A[i]
        amar = high - kabu * A[i]
    
print(high)

Solution (Python):

N = int(input())
X = 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):
        n = dp[j] // X[j]
        dp[i] = max(dp[i], dp[j] + (X[i] - X[j]) * n)

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

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

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

M = 1000
K = 0


flgs = [0] * N
for i in range(N-1):
    if i == 0:
        if A[i] < A[i+1]:
            flgs[i] = 1
        continue
    if A[i] < A[i+1]:
        flgs[i] = 1
    else:
        flgs[i] = 2
flgs[N-1] = 2

for i in range(N):
    flg = flgs[i]
    if flg == 1:
        K += M // A[i]
        M = M % A[i]
    elif flg == 2:
        M += A[i] * K
        K = 0

print(M)

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

def main():
    money = 1000
    n = 0
    
    for i in range(1, len(a)):
        if (a[i-1] < a[i]):   
            n = money // a[i-1]
            money += (a[i] - a[i-1]) * n

    print(money)

if __name__ == '__main__':
    main()

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

Solution (Python):
ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
A = list(ma())
tot = 1000
kab = 0
for i in range(n-1):
    tot += A[i]*kab
    kab = 0
    if A[i] > A[i+1]:
        pass
    if A[i] <= A[i+1]:
         kab,tot = divmod(tot,A[i])
tot+=A[-1]*kab
print(tot)

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

    dp = [-float('inf')] * N
    dp[0] = 1000

    for i in range(1,N):
        dp[i] = dp[i-1]
        for j in range(i):
            n_stock = dp[j] // A[j]
            n_money = n_stock * A[i] + dp[j] % A[j]
            dp[i] = max(dp[i], n_money)
    
    print(dp[-1])
        
if __name__ == '__main__':
    solve()

Solution (Python):

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

cur = 1000
for i in range(N - 1):
    if X[i] < X[i + 1]:
        stocks = cur // X[i]
    else:
        stocks = 0

    cur += (X[i + 1] - X[i]) * stocks


print(cur)

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


if __name__ == "__main__":
    solve()

Solution (Python):
def unique(list_to_unique) -> list:
    if len(list_to_unique) == 0:
        return []
    else:
        result = [list_to_unique[0]]
        for it in range(1, len(list_to_unique)):
            if list_to_unique[it] != list_to_unique[it - 1]:
                result.append(list_to_unique[it])
        return result


n = int(input())
a = list(map(int, input().split()))
a = unique(a)
while len(a) > 1 and a[0] >= a[1]:
    a.pop(0)
while len(a) > 1 and a[len(a) - 1] <= a[len(a) - 2]:
    a.pop(len(a) - 1)
b = []
na = []
for i in range(len(a)):
    if i == 0 or i == len(a) - 1:
        b.append(a[i])
    elif a[i] > a[i - 1] and a[i] > a[i + 1] or a[i] < a[i + 1] and a[i] < a[i - 1]:
        b.append(a[i])
a = b
if len(a) > 2:
    money = 1000
    stocks = 0
    for i in range(len(a)):
        if i % 2 == 1:
            money += stocks * a[i]
            stocks = 0
        else:
            stocks += money // a[i]
            money %= a[i]
    print(money)
elif len(a) == 2 and a[0] < a[1]:
    print(1000 // a[0] * a[1] + 1000 % a[0])
else:
    print(1000)

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

am = 1000
st = 0
for a1, a2 in zip(an, an[1:]):
    am += a1 * st
    st = 0
    if a1 < a2:
        st, am = divmod(am, a1)

am += an[-1] * st
print(am)

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

k_y = [1000]
yen = 1000
resyen = 1000
kabu_max = 0
for i in range(n):
	
	newyen = max( yen, kabu_max * a[i] + resyen)
	
	
	kabu_max_new = max( kabu_max + resyen // a[i], yen // a[i] )
	if kabu_max_new == yen // a[i]:
		if kabu_max_new == kabu_max + resyen // a[i]:
			resyen = max( yen % a[i], resyen % a[i])
		else:
			resyen = yen % a[i]
	
	yen = newyen
	kabu_max = kabu_max_new
	
print( yen )

Solution (Python):
N = int(input())
s_list = list(input().split())
money = 1000
stock = 0

for i in range(N):
  

  
  if (i == N-1):
    money += stock * int(s_list[i])
    stock = 0
    break

  
  if (int(s_list[i+1]) > int(s_list[i])):
    stock = stock + int(money / int(s_list[i]))
    money = money - (int(s_list[i]) * int(money / int(s_list[i])))
    continue

  
  if (int(s_list[i+1]) <= int(s_list[i])):
    money = money + (int(s_list[i]) * stock)
    stock = 0
    continue

print(money)

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

m = 1000
s = 0

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

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

stock=0
money=1000

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

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

A.append(0)
money = 1000

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

print(money)

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

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

wallet = 1000
stock = 0

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

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

m = 1000
s = 0

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = 1000
for i in range(len(A) - 1):
    stocks = 0
    if A[i] < A[i + 1]:
        stocks = ans // A[i]
        ans += (A[i + 1] - A[i]) * stocks
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]:
    if money<a[i]:
      continue
    kabu=money//a[i]
    money=money-a[i]*kabu
  elif a[i]==a[i+1]:
    pass
  else:
    money=money+a[i]*kabu
    kabu=0
money=money+a[-1]*kabu

print(money)

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

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

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

money = 1000

for i in range(n-1):
    s = 0
    if a[i] < a[i + 1]:
        s = money // a[i]
    money += (a[i + 1] - a[i]) * s
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+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,*l=map(int,open(0).read().split())
a=1000
for s,t in zip(l,l[1:]): a+=a//s*max(t-s,0)
print(a)

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

A.append(0)

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

print(ans)

Solution (Python):
from collections import defaultdict,deque
import math
def gcd(a,b):
    return b if not a%b else gcd(b,a%b)
def lcm(a,b):
    return (a*b)//gcd(a,b)

def main():
    n = int(input())
    a=[int(i) for i in input().split()]
    money = 1000
    for i in range(n-1):
        stocks = 0
        if(a[i] < a[i+1]):
            stocks = money//a[i]
        money += stocks*(a[i+1]-a[i])
    print(money)

if __name__ == '__main__':
    main()

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

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 -= kabu * A[i]
        money += kabu * A[i+1]
        

print(money)

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

now = 1000

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

print(now)

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

dp = [1000]*(N+1)

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

Solution (Python):

import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = LI()
buy = [0] * n

katamuki = 0
for i in range(n-1):
    if katamuki == 0:
        if mylist[i+1] > mylist[i]:
            buy[i] = "buy"
            katamuki = 1
        elif mylist[i+1] < mylist[i]:
            katamuki = -1
    elif katamuki == -1 and mylist[i+1] > mylist[i]:
        buy[i] = "buy"
        katamuki = 1
    elif katamuki == 1 and mylist[i+1] < mylist[i]:
        buy[i] = "sell"
    elif katamuki == 1 and mylist[i+1] > mylist[i]:
        buy[i] = "buysell"

        
result = 1000
stock = 0
price = 0    
for i in range(n):
    if buy[i] == "buy":
        stock = result // mylist[i]
        result -= mylist[i] * stock
    elif buy[i] == "sell":
        result += mylist[i] * stock
        stock = 0
    elif buy[i] == "buysell":
        result += mylist[i] * stock
        stock = result // mylist[i]
        result -= mylist[i] * stock
    elif i == n-1:
        result += mylist[i] * stock
print(result)

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

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

dp = [-1] * 81
dp[0] = 1000

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

print(dp[N - 1])

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

print(m)

Solution (Python):
import numpy as np

n = int(input())
A = np.array(input().split(), dtype=np.int64)
money = 1000
kabu = 0

for i in range(n):
    if kabu > 0:
        if i != 0:
            if A[i] > A[i - 1]:
                money += A[i] * kabu
                kabu = 0
    if i != n - 1:
        if A[i] < A[i + 1]:
            kabu += money // A[i]
            money -= A[i] * kabu
print(money)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
money = [[1000, 0]]
ans = 1000
B = [1 for _ in range(N)] 
for k in range(N-1):
  if A[k] < A[k+1]:
    B[k] = -1
  elif A[k] == A[k+1]:
    B[k] = 0

for k in range(N):
  if B[k] == -1:
    new = []
    for j in range(len(money)):
      if A[k] <= money[j][0]:
        new.append([money[j][0]%A[k], money[j][1] + money[j][0]//A[k]])
    money += new
  
  if B[k] == 1:
    ans = 0
    for j in range(len(money)):
      ans = max(money[j][0] + money[j][1]*A[k], ans)
    money[0] = [ans, 0]

print(ans)

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

M = 1000
X = 0

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

print(int(M))

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    last = a[0]
    money = 1000
    kabu = 0
    for i, kabuka in enumerate(a):
        if i == len(a)-1:
            break
        if a[i+1] > a[i]:
            kabu = money//a[i]
            money += (a[i+1] - a[i]) * kabu
    print(money)
if __name__ == '__main__':
    main()

Solution (Python):
x=1000
for a,b in zip(a:=[*map(int,[*open(0)][1].split())],a[1:]):x+=x//a*(b-a)*(a<b)
print(x)

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

now = 1000
for a_pre, a in zip(A, A[1:]):
    if a > a_pre:
        n = now // a_pre
        now = (now%a_pre) + a*n

print(now)

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

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

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

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

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

print(ans)

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

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

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

Solution (Python):



def solve(*args: str) -> str:
    n = int(args[0])
    A = list(map(int, args[1].split()))
    budget = 1000
    stock = 0

    for i in range(n-1):
        if A[i] < A[i+1] and A[i] <= budget:
            stock, budget = divmod(budget, A[i])
        elif A[i+1] < A[i]:
            budget += A[i]*stock
            stock = 0

    return str(A[-1]*stock+budget)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

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

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

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

Solution (Python):
n = int(input())
al = [int(i) for i in input().split()]

mn = 201
money = 1000

for a in al:
    if a < mn:
        mn = a
    if a > mn:
        money = money-(money//mn*mn) + (money//mn)*a
        mn = a

print(money)

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

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

print(yen)

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

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

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

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

money = 1000

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

print(money)

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

money=1000
stock=0

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

    else :
        continue

print(money)

Solution (Python):
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;cnt = 0 ;pro = 1

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

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

    money = 1000

    low = A[0]
    p = A[0]
    for x in A:
        if p > x:
            money += (p - low) * (money // low)
            low = x
        p = x

    money += (p - low) * (money // low)

    print(money)


if __name__ == '__main__':
    main()

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

m = 1000
s = 0

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

Solution (Python):
n,*l=map(int,open(0).read().split())
a,c=1000,0
for i in range(n-1):
  s,t=l[i:i+2]
  if s>t: a+=c*s; c=0
  if s<t: c+=a//s; a-=a//s*s
print(a+c*t)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
m = 1000
s = 0
flag = "e"
idx = 0
for i in range(N-1):
  if A[i]<A[i+1] and (flag == "d" or flag == "e"):
    s += m//A[i]
    m = m%A[i]
    flag = "u"
  elif A[i]>A[i+1] and (flag == "u" or flag == "e"):
    m += s*A[i]
    s = 0
    idx = i
    flag = "d"
  elif A[i]==A[i+1]:
    flag = "e"
    
m += s*A[N-1]

print(int(m))

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  

N = I()
A = LI()




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):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')

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

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

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

    if A[i] < A[i+1]:
        buy = money // A[i]
        money -= buy * A[i]

if buy != 0:
    money += buy*A[-1]

print(money)

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

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

cnt = 0
money = 1000
b = 0
for i in range(n-1):
    if cnt == 0 and A[i] < A[i+1]:
        cnt += money//A[i]
        money %= A[i]
        b = A[i]
    else:
        money += cnt * A[i]
        cnt = 0
        if A[i] < A[i+1]:
            cnt += money//A[i]
            money %= A[i]
            b = A[i]
if cnt > 0:
    money += cnt * max(b, A[-1])
print(money)

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

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

money = 1000
kabu = 0

for i in range(len(A)-1):
    if kabu != 0:
        if A[i] >= A[i + 1]:
            money += kabu * A[i]
            kabu = 0

    else:
        if A[i] < A[i + 1]:
            kabu = money // A[i]
            money -= kabu * A[i]

if kabu != 0:
    money += kabu * A[len(A) - 1]
    
print(money)

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

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

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

    money = 1000

    low = A[0]
    p = A[0]
    for x in A:
        if p > x:
            money += (p - low) * (money // low)
            low = x
        p = x

    money += max(0, p - low) * (money // low)

    print(money)


if __name__ == '__main__':
    main()