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
input = sys.stdin.readline
from bisect import bisect_left;
from bisect import bisect_right;
from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1;
    return x;
    

def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;


def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);


def nCr(n, k): 
    if(k > n - k): 
        k = n - k; 
    res = 1;
    for i in range(k): 
        res = res * (n - i);
        res = res / (i + 1); 
    return int(res);


def primefs(n):
    
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    
    
    return primes


def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 


def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;









def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;




def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x


def sieve(n): 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime


MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    




def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret;
    
    


def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));


def str_array():
    return input().strip().split();


MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');



n = int(input()); a = int_array();
ans = 1000; shares = 0;
for i in range(n - 1):
    if a[i] < a[i + 1]:
        
        shares += ans // a[i];
        ans %= a[i];
        
        ans += shares * a[i + 1];
        shares = 0;
print(ans);

Solution (Python):


import sys
input = sys.stdin.readline
from bisect import bisect_left;
from bisect import bisect_right;
from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1;
    return x;
    

def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;


def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);


def nCr(n, k): 
    if(k > n - k): 
        k = n - k; 
    res = 1;
    for i in range(k): 
        res = res * (n - i);
        res = res / (i + 1); 
    return int(res);


def primefs(n):
    
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    
    
    return primes


def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 


def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;









def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;




def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x


def sieve(n): 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime


MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    




def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret;
    
    


def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));


def str_array():
    return input().strip().split();


MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');



n = int(input()); a = int_array();
ans = 1000; shares = 0;
for i in range(n):
    if i < n - 1 and a[i] < a[i + 1]:
        shares += ans // a[i];
        ans %= a[i];
    else:
        ans += shares * a[i];
        shares = 0;
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] and a[i]<=money:
        kabu+=money//a[i]
        money-=kabu*a[i]
    if a[i]>a[i+1] and kabu>0:
        money+=kabu*a[i]
        kabu=0
if kabu>0:
    money+=kabu*a[-1]
print(money)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()+[0]

money=1000
ans=1000
kabu=0

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

  ans=max(ans,money)

print(ans)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()+[0]

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

print(money)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()

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

money+=kabu*a[n-1]
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+1]>A[i]:
    S+=M//A[i]
    M-=A[i]*(M//A[i])
  else:
    M+=S*A[i]
    S=0
    
print(M+S*A[N-1])

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

tmp = []
for i in range(1, len(As)):
    if As[i]-As[i-1]>0:
        tmp.append(1)
    elif As[i]-As[i-1]<0:
        tmp.append(-1)
    else:
        tmp.append(0)

seq = False
money = 1000
stock = 0
for i, pm in enumerate(tmp, 1):
    if pm==1:
        if seq == False:
            stock = As[i-1]
            seq = True
    if pm==-1:
        if stock:
            stock_num = money//stock
            money-=stock*stock_num

            max_ = As[i-1]
            money+=max_*stock_num

            seq = False
            stock = 0
    if len(tmp) == i:
        if stock<As[i] and stock!=0:
            stock_num = money//stock
            money-=stock*stock_num
            max_ = As[i]
            money+=max_*stock_num
print(money)

Solution (Python):


import itertools
import collections
from decimal import Decimal
from functools import reduce
import heapq

def main():
    n = int(input())
    a = input_list()
    money = 1000
    stocks = 0
    for i, v in enumerate(a):
        if stocks > 0:
            money += v * stocks
            stocks = 0
        if i == len(a)-1:
            continue
        if v < a[i+1]:
            stocks = money // v
            money -= stocks * v
    print(money)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def bfs(H, W, black_cells, dist):
    d = 0
    while black_cells:
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:
                dist[new_h][new_w] = d + 1
                black_cells.append((new_h, new_w))
    return d


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


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

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):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

Solution (Python):
import sys

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

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

print(yen)

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

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

Solution (Python):
import math
import collections
import fractions
import itertools
import functools
import operator

