Problem:
 Score: 400 points    Problem Statement  To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.  He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows:   A_1 yen on the 1 -st day, A_2 yen on the 2 -nd day, ..., A_N yen on the N -th day.   In the i -th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time .   Buy stock: Pay A_i yen and receive one stock.  Sell stock: Sell one stock for A_i yen.   What is the maximum possible amount of money that M-kun can have in the end by trading optimally?      Constraints   2 \leq N \leq 80  100 \leq A_i \leq 200  All values in input are integers.         Input  Input is given from Standard Input in the following format:  N  A_1  A_2  \cdots  A_N       Output  Print the maximum possible amount of money that M-kun can have in the end, as an integer.        Sample Input 1 7
100 130 130 130 115 115 150      Sample Output 1 1685  In this sample input, M-kun has seven days of trading. One way to have 1685 yen in the end is as follows:   Initially, he has 1000 yen and no stocks.  Day 1 : Buy 10 stocks for 1000 yen. Now he has 0 yen.  Day 2 : Sell 7 stocks for 910 yen. Now he has 910 yen.  Day 3 : Sell 3 stocks for 390 yen. Now he has 1300 yen.  Day 4 : Do nothing.  Day 5 : Buy 1 stock for 115 yen. Now he has 1185 yen.  Day 6 : Buy 10 stocks for 1150 yen. Now he has 35 yen.  Day 7 : Sell 11 stocks for 1650 yen. Now he has 1685 yen.   There is no way to have 1686 yen or more in the end, so the answer is 1685 .       Sample Input 2 6
200 180 160 140 120 100      Sample Output 2 1000  In this sample input, it is optimal to do nothing throughout the six days, after which we will have 1000 yen.       Sample Input 3 2
157 193      Sample Output 3 1216  In this sample input, it is optimal to buy 6 stocks in Day 1 and sell them in Day 2 , after which we will have 1216 yen.

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
 
m = 1000
 
for a,b in zip(A,A[1:]):
    if a >= b: continue
    k,m = divmod(m,a)
    m += k*b
print(m)

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 money != 0:
        kabu += money // a[i]
        money -= a[i] *(money // a[i])
    elif a[i] > a[i+1] and kabu != 0:
        money += a[i] * kabu
        kabu = 0
print(money + a[-1] * kabu)

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

ans = 1000
lastpay = -1
buy = True
stock = 0

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

for i in range(len(buf)):
  if buy:
    if i == 0 and buf[i]>0:
      buy = False
      dstock = ans//A[i]
      stock += dstock
      ans -= dstock*A[i]
      lastpay = dstock*A[i]
      
    elif i>0 and buf[i]>0:
      buy = False
      dstock = ans//A[i]
      stock += dstock
      ans -= dstock*A[i]
      lastpay = dstock*A[i]
      
    if i == N-2 and buf[i]>0:
       ans += stock*A[i+1]
        
  else:
    if buf[i-1]>=0 and buf[i]<0:
      buy = True
      ans += stock*A[i]
      stock = 0
      
    elif i == N-2 and buf[i]>=0:
      buy = True
      ans += stock*A[i+1]
      

print(ans)

Solution (Python):
import sys
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 kabu == 0 :
    kabu = money // A[i]
    money = money - kabu*A[i]
  elif A[i] > A[i + 1] and kabu > 0:
    money = money + kabu*A[i]
    kabu = 0
    
if kabu > 0 :
  print(money + kabu*A[N-1])
else :
  print(money)

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

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

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

print(money)

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

Solution (Python):
N = int(input())
*A, = map(int, input().split())
money, stock = 1000, 0
for a, nxt in zip(A, A[1:]):
    money += stock * a
    stock = 0
    if a <= nxt:
        stock, money = divmod(money, a)
money += stock * A[-1]
print(money)

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

stock = 1000

num = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        num += stock // A[i]
        stock %= A[i]
    elif A[i] > A[i+1]:
        stock += num * A[i]
        num = 0

print(stock+A[-1]*num)

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

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

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

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

money=1000
kabu=0

for i in range(N-1):
    if A[i] < A[i+1]:
        kabu+=money // A[i]
        money=money % 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())
