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
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
A = LI()
money,stock = 1000,0
temp = A[0]
for i in range(1,N):
    if temp<A[i]:
        add_stock = money//A[i-1]
        money -= A[i-1]*add_stock
        stock += add_stock
    if temp>A[i]:
        if stock:
            money += A[i-1]*stock
            stock = 0
    if i==N-1:
        if stock:
            money += A[i]*stock
    temp = A[i]
print(money)

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

shojikin = 1000
kabu = 0

l = [0,0]
s = [0,0]
for i in range(n-1) :
    if kabu == 0 : 
        if a[i] < a[i+1] :
            l[0] = shojikin // a[i]
            l[1] = shojikin % a[i]
            shojikin = l[1]
            kabu += l[0]
            l[0] = 0
            l[1] = 0
    if kabu > 0 :
        if a[i] > a[i+1] :
            shojikin += kabu * a[i]
            kabu = 0

if kabu > 0 :
    shojikin += kabu * a[n-1]

print(shojikin)

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

ans = 1000
left = A[0]
right = 0
for i in range(n-1):
    right = A[i]
    if A[i]>A[i+1]:
        ans+=(right-left)*(ans//left)
        left = A[i+1]
        

if left<A[-1]:
    ans+=(A[-1]-left)*(ans//left)
print(ans)

Solution (Python):
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

N = ri()
A = ri_()
A.append(-1)
sell = set([])
buy = set([])
tmp = A[0]
f = 0
bf = False
for i in range(1, N + 1):
    if tmp < A[i]:
        if f == 0:
            f = 1
            buy.add(0)
        if f == 1:
            f = 1
        else:
            buy.add(i - 1)
            f = 1
    elif tmp > A[i]:
        if f == 0 or f == 2:
            f = 2
        else:
            sell.add(i - 1)
            f = 2
    tmp = A[i]
m = 1000
k = 0
L = max(sell) if sell else N - 1
for i in range(L):
    if i in buy:
        k = k + m // A[i]
        m = m % A[i]
    elif i in sell:
        m = m + k * A[i]
        k = 0
print( m + k * A[L])

Solution (Python):
import math
N = int(input())
A = list(map(int, input().split()))
C = 1
m = A[0]
M = A[0]
money = 1000;
for i in range(1,N):
  if C == 1 and M <= A[i]:
    M = A[i]
  elif C == 1 and M > A[i]:
    money = (money % m) + math.floor(money / m)*M
    C = 0
    m = A[i]
  elif C == 0 and m >= A[i]:
    m = A[i]
  elif C == 0 and m < A[i]:
    M = A[i]
    C = 1
if C == 1:
  money = (money % m) + math.floor(money / m)*M
print(money)

Solution (Python):
n = int(input())
A = [201]+list(map(int,input().split()))+[99]
maxp = 0
minp = A[0]
money = 1000
stock = 0
for i in range(n+1):
  if A[i] >= A[i+1] and A[i]>minp:
    money = (money//minp)*A[i]+money%minp
    minp = A[i+1]
  minp = min(minp,A[i+1])
print(money)

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

c = 1000
s = 0

for i in range(0,N-1):
  if ((A[i]-A[i-1])*(A[i+1]-A[i])>0) and i>0:
    continue
  if A[i]<A[i+1]:
    s = s + c//A[i]
    c = c - c//A[i]*A[i]
  else:
    c = c + s * A[i]
    s = 0

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

print(c)

Solution (Python):
def main():
    N = int( input())
    A = list( map( int, input().split()))
    ans = 1000
    stock = 0
    stock_price = 1000
    for i in range(N-1):
        a = A[i]
        
        if stock > 0 and stock_price <= a:
            ans += stock*a
            stock = 0
        
        if A[i+1] < a:
            pass
        else:
            stock += ans//a
            ans -= ans//a*a
            stock_price = a
        
    if stock_price < A[N-1]:
        ans += stock*A[N-1]
    else:
        ans += stock*stock_price
    print(ans)
            
        
if __name__ == '__main__':
    main()

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

profit = 0 
money = 1000
for i in range(0, len(prices)- 1): 
  dayDiff = prices[i+1] - prices[i]
  if dayDiff > 0:
    stock = money//prices[i]
    profit = prices[i+1]*stock
    money = profit + money - stock*prices[i]
 

print(money)

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

dp=[0 for i in range(N)]
dp[0]=1000

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

print(dp[-1])

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

if __name__=='__main__':
    n = I()
    a = list(IL())
    count = 0
    ans = 1000
    for i in range(len(a)-1):
        if a[i]<a[i+1]:
            tmp = ans//a[i]
            count += tmp
            ans -= tmp*a[i]
        elif a[i]>a[i+1]:
            ans += a[i]*count
            count = 0
    ans += count*a[-1]
    print(ans)
    exit()

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

money = 1000
stock = 0

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

print(money)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mny = 1000
up = True
i = 0
while True:
    if a[i+1] > a[i]:
        cnt = 0
        while a[i + cnt + 1] >= a[i + cnt]:
            cnt += 1
            if i + cnt == n - 1:
                mny += (mny//a[i])*(a[i+cnt] - a[i])
                i += cnt
                break
        if i == n - 1:
            break
        mny += (mny//a[i])*(a[i+cnt] - a[i])
        i += cnt
    else:
        i += 1
    if i == n - 1:
        break
print(mny)

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

now = 1000
stock = 0
down = []

for i in range(1, n):
    if A[i-1] > A[i]:
        down.append(i-1)

if len(down) > 0:
    if down[0] != 0:
        stock = 1000//A[0]
        now %= A[0]

    for i in range(len(down)):
        now += stock*A[down[i]]
        stock = 0
        if (i != len(down)-1 and down[i+1] == down[i]+1) or down[i] == n-2:
            pass
        else:
            a = A[down[i]+1]
            stock = now//a
            now %= a
            
    if down[-1] == n-2:
        pass
    else:
        now += stock*A[n-1]
    
else:
    now += (now//A[0])*(A[-1]-A[0])

print(now)

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

def short_long_decisions(xs):
    return [ *map(lambda t: xs[t[0]] <= t[1], zip(range(len(xs)), xs[1:])), False ]

stocks  = 0
money   = 1000
actions = short_long_decisions(ai)

for i, action in enumerate(actions):
    if action:
        buy = money // ai[i]
        stocks += buy
        money -= buy * ai[i]

    else:
        money += stocks * ai[i]
        stocks = 0

print(money)

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

flag=0
b=[]
c=[]
for i in range(n-1):
    if a[i]<a[i+1]:
        if flag>0:
            pass
        else:
            flag=1
            b.append(a[i])
    else:
        if flag<=0:
            pass
        else:
            flag=-1
            c.append(a[i])
    
    
if flag==1:
    c.append(a[n-1])
    
            
if c==[]:
    print(1000)
else:
    money=1000
    kabu=0
    for i in range(len(b)):
        kabu=money//b[i]
        money=money-kabu*b[i]+kabu*c[i]
        kabu=0
    print(money)

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
m=1000
d,dn=p[:-1],p[1:]
for i,j in zip(d,dn):
  m = m//i*j+m%i if j>i else m
print(m)

Solution (Python):
def main():
    n = int(input())
    A = [int(e) for e in input().split()]

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

    print(hand)


if __name__ == '__main__':
    main()

Solution (Python):
def m():
    N = int(input())
    A = list(map(int, input().split()))
    prev = 0
    cur = 1
    maximum = mini = A[prev]
    stock, money = 0, 1000
    while cur < N:
        while A[prev] <= A[cur]:
            maximum = max(maximum, A[cur])
            prev = cur
            cur += 1
            if cur >= N:
                stock += (money // mini)
                money -= (money // mini) * mini
                money += (stock * maximum)
                return  money

        stock += (money // mini)
        money -= (money // mini) * mini
        money += (stock*maximum)
        stock = 0

        mini = A[cur]
        maximum = A[cur]
        prev = cur
        cur += 1

    return money

print(m())

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
a.insert(0,10000)
a.append(0)
i=0
m=len(a)
while i<m-1:
    if a[i]==a[i+1]:
        del a[i]
        i-=1
    i+=1
    m=len(a)

n=len(a)-2

l=[0]*(n+2)
for i in range(1,n+1):
    if a[i-1]<a[i]>a[i+1]:
        l[i]=1
    elif a[i-1]>a[i]<a[i+1]:
        l[i]=-1
sto=[0,1000]
for i in range(n+2):
    if l[n+1-i]==-1:
        l[n+1-i]=0
        break
    elif l[n+1-i]==1:
        break
for i in range(n+2):
    if l[i]==-1:
        sto[0],sto[1]=divmod(sto[1],a[i])
    if l[i]==1:
        sto[1]+=sto[0]*a[i]
        sto[0]=0
print(sto[1])

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


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


wallet = 1000

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

print(wallet)

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

for i, a in enumerate(A):
  for j in (range(i+1, len(A))):
    if A[j] > a:
      n = cur // a
      cur -= n * a
      kabu += n
      break
    elif A[j] < a:
      cur += a * kabu
      kabu = 0 
      break
    else:
      continue

cur += a * kabu
print(cur)

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

money = 1000


kabu_num = 0

for i in range(N - 1):
    a1 = A[i]
    a2 = A[i + 1]
    if a1 > a2:
        
        if kabu_num != 0:
            money += a1 * kabu_num
            kabu_num = 0
    else:
        
        if money >= a1:
            kabu_num = math.floor(money / a1)
            money -= a1 * kabu_num

money += kabu_num * A[N - 1]

print(money)

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

money = 1000
temp = A[0]
up = None

for i in range(N-1):
  
  if A[i] == A[i+1]:
    continue

  if up is None:
    if temp < A[i+1]:
      up = True
    elif temp > A[i+1]:
      up = False
    continue

  if up:
    if A[i] < A[i+1]:
      continue
    else:
      up = False
      d = money // temp
      money += d * (A[i] - temp)
      temp = A[i+1]
  else:
    if A[i] < A[i+1]:
      up = True
      temp = A[i]
    else:
      temp = A[i+1]

if up:
  d = money // temp
  money += d * (A[-1] - temp)

print(money)

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

g = [1000, 0]

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

print(g[0] + g[1] * A[-1])

Solution (Python):
N = int(input())
A = []
S = 1000
pre =300
now = 0
_min = 200
_max = 100
for _i in input().split():
  now = int(_i)
  if now > pre:
    S += (now - pre) * (S // pre)
  pre = now
else:
  print(S)

Solution (Python):

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

last_value = A[0]
kabu = 0
money = 1000
for n in range(1, N):
    if A[n] > last_value:
        kabu = int(money / last_value)
        money -= last_value * kabu
        money += A[n] * kabu
        last_value = A[n]
    elif A[n] < last_value:
        last_value = A[n]

print(money)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
money=1000
stock=0
updown=[0 for i in range(n)]
flag=False

for i in range(1,n):
  if a[i]>a[i-1]:
    updown[i]=1
  if a[i]<a[i-1]:
    updown[i]=2
if a[0]<a[1]:
  buy=money//a[0]
  money-=buy*a[0]
  stock+=buy
  flag=True
for i in range(1,n):
  if updown[i]==1 and flag==False:
    buy=money//a[i-1]
    money-=buy*a[i-1]
    stock+=buy
    flag=True
  if updown[i]==2 and flag==True:
    sell=stock
    money+=sell*a[i-1]
    stock-=sell
    flag=False
if stock>0:
  money+=stock*a[n-1]
print(money)

Solution (Python):
import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase


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

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""



def inpt():
    return [int(k) for k in input().split()]


def main():
    n=int(input())
    ar=inpt()
    mx=ar[0]
    mn=10000000
    amt=1000
    s=0
    for i in ar:
        if(i<mx):
            s=amt//mn
            amt=amt%mn
            amt+=(s*mx)
            mn=i
            mx=i
        mx=max(mx,i)
        mn=min(mn,i)
    s = amt // mn
    amt = amt % mn
    amt += (s * mx)
    print(amt)


BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np


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

    A = np.int32(A)
    D = np.diff(A)
    if np.all(D <= 0):
        return 1000
    if np.all(D >= 0):
        stock, money = divmod(1000, A[0])
        money = stock * A[-1] + money
        return money

    money = 1000
    s = 0
    while s < N - 1:
        t = s + 1
        if A[t] >= A[s]:
            while t < N and A[t] >= A[t - 1]:
                t += 1
            stock, money = divmod(money, A[s])
            money = stock * A[t - 1] + money
            
            s = t
        else:
            while t < N and A[t] < A[t - 1]:
                t += 1
            
            s = t - 1
    
    return money


print(solve())

Solution (Python):



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

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

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


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

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

Solution (Python):

MOD = 10 ** 9 + 7
INFI = 10**10

import math
from collections import deque
import itertools
import heapq

from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint




def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default




def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    
    n=int(input())
    a=list(map(int,input().split()))
    now=1000
    nokoritemp=1000
    kabu=0
    bos=[0 for i in range(n)] 
    for i in range(n-1):
        if a[i]>a[i+1]:
            bos[i]=1
    bos[n - 1] = 1

 
 



    for i in range(n):
        if bos[i]==1:
            now=now+kabu*a[i]
            kabu=0
        elif bos[i]==0:
            urukabu=0
            kaukabu=0
            for j in range(kabu+1):
                kaukabu=(a[i]*j+now)//a[i]
                temp=j*a[i]+now-((a[i]*j+now)//a[i])*a[i]
                if now>=temp:
                    now=temp
                    urukabu=j
            kabu=kabu+kaukabu-urukabu
    print(now)



if __name__ == "__main__":

    main()

Solution (Python):
days = int(input())
yen = 1000
prices = list(map(int, input().split()))
stocks = 0

for i in range(0, days-1):
  if prices[i] < prices[i+1]:
    stocks += yen // prices[i]
    yen %= prices[i]
  elif prices[i] > prices[i+1]:
    yen += stocks*prices[i]
    stocks = 0


yen += stocks*prices[days-1]

print(yen)

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

mo=1000
ch=0
tu=0
b=sorted(a)
if a==b:
  ka=mo//a[0]
  mo=mo-ka*a[0]
  mo=mo+ka*a[-1]
  
else:
  
  for i in range(1,n):
    if a[i-1]<a[i]:
      ch+=1
    if a[i-1]>a[i] and ch>0:
      y=min(a[tu:i])
      ka=mo//y
      mo=mo-ka*y
      mo=mo+a[i-1]*ka
      tu=i
      ch=0
    if i==n-1:
      if a[i-1]<a[i]:
        y=a[i-1]
        ka=mo//y
        mo=mo-ka*y
        mo=mo+a[i]*ka
  
    
print(mo)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
x, y, z = 1000, 0, 1000
for a in A:
  s1, t1 = divmod(x, a)
  s2, t2 = divmod(z, a)
  s2 += y
  if s1 > s2:
    y, z = s1, t1
  elif s2 > s1:
    y, z = s2, t2
  else:
    y, z = s1, max(t1, t2)
  x = max(x, y*a+z)
ans = x
print(ans)

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
amt=1000
st=0
i=0
while(i<n-1):
    if arr[i]<arr[i+1]:
        mi=arr[i]
        while(i<n-1 and arr[i]<=arr[i+1]):
            i+=1
        st+=amt//mi
        amt-=mi*st
        amt+=arr[i]*st
        st=0
    else:
        while(i<n-1 and arr[i]>=arr[i+1]):
            i+=1
print(amt)

Solution (Python):

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

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

print(cash)

Solution (Python):
n= int(input())
a = list(map(int,input().split()))
s=0
k=0
top=[]
bottom=[]
t=0
ans=1000
ka=0
while a[s]==a[s+1] and s<n-1:
    s+=1
    if s == n - 1:
        break
if s==n-1:
    print(ans)
else:
    if a[s]>a[s+1]:
        k=-1
        t=1
    else:
        k=1

    while s<n-1:
        while a[s]*k <= a[s+1]*k and s<n-1:
            s+=1
            if s==n-1:
                break
        if k ==-1:
            bottom.append(a[s])
        else:
            top.append(a[s])
        k *= -1
        s+=1
    if k == 1:
        top.append(a[-1])
    else:
        bottom.append(a[-1])
    if t==1:
        for i in range(len(top)):
            ka+=ans//bottom[i]
            ans = ans % bottom[i]
            ans += ka*top[i]
            ka = 0
    else:
        for i in range(len(top)):

            if i== 0:
                ka += ans // a[i]
                ans = ans % a[i]
                ans += ka * top[i]
                ka = 0
            else:
                ka+=ans//bottom[i-1]
                ans = ans % bottom[i-1]
                ans += ka*top[i]
                ka = 0
    print(ans)

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

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

a.insert(0,99999)
a.append(-99999)

money = 1000
stocks = 0

prev_state = "decrease"
next_state = "none"

for i in range(1,len(a)-1):
    
    if a[i-1] > a[i]:
        prev_state = "decrease"
    elif a[i-1] < a[i]:
        prev_state = "increase"

    if a[i] > a[i+1]:
        next_state = "decrease"
    elif a[i] < a[i+1]:
        next_state = "increase"
    
    if prev_state == "decrease" and next_state == "increase":
        stocks += money // a[i]
        money %= a[i]
    elif prev_state == "increase" and next_state == "decrease":
        money += a[i]*stocks
        stocks = 0

print(money)

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

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

cnt = 0

M = 1000

min_ind = 0

def kau(M, a, cnt):
    result_cnt = M // a
    result_kingaku = M - (result_cnt * a)
    return result_kingaku, result_cnt
    
def uru(M, a, cnt):
    result_cnt = 0
    result_kingaku = M + a * cnt
    return result_kingaku, result_cnt

operation = "kau"

for i in range(N - 1):
    eval(operation)(M, A[i], cnt)
    
    if operation == "kau":
        if A[i] < A[i + 1]:
            
            M, cnt = eval(operation)(M, A[i], cnt)
            operation = "uru"
    else:
        if A[i] > A[i + 1]:
            
            M, cnt = eval(operation)(M, A[i], cnt)
            operation = "kau"
if cnt:
    M, cnt = uru(M, A[-1], cnt)
    
print(M)

Solution (Python):


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


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


print(pos)

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left, bisect_right 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
A = list(map(int, input().split()))
B = [0]*N 

inc = 0 
val = A[0]
bot = 0
for i, a in enu(A):
    if i == N-1:
        B[i] = 1
    if inc == 0:
        if val < a:
            B[i-1] = -1
            inc = 1
        elif val == a:
            pass
        else:
            B[i-1] = 1
            inc = -1
    elif inc == 1:
        if val < a:
            pass
        elif val == a:
            pass
        else:
            B[i-1] = 1
            inc = -1
    else:
        if val < a:
            B[i-1] = -1
            inc = 1
        elif val == a:
            pass
        else:
            pass
    val = a


money = 1000
stock = 0
for i, a in enu(A):
    if B[i] == -1:
        
        stock += money//A[i]
        money %= A[i]
    elif B[i] == 1:
        
        money += stock*A[i]
        stock = 0 

print(money)

Solution (Python):
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()


    
def solve():
    n = inp()
    a = inlt() + [0]
    q = 0
    w = 1000
    for i in range(len(a) - 1):
        if a[i + 1] >= a[i]:
            q = q + (w // a[i])
            w = w - ((w // a[i]) * a[i])
        else:
            w = w + (q * a[i])
            q = 0
    print(w)
    


 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 

def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)

def counter_elements(a):
    q = dict()
    for i in range(len(a)):
        if a[i] not in q:
            q[a[i]] = 0
        q[a[i]] = q[a[i]] + 1
    return(q)

def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)
 
def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))
 
def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

def transpose(a):
    n,m = len(a),len(a[0])
    b = [[0] * n for i in range(m)]
    for i in range(m): 
        for j in range(n): 
            b[i][j] = a[j][i]
    return(b)


ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()

Solution (Python):
import math


def _run(n, a_list):
    buy_bool = [False] * n
    sell_bool = [False] * n
    for i in range(n - 1):
        today_low = a_list[i] < a_list[i + 1]
        tomorrow_low = a_list[i + 1] < a_list[i]
        
        buy_bool[i] = today_low
        
        sell_bool[i] = tomorrow_low
    sell_bool[n - 1] = True
    money = 1000
    stock = 0
    for i in range(n):
        if sell_bool[i]:
            money += a_list[i] * stock
            stock = 0
        elif buy_bool[i]:
            buy_stock = money // a_list[i]
            money = money - a_list[i] * buy_stock
            stock += buy_stock
    print(money)


def _main():
    N = int(input())
    A_list = list(map(int, input().split()))
    _run(N, A_list)


if __name__ == "__main__":
    _main()

Solution (Python):
from collections import defaultdict

n = int(input())
aa = tuple(map(int, input().split()))

x = {0: 1000}
for i in range(n):
    xx = defaultdict(int)
    for stock, money in x.items():
        xx[0] = max(xx[0], money + stock * aa[i])
        ns = money // aa[i]
        xx[stock + ns] = max(xx[stock + ns], money - ns * aa[i])
    x = xx
print(x[0])

Solution (Python):




import numpy as np

def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(input()))
    return np.array(x)

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

money = 1000
stock = 0

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

if stock > 0:
    money = money + stock*A[N-1]
print(money)

Solution (Python):
def main():
    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]:
            money += stock * A[i]
            stock = 0
        else:
            stock += money // A[i]
            money = money % A[i]
    money += stock * A[N-1]
    print(money)
if __name__ == '__main__':
    main()