def divis(l):
    seq = []
    beg, end = 0, 0
    le = len(l)
    for i in range(1,le):
        end = i
        if l[i] < l[i-1]:
            seq.append(l[beg:end])
            beg = i
    seq.append(l[beg:end+1])
    return seq

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    a = divis(a)
    yosan = 1000
    for i in a:
        yosan += (i[-1]-i[0])*(yosan//i[0])
    print(yosan)
    return 0

if __name__ == "__main__":
    solve()

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

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

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

for a in alst:
    tmp1 = max(dp[-1][0], dp[-1][1][0] * a + dp[-1][1][1])
    tmp2 = tmp1 // a
    tmp3 = tmp1 % a
    dp.append([tmp1, [tmp2, tmp3]])
print(dp[-1][0])

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

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

print(ans)

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

n = int(input())
*a, = 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] + b % a[i]
print(b)

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

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

Solution (Python):
N = int(input())
A_list = list(map(int, input().split()))
zandaka = 1000
kabu = 0
mode = 0

for i in range(N):
  if i == 0:
    if A_list[i + 1] > A_list[i]:
      kabu = 1000 // A_list[i]
      zandaka -= kabu * A_list[i]
      mode = 1
    else:
      continue
  elif i == N - 1:
    zandaka += kabu * A_list[i]
  else:
    if mode == 1:
      if A_list[i] >= A_list[i - 1]:
        if A_list[i] > A_list[i + 1]:
          zandaka += kabu * A_list[i]
          kabu = 0
          mode = 0
        else:
          continue
    else:
      if A_list[i] < A_list[i + 1]:
        kabu = zandaka // A_list[i]
        zandaka -= kabu * A_list[i]
        mode = 1
      else:
        continue

if zandaka >= 1000:
  print(zandaka)
else:
  print(1000)

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

x = 1000
for i in range(n-1):
    if A[i] < A[i+1]:
        q, x = divmod(x, A[i])
        x += q*A[i+1]
print(x)

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

x = 1000
for i in range(n-1):
    if A[i] < A[i+1]:
        q, x = divmod(x, A[i])
        x += q*A[i+1]
print(x)

Solution (Python):

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

money = 1000
stock = 0

i = 0
for i in range(N):
  
  if i != 0 and A[i] > A[i-1]:
    money += stock * A[i]
    stock = 0
  
  
  if i != (N-1) and A[i+1] > A[i]:
    stock += money // A[i]
    money = money % A[i]
print(money)

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

m=1000

tmp = A[0]
stock=0

for i,ai in enumerate(A):
    if tmp>=ai:
        m+=tmp*stock
        stock=0
        if ai < max(A[i:]):
            stock=m//ai
            m-=ai*stock
    tmp = ai
print(m+stock*A[-1])

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

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

Solution (Python):


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

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

print(total)