stack = list(map(int,input().split()))
cnt = 1000
p = stack[0]
g = stack[0]
f = 0
for i in range(len(stack)):
    if stack[i] > g:
        g = stack[i]
        f = 1
        continue

    if stack[i] < g:
        itp = cnt // p
        cnt = cnt - (itp * p)
        cnt = cnt + (itp * g)
        p = stack[i]
        g = stack[i]
        f = 0

itp = cnt // p
cnt = cnt - (itp * p)
cnt = cnt + (itp * g)
print(cnt)

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

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

  m += s*A[i+1]
  s = 0

print(m)

Solution (Python):
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

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


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

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

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

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

s=1000

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

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

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

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


i += 1
total += (kabu * A[i])
kabu = 0
print(total)

Solution (Python):
from bisect import bisect_right

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

    money = 1000
    stock = 0
    old_trend = 0
    trend = A[1] - A[0]
    buy_point = []
    bought_point = []

    for i in range(N-1):
        trend = A[i+1] - A[i]
        if trend * old_trend > 0 or trend == 0:
            continue
        else:
            if trend > 0:
                buy_point.append(i)
            if trend < 0:
                bought_point.append(i)
        old_trend = trend

    if len(buy_point) > len(bought_point):
        bought_point.append(N-1)

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

        
        if i in bought_point:
            bought = stock
            stock = 0
            money += bought * A[i]
    print(money)
    


if __name__ == "__main__":
    main()

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

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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    A = list(readnums())
    b = 1000
    s = 0
    for i in range(N - 1):
        if A[i] < A[i + 1]:
            s += b // A[i]
            b %= A[i]
        elif A[i] > A[i + 1]:
            b += A[i] * s
            s = 0

    if A[-1] >= A[-2]:
        b += A[-1] * s
        s = 0

    print(b)
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    


if __name__ == "__main__":
    main()

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

money = 1000
for i in range(len(a_list) - 1):
  if a_list[i] < a_list[i+1]:
    money += (a_list[i+1] - a_list[i]) * (money // a_list[i])
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]:
        pass
    else:
        T=ans//A[i]
        ans+=T*(A[i+1]-A[i])
print(ans)

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


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

  buy = []
  sell = []

  iflag = False
  if A[0] < A[1]:
    iflag = True
    buy.append(0)
  else:
    iflag = False

  for i in range(2, N):
    if iflag and A[i-1] < A[i]:
      iflag = True

    elif iflag and A[i-1] > A[i]:
      iflag = False
      sell.append(i-1)

    elif not(iflag) and A[i-1] < A[i]:
      iflag = True
      buy.append(i-1)

    elif not(iflag) and A[i-1] > A[i]:
      iflag = False

    else:
      continue

  if iflag:
    sell.append(N-1)

  
  

  m = 1000
  nstack = 0
  for i in range(N):
    if i in buy:
      nbuy = (m//A[i])
      m -= A[i]*nbuy
      nstack += nbuy
    if i in sell:
      m += A[i]*nstack
      nstack = 0
    
  print(m)


if(__name__ == '__main__'):
  main()

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

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()
B = [0] + LI()

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

N = len(A)-1
MAX = [0,1000] + [0]*N  

from functools import lru_cache

@lru_cache(maxsize=None)
def dfs(n,money):
    if n == N+1:
        return money
    else:
        res = money
        for i in range(n,N):  
            for j in range(i+1,N+1):  
                if A[i] == min(A[i:j+1]) and A[j] == max(A[i:j+1]) and A[i] < A[j]:
                    a = money+(A[j]-A[i])*(money//A[i])
                    if a > MAX[j+1]:
                        res = max(res,dfs(j+1,a))
                        MAX[j+1] = a
        return res

print(dfs(1,1000))

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def main():
    n = II()
    aa = MII()
    balance = 1000
    for i in range(n-1):
        if aa[i] < aa[i+1]:
            num = balance // aa[i]
            balance += num * (aa[i+1] - aa[i])
    print(balance)

if __name__ == '__main__':
    main()

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

baibai = [] 

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)



for j in range(N):
    if 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):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n):
    res = [None] * n
    for i in range(n):
        res[i] = II()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI()
    return res
