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
import numpy as np
import math  
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate 
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache 

def main():
    INF = 10**9
    n = int(input())
    A = list(map(int,input().split()))
    B = [0] * n
    for i in range(len(A) - 1):
        B[i + 1] = A[i + 1] - A[i]
    
    B.append(-INF)
    C = ['D'] * (n + 1)
    for i in range(1, len(B)):
        if B[i] > 0:
            C[i] = 'U'
        if B[i] == 0:
            C[i] = C[i - 1]
    

    money = 1000
    stock = 0

    for i in range(n):
        if C[i] == 'D' and C[i + 1] == 'U':
            stock = money // A[i]
            money = money - (stock * A[i])
        if C[i] == 'U' and C[i + 1] == 'D':
            
            money += stock * A[i]
            stock = 0
    print(money)
    return 0

if __name__ == "__main__":
    main()

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

A_max = max(A)
A_min = min(A)

c = 1000
s = 0
p = 0

for i in range(N - 1):
    
    if A[i] < A_max and A[i] < A[i + 1]:
        t = c // A[i]
        p = A[i]
        c -= A[i] * t
        s += t
        continue

    
    if A[i] > A_min and p < A[i] and A[i] > A[i + 1]:
        c += A[i] * s
        s = 0
        p = 0
        continue


c += A[N - 1] * s
s = 0

print(c)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
a = []
for i in range(1, n):
    if l[i] != l[i - 1]: a.append(l[i - 1])
a.append(l[n - 1])
n = len(a)



hi = []
for i in range(1, n - 1):
    if a[i - 1] < a[i] and a[i + 1] < a[i]: hi.append(i)
mn = a[0]
p1 = 0
money = 1000
stocks = 0



for i in hi:
    while p1 < i:
        mn = min(mn, a[p1])
        p1 -= -1
    stocks = money // mn
    money = money % mn
    money += stocks * a[i]
    mn = a[i]

for i in range(p1 + 1, n):
    mn = min(mn, a[i])
stocks = money // mn
money = money % mn
money += stocks * a[n - 1]

print(money)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
tmp=a[0]
up=0
check=0
stock=0
n=1000
for i in range(N-1):
    if i==0:
        if a[i]<=a[i+1]:
            check=1
            stock=n//a[i]
            n-=stock*a[0]
        else:
            check=2
    else:
        if check==1:
            if a[i]<=a[i+1]:
                pass
            else:
                check=2
                n+=stock*a[i]
                stock=0
        elif check==2:
            if a[i]<=a[i+1]:
                check=1
                stock=n//a[i]
                n-=stock*a[i]
    
if check==1:
    n+=stock*a[-1]
print(n)

Solution (Python):


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

now_kabu = 0
shoji = 1000
for i in range(N-1):
    if A[i+1] > A[i]:
        now_kabu += shoji // A[i]
        shoji -= shoji // A[i] * A[i]
    if now_kabu != 0:
        shoji += A[i+1] * now_kabu
        now_kabu = 0

print(shoji)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))+[0]
baibai = []
kane = 1000
kabu = 0
for i in range(N):
    sa = A[i+1] -A[i]
    if sa == 0:
        baibai.append(0)
    elif sa != abs(sa):
        baibai.append(-1)
    else:
        baibai.append(1)
if 1 in baibai:
    uri = N - (baibai[::-1].index(1))
else:
    uri = -1