Solution (Python):
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def divis(l):
    seq = []
    beg, end = 0, 0
    le = len(l)
    for i in range(1,le):
        end = i
        if l[i] < l[i-1]:
            seq.append(l[beg:end])
            beg = i
    seq.append(l[beg:end+1])
    return seq

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    divia = divis(a)
    saihu = 1000
    for i in divia:
        saihu += (i[-1]-i[0])*(saihu//i[0])
    print(saihu)
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def divis(l):
    seq = []
    beg, end = 0, 0
    le = len(l)
    for i in range(1,le):
        end = i
        if l[i] < l[i-1]:
            seq.append(l[beg:end])
            beg = i
    seq.append(l[beg:end+1])
    return seq

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    divia = divis(a)
    saihu = 1000
    for i in divia:
        saihu += (i[-1]-i[0])*(saihu//i[0])
    print(saihu)
    return 0

if __name__ == "__main__":
    solve()

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

monney = 1000
stock = 0


def max_day(index):
    if index == N-1 or (A_list[index] > A_list[index+1]):
        return index
    return max_day(index+1)


def min_day(index):
    if index == N-1:
        return -1
    if A_list[index] < A_list[index+1]:
        return index
    return min_day(index+1)


def main(day=0, flag="buy"):
    global monney, stock
    if flag == "buy":
        buy_day = min_day(day)
        if buy_day == -1:
            return monney
        stock, monney = divmod(monney, A_list[buy_day])
        return main(buy_day+1, "sell")
    elif flag == "sell":
        sell_day = max_day(day)
        monney += stock * A_list[sell_day]
        stock = 0
        if sell_day == N-1:
            return monney
        return main(sell_day+1, "buy")


print(main())

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]:
        zzz = ans // a[i]
        ans -= zzz * a[i]
        ans += zzz * a[i + 1]

print(ans)

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

for i in range(0, N):
  if i != N-1 and A[i] < A[i+1]:
    if S == 0:
      S = M // A[i]
      M = M % A[i]
  elif i == N-1 or A[i] > A[i+1]:
    if S > 0:
      M += S * A[i]
      S = 0  
print(M)

Solution (Python):
n = int(input())
a_nums = list(map(int, input().split()))
money = 1000
stock = 0
for i in range(n):
    if i != n - 1 and a_nums[i] < a_nums[i + 1]:
        times = money // a_nums[i]
        stock += times
        money -= a_nums[i] * times
    elif i == n - 1 or a_nums[i] > a_nums[i + 1]:
        money += stock * a_nums[i]
        stock = 0
print(money)

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

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

print(money)

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



































money = 1000
kabu = 0
a = []
for kabuka in given_a:
    if len(a) > 0 and a[-1] == kabuka:
        continue
    else:
        a.append(kabuka)

n = len(a)
if n ==1:
    print(money)
    exit()

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

print(money)

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

money = 1000
kabu = 0

a = []
for kabuka in given_a:
    if len(a) > 0 and a[-1] == kabuka:
        continue
    else:
        a.append(kabuka)

n = len(a)
if n == 1:
    print(money)
    exit()


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

print(money)

Solution (Python):

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

cur = 1000
stock = 0
state = 0  
for i in range(N - 1):
    if state == 1 and X[i] > X[i + 1]:
        cur += X[i] * stock
        stock = 0
        state = 0
    elif state == 0 and X[i] < X[i + 1]:
        n = cur // X[i]
        cur -= X[i] * n
        stock += n
        state = 1

print(cur + stock * X[-1])

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

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

print(ans)

Solution (Python):

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

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

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

print(m)

Solution (Python):

import sys
def main(N, A):
    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[N])

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)

Solution (Python):

import sys
def main(N, A):
    m = ans = 1000
    s = 0
    for i in range(N - 1):
        if A[i + 1] > A[i]:
            s += m // A[i]
            m %= A[i]
        else:
            m += s * A[i]
            s = 0
        ans = max(ans, m)
    ans = max(ans, m + s * A[-1])
    print(ans)

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)

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

def buy(money, stock, p):
    amount = money // p
    return (money - amount * p), amount

def sell(money, stock, p):
    return (money + stock * p), 0

money = 1000
stock = 0
for i, (p, q) in enumerate(zip(a[:-1], a[1:])):
    if stock == 0 and p < q:
        money, stock = buy(money, stock, p)
    elif stock and p > q:
        money, stock = sell(money, stock, p)

if stock:
    money += stock * a[-1]

print(money)

Solution (Python):
n=int(input())
a=[int(o) for o in input().split()]
ans=1000
stock=0
prev=0
for i in range(n-1):
    if i>0 and prev<a[i] and stock>0:
        ans+=stock*a[i]
        stock=0
    if a[i]<a[i+1]:
        m=ans//a[i]
        ans-=m*a[i]
        stock+=m
        prev=a[i]
    
if  prev<a[n-1] and stock>0:
        ans+=stock*a[n-1]
print(ans)

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


if __name__ == '__main__':
    solve()

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

Solution (Python):
def sell(m,s,a):
  return m+s*a,0