def FR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR_(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI_()
    return res
def SR(n):
    res = [None] * n
    for i in range(n):
        res[i] = S()
    return res
def LSR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LS()
    return res
mod = 1000000007
inf = float('INF')


def solve():
    n = II()
    a = LI()
    ans = 1000
    have = 0
    state = 0
    for i in range(n - 1):
        if state == 0:
            if a[i] < a[i + 1]:
                have += ans // a[i]
                ans %= a[i]
                state = 1
        else:
            if a[i] > a[i + 1]:
                ans += a[i] * have
                have = 0
                state = 0
    ans += a[-1] * have
    print(ans)
    return



if __name__ == '__main__':
    solve()

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

money = 1000
ad = 0
for i in range(n - 1):
    if a[i + 1] > a[i]:
        buy_stock = (money // a[i])
        buy_money = buy_stock * a[i]
        sel = buy_stock * a[i + 1]
        remain = money - buy_money
        money = remain + sel
    

print(money)

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

m = 1000
k = 0

for i in range(n):
    if i == n-1: 
        m = m + A[i]*k
    elif A[i] <= m and A[i] < A[i+1]: 
        k = m//A[i]
        m = m - A[i]*k
    elif 0 < k and A[i+1] < A[i]: 
        m = m + A[i]*k
        k = 0
    else:
        pass

print (m)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt, pi
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

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





N = getN()
A = getList()

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

Solution (Python):
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    C = 1000
    kabu = 0

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

    print(C)

resolve()

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

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

mon=1000
for i in range(1,N):
    if A[i]>A[i-1]:
        sho,mod=divmod(mon,A[i-1])
        mon=sho*A[i]+mod

print(mon)

Solution (Python):
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))

n = inN()
a = inL()

kab = 0
mon = 1000
f = []
i=0
state = 0
while(i < n-1):
    if state == 1:
        while(i<n-1):
            
            if a[i+1]>=a[i]:
                f.append(0)
                i+=1
            else:
                f.append(2)
                
                break
        state = 0
    elif state == 0:
        while(i<n-1):
            if a[i+1]<=a[i]:
                f.append(0)
                i +=1
            else:
                f.append(1)
                
                state = 1
                break
    else:
        f.append(0)
    i += 1
f.append(2)
    

for i in range(n):

    if f[i] == 1 :
        kab += mon//a[i]
        mon = mon % a[i]
    elif f[i] == 2:
        mon += a[i]*kab
        kab = 0
    
print(mon)

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

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

CurrentMoney = 1000

for i in range(0, n-1):
    Stocks = 0
    if A[i] < A[i+1]: Stocks = CurrentMoney // A[i]
    CurrentMoney += (A[i+1] - A[i]) * Stocks

print(CurrentMoney)

Solution (Python):
N = 2
ARR = [157, 193]

N = 6
ARR = [200, 180, 160, 140, 120, 100]

N = 7
ARR = [100, 130, 130, 130, 115, 115, 150]

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





def prepare(n,arr):
    result = []
    for i in range(n):
        if i == 0:
            result.append(arr[0])
        else:
            if arr[i] != arr[i-1]:
                result.append(arr[i])
    return result


def calculate(arr):
    n = len(arr)
    result = []
    for i in range(n):
        if i == n-1:
            if arr[i] > arr[i-1]:
                result.append({'type': 1, 'value': arr[i]})
            continue

        if i == 0:
            if arr[1] > arr[0]:
                result.append({'type': 0, 'value': arr[i]})
            continue

        if (arr[i + 1] > arr[i]) and (arr[i] < arr[i - 1]):
            result.append({'type': 0, 'value': arr[i]})

        if (arr[i + 1] < arr[i]) and (arr[i] > arr[i - 1]):
            result.append({'type': 1, 'value': arr[i]})

    money = 1000
    num = 0
    for index,res in enumerate(result):
        type = res.get('type')
        value = res.get('value')

        if index == (len(result) - 1):
            if value == 1:
                continue

        if type == 0:
            tmpNum = money // value
            num += tmpNum
            money -= value * tmpNum
        else:
            money += num * value
            num = 0

    print(money)