for j in range(N):
    if j == uri:
        kane += A[j] * kabu
        print(kane)
        exit()
    elif baibai[j] > 0:
        kabu += (kane//A[j])
        kane -= A[j] * (kane//A[j])
    elif baibai[j] < 0:
        kane += A[j] * kabu
        kabu = 0
        
print(kane)

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial,sin
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
count=0
point=[]
for i in range(n-1):
    if count%2==0 and lis[i+1]-lis[i]>0:
        point.append(lis[i])
        count+=1
    if count%2==1 and lis[i+1]-lis[i]<0:
        point.append(lis[i])
        count+=1
'''if count%2==1 and lis[n-1]-lis[n-2]>=0:
    point.append(lis[n-1])
elif count%2==0 and lis[n-1]-lis[n-2]<=0:
    point.append(lis[n-1])'''
point.append(lis[-1])   


money=1000
for i in range(len(point)//2):
    x=money//point[2*i]
    y=money%point[2*i]
    money=y+x*point[2*i+1]
print(money)

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

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

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




m = 1000
k = 0
flag = False
for i in range(N):

    m += k*A[i]
    k = 0
    low = False
    high = False
    for j in range(i+1, N):
        if A[i] < A[j]:
            high = True
            break
        elif A[i] >= A[j]:
            low = True
    if not low and high:
        k = m // A[i]
        m -= k*A[i]

print(m)

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

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

money = 1000
stock = 0

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

print(money)

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

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

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

result = 1000
stock = 0

day = 0

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

for i in range(len(dif)):
    if dif[i] > 0:
        stock += result // min(a[day:i+1])
        result -= (result // min(a[day:i+1]))*min(a[day:i+1])
        
        result += stock*a[i+1]
        stock = 0
        
        day = i+1
print(result)

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

for n in range(N-1):
    if A[n] < A[n+1]:
        k = int(m/A[n])
        m -= k*A[n]
        m += k*A[n+1]
        
print(m)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
A = []
f = 0
bf = 0
for i in range(n - 1):
    if a[i] < a[i + 1]:
        f = 1
    elif a[i] > a[i + 1]:
        f = -1

    if bf != f:
        A.append(a[i])

    bf = f
A.append(a[n-1])
m = 1000
c = 0
for i in range(len(A)-1):
    if A[i] < A[i + 1]:
        c = m // A[i]
        m %= A[i]
        if i == len(A) - 2:
            m += c * A[i+1]
            c = 0
    else:
        m += c * A[i]
        c = 0


print(m)

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

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

pos = 0 
kane = 1000 
kabu = 0
hi = 0      

while hi < n:
    if pos == 0:
        if a[hi] < a[hi+1]:
            kabu = kane // a[hi]
            kane = kane % a[hi]
            pos = 1
            hi += 1
        else:
            hi += 1
    else:
        if a[hi] > a[hi+1]:
            kane += a[hi]*kabu
            kabu = 0
            pos = 0
            hi += 1
        else:
            hi += 1

print(kane)

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

dpMoney = [1000]
dpStock = [(0, 0)]
for A in As:
    money = max([A*s+m for s, m in dpStock])
    m = max(dpMoney)
    s2, m2 = m//A, m%A
    dpMoney.append(money)
    dpStock.append((s2, m2))

print(max(dpMoney))

Solution (Python):
n=int(input())
n=1000
a=list(map(int,input().split()))
x=[0]*(len(a)-1)
for i in range(len(a)-1):
    x[i]+=a[i+1]-a[i]

cnt=0

for i in range(len(x)):
    if x[i]>0:
        cnt+=n//a[i]
        n%=a[i]
    elif x[i]==0:
        continue
    elif x[i]<0:
        n+=cnt*a[i]
        cnt=0

n+=cnt*a[-1]

print(n)

Solution (Python):



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

cash = 1000
stock = 0

for i in range(n - 1):
    if stock == 0:
        if all(j < a[i] for j in a[i:]):
            break
        else:
            if a[i] < a[i + 1]:
                stock = int(cash / a[i])
                cash = cash % a[i]

    else:
        if a[i] > a[i + 1]:
            cash += stock * a[i]
            stock = 0

if stock != 0:
    cash += stock * a[n - 1]
    stock = 0
print("{}".format(cash))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
up_down = [0]
for i in range(1, N):
    if A[i - 1] < A[i]:
        up_down.append(1)
    elif A[i - 1] > A[i]:
        up_down.append(-1)
    elif A[i - 1] == A[i]:
        up_down.append(0)



money = 1000
kabu = 0

for i in range(0, N - 1):
    if up_down[i + 1] == 1:
        can_buy = money // A[i]
        money -= A[i] * (can_buy)
        kabu += can_buy
    elif up_down[i + 1] == -1:
        money += A[i] * kabu
        kabu = 0
    

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

print(money)

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

diff = [i < j for i, j in zip(A[0:], A[1:])]

buy = []
sell = []
is_increasing = False
for i, diff_i in enumerate(diff):
    if is_increasing is False and diff_i is True:
        buy.append(i)
    if is_increasing is True and diff_i is False:
        sell.append(i)
    is_increasing = diff_i
else:
    sell.append(N - 1)

money = 1000
stock = 0
for i in range(N):
    if i in buy:
        stock = money // A[i]
        money -= stock * A[i]
    elif i in sell:
        money += stock * A[i]
        stock = 0

print(money)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
d=1
kabu=0
ans=1000
while d<=n-1:
    if a[d]>a[d-1]:
        f=ans//a[d-1]
        kabu+=f
        ans=ans-a[d-1]*f
    if a[d]<a[d-1]:
        ans+=kabu*a[d-1]
        kabu=0
    d+=1
ans+=kabu*a[n-1]
print(ans)

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

cur = 1000
stock = 0

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

if stock != 0:
    cur += stock * A[N-1]
    stock = 0

print(cur)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    N, *A = map(int, read().split())
    money = 1000
    kabu_no = 0
    status = 0
    for i in range(len(A)-1):
        if A[i]<A[i+1]:
            if status == 1:
                continue
            elif status == 0:
                kabu_no = money // A[i]
                money %= A[i]
                status = 1
        elif A[i]==A[i+1]:
            continue
        else:
            if status == 1:
                money += kabu_no * A[i]
                kabu_no = 0
                status = 0
            elif status == 0:
                continue
    money += kabu_no * A[N-1]
    print(money)
    return

if __name__ == '__main__':
    main()

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

pos = [1000, 0]

val1 = [lst[0]]

for i in range(1, n):
  if lst[i-1] != lst[i]:
    val1.append(lst[i])

val = []

n = len(val1)
val1.insert(0, 10000)
val1.append(0)

for i in range(1, n+1):
  if val1[i-1] < val1[i] > val1[i+1] or val1[i+1] > val1[i] < val1[i-1]:
    val.append(val1[i])
    

n = len(val)

if val == []:
  print(pos[0])
  exit()
  
for i in range(n):
  if i%2 == 0:
    pos[1] += pos[0]//val[i]
    pos[0] -= pos[1]*val[i]
  
  else:
    pos[0] += pos[1]*val[i]
    pos[1] = 0
    
print(pos[0])

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

kane=[None]*(N+1)
kabu=[None]*(N+1)
kane[0]=1000
kabu[0]=(0,1000)
for i in range(1,N+1):
    kane[i] = max(kane[i-1],kabu[i-1][0]*A[i-1]+kabu[i-1][1])
    
    cand1 = (kane[i-1]//A[i-1],kane[i-1]%A[i-1])
    if A[i-1]<=kabu[i-1][1]:
        cand2 = (kabu[i-1][0]+1,kabu[i-1][1]-A[i-1])
    else:
        cand2 = (kabu[i-1][0],kabu[i-1][1])
    kabu[i] = max(cand1,cand2)

print(kane[-1])

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

INF = float("inf")


N = int(input())
A = list(map(int,input().split()))
sell = [0]*N
buy = [0]*N
hand = [[1000,0] for i in range(N+1)]
for i in range(1,N-1):
    if A[i] >= A[i-1] and A[i] > A[i+1]:
        sell[i] = 1
    if A[i] <= A[i-1] and A[i] < A[i+1]:
        buy[i] = 1
if A[0] < A[1]:
    buy[0] = 1
if A[N-1] > A[N-2]:
    sell[N-1] = 1
for i in range(N-1):
    if buy[i] == 1:
        hand[i+1][0] = hand[i][0] % A[i]
        hand[i+1][1] += hand[i][1] + (hand[i][0] // A[i])
    elif sell[i] == 1:
        hand[i+1][0] = hand[i][0] + A[i]*hand[i][1]
        hand[i+1][1] = 0
    else:
        hand[i+1][0] = hand[i][0]
        hand[i+1][1] = hand[i][1]
if hand[N-1][1] != 0:
    hand[N][0] = hand[N-1][0] + A[N-1]*hand[N-1][1]
else:
    hand[N][0] = hand[N-1][0]
print(hand[N][0])

Solution (Python):
import numpy as np
n = int(input())
As = np.array(list(map(int, input().split())))
As_diff = np.diff(As)
status = "no"
money = 1000
stock = 0
for i in range(n):
    if status == "no":
        if i == n-1:
            continue
        elif As_diff[i] > 0:
            stock += int(money / As[i])
            money -= As[i]*stock
            status = "yes"
      
    else:
        if i == n-1:
            
            money += As[i] * stock
            stock = 0
    
        elif As_diff[i] < 0:
            
            money += As[i] * stock
            stock = 0
            status = "no"
print(money)

Solution (Python):
from collections import defaultdict

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

C = defaultdict(int)

C[0] = 1000

for i in range(N):
    nc = defaultdict(int)

    for n, c in C.items():
        
        n0 = n + c // A[i]
        c0 = c - (c // A[i]) * A[i]
        nc[n0] = max(nc[n0], c0)

        
        c1 = c + n * A[i]
        n1 = 0
        nc[n1] = max(nc[n1], c1)

        
        nc[n] = max(c, nc[n])

    C = nc

print(max(C.values()))

Solution (Python):
n = int(input())
stock_price = [int(i) for i in input().split()]
stock_num = 0
money = 1000

for i in range(n - 1):
    if stock_price[i] < stock_price[i + 1]:
        num = money // stock_price[i]
        money -= num * stock_price[i]
        stock_num += num
    
    if stock_price[i] > stock_price[i + 1]:
        money += stock_num * stock_price[i]
        stock_num = 0

money += stock_num * stock_price[i + 1]

print(money)

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

plus_list = []
prev = 0
cum = 0
for i in range(n):
    if prev <= alist[i]:
        cum += 1
    else:
        cum = 0
    prev = alist[i]
    plus_list.append(cum)


stock = 0
money = 1000

for i in range(n):
    if i == n-1:
        money += stock*alist[i]
        break

    if plus_list[i+1] == 0:
        
        money += stock*alist[i]
        stock = 0
    else:
        if stock != 0:
            continue
        
        stock = int(money / alist[i])
        money -= stock*alist[i]

print(money)

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

ans = 1000
cnt = 0

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

print(ans)

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

ans = 1000
checkpoint = [a[0]]

for i in range(1, n):
    if a[i] >= a[i - 1]:
        checkpoint.append(a[i])
    else:
        kabu = ans // checkpoint[0]
        ans += kabu * (checkpoint[-1] - checkpoint[0])
        checkpoint = [a[i]]

if checkpoint[-1] >= checkpoint[0]:
    kabu = ans // checkpoint[0]
    ans += kabu * (checkpoint[-1] - checkpoint[0])
    
print(ans)

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

balance = 1000
position = A[0]

for i in range(1,N):
    if A[i] > position:
        balance = (balance//position)*A[i] + balance%position
        position = A[i]
    else: position = A[i]

print(balance)

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

buy = []
sell = []

if A[0] < A[1]:
    buy.append(0)
    f = True 
else:
    f = False 
for i in range(1,len(A)-1):
    if f == True:
        if A[i] > A[i+1]:
            sell.append(i)
            f = False
    else:
        if A[i] < A[i+1]:
            buy.append(i)
            f = True
if f == True:
    sell.append(len(A)-1)

ans = 1000
stock = 0
for i in range(len(buy)):
    stock = ans // A[buy[i]]
    ans %= A[buy[i]]
    ans += A[sell[i]] * stock
    stock = 0
print(ans)

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

lis = [0]*N

isnextup = [0]*(N-1) 
for day in range(N-1):
    today = A[day]
    tommorow = A[day+1]
    if today < tommorow:
        isnextup[day] = 1
    elif today > tommorow:
        isnextup[day] = -1
        

money = 1000
stock = 0
for day in range(N-1):
    if isnextup[day] == 1:
        price = A[day]
        div, mod = divmod(money, price)
        money -= price * div
        stock += div
    elif isnextup[day] == -1: 
        price = A[day]
        money += price * stock
        stock = 0

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

Solution (Python):
""" D
    https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d
"""
import sys
import math
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return [lambda _: readIntegerSet(m) for _ in range(0, n)]

def div_by(n, x, k):
    result = 0
    for i in n:
        if x[i] == "1":
            result = (result + pow(2, n-i-1)) % k
    return result

def popcount(x):
    return sum([int(c) for c in x])

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

    money += A[N-1] * kabu

    return money

if __name__ == "__main__":
    _N = readInteger()
    _A = readIntegerSet(_N)

    print(main(_N, _A))

Solution (Python):
import math
N = int(input())
price = list(map(int,input().split()))
price.append(0)
stock = 0
money = 1000
for i in range(N):
    if price[i] <= price[i+1]:
        times = math.floor(money/price[i])
        money -= price[i]*times
        stock += times
    else:
        money += price[i]*stock
        stock =0
print(money)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
kau = [0]*n
index = []
if a[0] < a[1]:
    kau[0] = 1
elif a[0] == a[1]:
    for j in range(1, n):
        if a[0] < a[j]:
            kau[0] = 1
            break
        if a[0] > a[j]:
            break
    
for i in range(1, n-1):
    if a[i-1] > a[i]:
        for j in range(i+1, n):
            if a[i] < a[j]:
                kau[i] = 1
                break
            if a[i] > a[j]:
                break
for i, j in enumerate(kau):
    if j == 1:
        index.append(i)
index.append(n)

ans = 1000
for i in range(len(index)-1):
    kabu = ans//a[index[i]]
    ans -= a[index[i]]*kabu
    ans += max(a[index[i]+1:index[i+1]])*kabu
print(ans)

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

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

down = True
for i in range(1,n):    
    if down and a[i-1] < a[i]:
        s.append(a[i-1])
        down = False
    elif down == False and a[i-1] > a[i]:
        s.append(a[i-1])
        down = True
if len(s)%2!=0:
    s.append(a[-1])

start = 1000
for i in range(0,len(s),2):
    start = (start//s[i])*s[i+1] + start%s[i]

print(start)

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

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

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

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

b = [0] * (n-1)

m = 1000
s = 0





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

if s > 0:
    m += s*a[n-1]

print(m)

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
price={}
flg=10
ans=1000
stock=0
for i in range(1,N):
    if A[i]!=A[i-1]:
        if A[i]>A[i-1]:
            flg=1
            stock=ans//A[0]
            ans-=A[0]*stock
            break
        else:
            flg=0
            break
for i in range(1,N):
    if flg==1:
        if A[i]<A[i-1]:
            flg=0
            price[i-1]=1
    else:
        if A[i]>A[i-1]:
            flg=1
            price[i-1]=0
for i in price.keys():
    if price[i]==1:
        ans+=(int(A[i])*stock)
        stock=0
    else:
        stock=ans//A[i]
        ans-=A[i]*stock
print(ans+(A[-1]*stock))

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

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

M = 1000
for i in L:
    k = M // A[i]
    M -= k * A[i]
    M += k * A[i+1]
print(M)

Solution (Python):
T = 1


for ti in range(1, T + 1):
    n = int(input())
    a = []
    a.extend([int(e) for e in input().split()])
    money, stocks = 1000, 0
    rise = [i for i in range(n)]
    for _ in range(n - 1, 0, -1):
        if a[_] >= a[_ - 1]:
            rise[_ - 1] = rise[_]
    t = 0
    while t < n:
        if rise[t] == t:
            
            money += a[t] * stocks
            stocks = 0
            t += 1
        else:
            deal = money // a[t]
            stocks += deal
            money -= deal * a[t]
            t = rise[t]
    print(money)

Solution (Python):
from itertools import groupby

n = int(input())
a = [i for i, _ in groupby(map(int, input().split()))]
n = len(a)

money = 1000
stock = 0
if n > 1 and a[0] < a[1]:
    stock, money = divmod(money, a[0])
for i in range(1, n-1):
    if a[i-1] < a[i] > a[i+1]:
        money += stock * a[i]
        stock = 0
    elif a[i-1] > a[i] < a[i+1]:
        stock, money = divmod(money, a[i])
if n > 1 and a[-2] < a[-1]:
    money += stock * a[-1]
    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] < a[i+1]:
        count = ans//a[i]
        ans += (a[i+1]-a[i])*count
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
money = 1000
stock = 0
index = 0
while True:
    if stock == 0:
        if a[index] < a[index + 1]:
            stock += money // a[index]
            money -= stock * a[index]
        index += 1
    else:
        if a[index] > a[index + 1]:
            money += stock * a[index]
            stock = 0
        index += 1
    if index == n - 1:
        break
if stock != 0:
    money += stock * a[-1]
print(money)

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

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

    if A_LIST[i] > A_LIST[i + 1]:
        
        money += A_LIST[i] * stock
        stock = 0
        
        


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

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
l.append(0)

m = 1000
s = 0

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

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

Solution (Python):
n=int(input())
al=list(map(int,input().split()))
s=1000
k=0
for i,j in zip(al,al[1:]):
    if i==j:
        continue
    if i<j:
        m=s//i
        k+=m
        s-=m*i
    else:
        s+=k*i
        k=0
s+=k*al[-1]
print(s)

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

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

a_ls+=[0]

m=1000
k=0

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


print(m+k*a_ls[N-1])

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

orl = 1000

for i in range(len(li)-1):
    if li[i] < li[i+1]:
        orl = int(orl/li[i]) * (li[i+1]) + (orl - li[i] * int(orl/li[i]))

print(orl)

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

kabu = 0
money = 1000

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