def buy(m,a):
  return m%a,m//a

def solve():
  m = 1000
  s = 0
  N = int(input())
  A = list(map(int, input().split()))
  for i in range(N-1):
    m,s = sell(m,s,A[i])
    if A[i]<A[i+1]:
      m,s = buy(m,A[i])
  m,s = sell(m,s,A[-1])
  return m
print(solve())

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

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

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

print(max(dp))

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

c=1000

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

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

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

stock = 0
money = 1000
for i in range(N-1):
    today = A[i]
    tomorrow = A[i+1]
    if today < tomorrow:
        
        n = money // today
        money -= n * today
        stock += n
    elif today > tomorrow:
        
        money += stock * today
        stock = 0
print(money + stock * A[-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] = dp[i-1]
    for j in range(i):
        s = dp[j] // a[j]
        m = dp[j] + (a[i] - a[j]) * s
        dp[i] = max(dp[i], m)

print(dp[n-1])

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 += (a[i+1]-a[i]) * s

print(m)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
i = 0
money = 1000
while i < N-1:
    today = i
    j = i + 1
    while A[i] <= A[j]:
        i += 1; j += 1
        if j == N:
            break
    money += (money // A[today]) * (A[i] - A[today])
    i = j
print(money)

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

B = []
temp = 0
for i in range(N):
    if A[i] != temp:
        B.append(A[i])
        temp = A[i]

N = len(B)
A = [float("inf")] + B + [0]

money, stock = 1000, 0
for i in range(1, N + 1):
    if A[i - 1] > A[i] and A[i] < A[i + 1]:
        x = money // A[i]
        money -= A[i] * x; stock += x
    if A[i - 1] < A[i] and A[i] > A[i + 1]:
        x = stock
        money += A[i] * x; stock -= x

print(money)

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

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

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

Solution (Python):

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

money = 1000
kabu = 0 

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

print(money)

Solution (Python):

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


dp = [0] * 100
dp[0] = 1000
for i in range(1,N):
    dp[i] = dp[i-1]
    for j in range(0,i):
        V = int(dp[j] / A[j])
        W = dp[j] + (A[i] - A[j]) * V
        dp[i] = max(dp[i], W)
print(dp[N-1])

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

A = list(map(int,input().split()))
chk = []

for i in range(N-1):
    if A[i+1] > A[i]:
        chk.append(1)
    else:
        chk.append(0)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
m=1000
day_buy=[]
for i in range(n):
    if i==0:
        if a[i]<a[i+1]:
            day_buy.append(i)
    elif i<n-1:
        if a[i-1]>=a[i] and a[i]<a[i+1]:
            day_buy.append(i)
day_sell=[]
for j in range(n):
    if n-1>j>0:
        if a[j-1]<a[j] and a[j]>=a[j+1]:
            day_sell.append(j)
    elif j==n-1>0:
        if a[j-1]<a[j]:
            day_sell.append(j)
k=0
for i in range(len(day_buy)):
    kb=m//a[day_buy[i]]
    m-=kb*a[day_buy[i]]
    k+=kb
    m+=k*a[day_sell[i]]
    k=0
print(m)

Solution (Python):

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

a = []
for k in given_a:
    if len(a) > 0 and a[-1] == k:
        continue
    else:
        a.append(k)

money = 1000
kabu = 0 

n = len(a)

if n == 1:
    print(money)
    exit()

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

print(money)

Solution (Python):
N = int(input())
C = list(map(int, input().strip().split()))
curr = 1000
for i in range(1, N):
    if C[i] > C[i - 1]:
        share, remain = divmod(curr, C[i - 1])
        curr = remain + share * C[i]
print(curr)

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

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

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

    for i, a in enumerate(A):
        dp[i + 1] = dp[i]
        for j in range(i):
            buy, rest = divmod(dp[j], A[j])
            dp[i + 1] = max(dp[i + 1], buy * a + rest)

    print(dp[-1])


if __name__ == '__main__':
    main()