arr = prepare(N, ARR)
calculate(arr)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
money = 1000
kabu = 0
todo = [0]*n
for i in range(n):
    if(i == 0):
        if(a[n-2-i] < a[n-1-i]):
            state = 1
            todo[n-1] = 1
        elif(a[n-2-i] > a[n-1-i]):
            state = -1
            todo[n-1] = 0
        else:
            state = 0
            todo[n-1] = 0
    elif(i == n-1):
        if(state == 1):
            todo[n-1-i] = -1
    else:
        if(a[n-2-i] < a[n-1-i]):
            temp = 1
            if(state != temp):
                todo[n-1-i] = 1
            state = 1
        elif(a[n-2-i] > a[n-1-i]):
            temp = -1
            if(state != temp):
                todo[n-1-i] = -1
            state = -1

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
syoji = 1000
kabu = 0
kai = 0
uri = 0
if N ==1:
  print(syoji)
  exit()
sw = 0
for i in range(N):
  if i<N-1 and kabu == 0 and A[i] < A [i+1]:
    for j in range(i+1,N):
      if sw ==1 and uri >= A[j]:
        break
 
      elif  A[i] < A[j]:
        uri = A[j]
        sw = 1
    if sw ==1:
      kabu = syoji // A[i]
      syoji = syoji - kabu*A[i]
      kai = A[i]
      sw = 0
  elif kabu > 0 and A[i]==uri:
    syoji = syoji + kabu*A[i]
    kabu = 0
    uri = 0
 
        
print(syoji)

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

    N = len(A)
    money = 1000
    for i in range(0,N):
        if i+1 >= N:
            break
        money2 = money // A[i] * A[i+1] +  money % A[i]
        money = max(money,money2)
    
    print(money)
        
if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
A = tuple(map(int, input().split()))
m = 1000
kabu = 0
for pa, aa in zip(A[:n], A[1:]):
    if pa < aa:
        
        kk, m = divmod(m, pa)
        kabu += kk
    elif pa > aa:
        
        m += kabu * pa
        kabu = 0

if kabu > 0:
    m += kabu*aa

print(m)

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

money = 1000

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

print(money)

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


a=[]
ma=False

for i in range(len(tl)):
    if len(tl)==1:
        break
    if i==0:
        if tl[i]>tl[i+1]:
            ma=True
            a.append(tl[i])
        else:
            ma=False
            a.append(tl[i])
    elif i==len(tl)-1:
        if tl[i]>tl[i-1]:
            a.append(tl[i])
        else:
            a.append(tl[i])
    else:
        if tl[i-1]<tl[i] and tl[i+1]<tl[i]:
            a.append(tl[i])
        elif tl[i-1]>tl[i] and tl[i+1]>tl[i]:
            a.append(tl[i])

if ma:
    a.pop(0)


num=0
ans=1000

for i in range(0,len(a)-1,2):
    
    thing1=(ans//(a[i]))*a[i+1]
    thing2=num*a[i+1]
    if thing1>thing2:
        ans=thing1+ans%a[i]
        num=0
        
    elif thing2>thing1:
        ans=thing2

print(ans)

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

cash = 1000
hold_stock = 0

for i in range(N):
    stock_price = stocks[i]
    if hold_stock == 0:
        if i == N-1:
            break
        elif stock_price == max(stocks[i:]):
            pass
        else :
            j = 1
            next_stock_price = stocks[i+j]
            while stock_price == next_stock_price:
                j += 1
                next_stock_price = stocks[i+j]
                if i + j == N:
                    break
            if next_stock_price < stock_price:
                pass
            else :
                hold_stock, cash = divmod(cash, stock_price)
    else :
        if i == N-1:
            cash += hold_stock*stock_price
            hold_stock = 0

        elif stock_price == min(stocks[i:]):
            pass
        else :
            j = 1
            next_stock_price = stocks[i+j]
            while stock_price == next_stock_price:
                j += 1 
                next_stock_price = stocks[i+j]
                if i + j == N:
                    break
            if next_stock_price > stock_price:
                pass
            else :
                cash += hold_stock*stock_price
                hold_stock = 0

print(cash)

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

Solution (Python):
from collections import defaultdict


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

money = 1000
min_v = a[0]
max_v = a[0]

for i in range(1,n):
    if max_v > a[i]:
        money = money//min_v * max_v + money % min_v
        min_v = a[i]
        max_v = a[i]
    
    max_v = a[i] if a[i] > max_v else max_v
    min_v = a[i] if a[i] < min_v else min_v

    if i == n-1 and a[i] > min_v:
        money = money//min_v * max_v + money % min_v

    

print(money)

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


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

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))
ct = 1000
stock = 0

lst2 = [0]*n
for i in range(n-1):
    if lst1[i] < lst1[i+1]:
        lst2[i] = 1
    elif lst1[i] > lst1[i+1]:
        lst2[i] = -1
for i in range(n):
    if lst2[i] == 1:
        stock += ct//lst1[i]
        ct %= lst1[i]
    elif lst2[i] == -1:
        ct += stock*lst1[i]
        stock = 0


print(ct + stock*lst1[-1])

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N = I()
A = LI()

X = []
Y = 1000

for i in range(N):
    for x in X:
        if Y < x[0]*A[i]+x[1]:
            Y = x[0]*A[i]+x[1]
    X.append((Y//A[i],Y%A[i]))

print(Y)

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

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]





N = ii()
A = li()

yen = 1000
kabu = 0

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

print(yen)

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

min_money = 0
ans = 1000
i = 0
while i < n:
    stock = 0
    rest = 0
    for k in range(i, n):
        if a[k] < a[k + 1]:
            min_money = a[k]
            stock = ans // a[k]
            rest = ans % a[k]
            i = k
            break
    
    if stock != 0:
        temp = stock * a[i+1]
        for k in range(i, n):
            if temp <= a[i+1] * stock:
                ans = a[i+1] * stock
    ans += rest
    i += 1

print(ans)

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter

from fractions  import gcd

import bisect
n=int(input())
a=list(map(int,input().split()))
i=0
m=1000
f=True
k=0
M=[1000]
res=[0]*(n-1)
for i in range(1,n):
    if a[i]<a[i-1]:
        res[i-1]=-1
    else:
        res[i-1]=1

for i in range(n):

    if f:
        if i==n-1:
          break
        if res[i]==1:
            f=False 
            k=m//a[i]
            m=m%a[i]
        else:
          continue
    else:
        if i==n-1 or res[i]==-1:
            m=k*a[i]+m
            M.append(m)
            f=True 
        else:
            continue
print(max(M))

Solution (Python):
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))

    A.append(0)
    min_, max_ = A[0], A[0]
    money = 1000
    for i in range(N + 1):
        if A[i] < max_:
            d, m = divmod(money, min_)
            money = d * max_ + m
            min_, max_ = A[i], A[i]
            continue
        min_ = min(min_, A[i])
        max_ = max(max_, A[i])
    print(money)


main()

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

cash = 1000
stocks = 0

buy = []
sell = []

trend = 'down'

for i in range(n-1):
    if trend == 'down':

        if A[i] >= A[i+1]:
            continue
        else:
            trend = 'up'
            buy.append(i)
            if i == n-2:
                sell.append(i+1)
    
    else:
        if A[i] <= A[i+1]:
            if i == n-2:
                sell.append(i+1)
            continue
        else:
            trend = 'down'
            sell.append(i)

while len(buy) and len(sell):
    b = buy.pop(0)
    count = cash // A[b]
    cash -= A[b] * count
    stocks += count

    s = sell.pop(0)
    cash += A[s] * stocks
    stocks = 0

print(cash)