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 numpy as np

N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
have_money = 1000
have_stock = 0
have_stock_valuation = 0
call_status = True

def buy_stock(have_money, have_stock, have_stock_valuation, stock_price):
    stock_num = have_money // stock_price
    have_money -= stock_num * stock_price
    have_stock += stock_num
    have_stock_valuation += stock_num * stock_price

    return have_money, have_stock, have_stock_valuation

def sell_stock(have_money, have_stock, have_stock_valuation, stock_price):
    have_money += have_stock * stock_price
    have_stock = 0
    have_stock_valuation = 0

    return have_money, have_stock, have_stock_valuation

for i in range(N):

        if call_status:
            if i == N - 1:
                continue
            if A[i] < A[i+1]:
                have_money, have_stock, have_stock_valuation = buy_stock(have_money, have_stock, have_stock_valuation, A[i])
                call_status = False
            if not call_status:
                if have_stock_valuation / have_stock < A[i]:
                    have_money, have_stock, have_stock_valuation = sell_stock(have_money, have_stock, have_stock_valuation,  A[i])
                    call_status = True
        else:
            if have_stock_valuation / have_stock < A[i]:
                have_money, have_stock, have_stock_valuation = sell_stock(have_money, have_stock, have_stock_valuation,  A[i])
                call_status = True
            if call_status:
                if i == N - 1:
                    continue
                if A[i] < A[i+1] and call_status:
                    have_money, have_stock, have_stock_valuation = buy_stock(have_money, have_stock, have_stock_valuation, A[i])
                    call_status = False
        
print(have_money)

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

Mcashe = 1000
Mkabu = 0

for i in range(len(A) - 1):
    Mcashe += (Mkabu * A[i])
    Mkabu = 0
    if A[i] < A[i+1]:
        Mkabu = Mcashe // A[i]
        Mcashe = Mcashe % A[i] 

Mcashe += (Mkabu * A[-1])
print(Mcashe)

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

Solution (Python):


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    A = list(map(int, input().split()))

    return N, A

def main(N: int, A: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 日数（2 <= N <= 80）
        A (list): i日目の株価（100 <= A_i <= 200）
    """
    
    pos = 1000
    for i in range(N - 1):
        stock = 0
        if A[i] < A[i + 1]:
            stock = pos // A[i]
        pos += (A[i + 1] - A[i]) * stock

    
    print(pos)

if __name__ == "__main__":
    
    N, A = get_input()

    
    main(N, A)

Solution (Python):
 

from collections import defaultdict

import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange



	
def print_case_iterable(case_num, iterable):
	print("Case 

def print_case_number(case_num, iterable):
	print("Case 

def print_iterable(A):
	print (' '.join(A))

def read_int():
	return int(f.readline().strip())
def read_int_array():
	return [int(x) for x in f.readline().strip().split(" ")]
def rns():
	a =  [x for x in f.readline().split(" ")]
	return int(a[0]), a[1].strip()
def read_string():
	return list(f.readline().strip())
def ri():
	return int(f.readline().strip())
def ria():
	return [int(x) for x in f.readline().strip().split(" ")]
def rns():
	a =  [x for x in f.readline().split(" ")]
	return int(a[0]), a[1].strip()
def rs():
	return list(f.readline().strip())
def bi(x):
	return bin(x)[2:]





from collections import deque
import math
NUMBER = 10**9 + 7

def factorial(n) : 
	M = NUMBER
	f = 1
  
	for i in range(1, n + 1):  
		f = (f * i) % M 
						
	return f
def mult(a,b):
	return (a * b) % NUMBER

def minus(a , b):
	return (a - b) % NUMBER

def plus(a , b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		g, y, x = egcd(b % a, a)
		return (g, x - (b // a) * y, y)

def modinv(a):
	m = NUMBER
	g, x, y = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m
def choose(n,k):
	if n < k:
		assert false
	return  mult(factorial(n), modinv(mult(factorial(k),factorial(n-k)))) % NUMBER
from collections import deque, defaultdict 
import heapq


from types import GeneratorType
def bootstrap(f, stack=[]):
	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to

	return wrappedfunc


def dfs(g, timeIn, timeOut,depths,parents): 
	
	cnt = 0
	
	stack = [[1,0,0,0]]
	while stack:
		v,neig_i,parent,depth = stack[-1]
		parents[v] = parent
		depths[v] = depth
		
		if neig_i == 0:
			timeIn[v] = cnt    
			cnt+=1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i+=1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u,0,v,depth+1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1
  



cnt = 0
@bootstrap
def dfs(v,adj,timeIn, timeOut,depths,parents,parent=0,depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt+=1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u,adj,timeIn,timeOut,depths,parents,v,depth+1)
	timeOut[v] = cnt
	cnt+=1
	yield 

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

def lcm(a,b): 
	return (a*b) / gcd(a,b) 
def get_num_2_5(n):
	twos = 0
	fives = 0
	while n>0 and n%2 == 0:
		n//=2
		twos+=1
	while n>0 and n%5 == 0:
		n//=5
		fives+=1
	return (twos,fives)
def shift(a,i,num):
	for _ in range(num):
		a[i],a[i+1],a[i+2] = a[i+2],a[i],a[i+1]

def equal(x,y):
	return abs(x-y) <= 1e-9


def getAngle(a, b, c):
	ang = math.degrees(math.atan2(c[1]-b[1], c[0]-b[0]) - math.atan2(a[1]-b[1], a[0]-b[0]))
	return ang + 360 if ang < 0 else ang
def getLength(a,b):
	return math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)


from heapq import heapify, heappush, heappop

def bfs(adj):
	s = set()
	d = defaultdict(set)
	
	q = deque([])
	s.add(0)
	d[0].add(0)
	q.append((0,0))
	while len(q) > 0:
		v,depth = q.popleft()
		for u in adj[v]:
			if u not in s:
				s.add(u)
				d[depth+1].add(u)
				q.append((u,depth+1))
		
	return d



def isSubsetSum(arr, n, summ): 
	  
	
	
	
	subarr =([[False for i in range(summ + 1)]  
			for i in range(n + 1)]) 
	  
	
	for i in range(n + 1): 
		subarr[i][0] = True
		  
	
	
	for i in range(1, summ + 1): 
		 subarr[0][i]= False
			  
	
	for i in range(1, n + 1): 
		for j in range(1, summ + 1): 
			if j<arr[i-1]: 
				subarr[i][j] = subarr[i-1][j] 
			if j>= arr[i-1]: 
				subarr[i][j] = (subarr[i-1][j] or 
								subarr[i - 1][j-arr[i-1]]) 
	  
	
	
	
	
	
	return subarr[n][summ] 

@bootstrap
def dfs(v,adj,vis,black):
	vis[v] = 1
	for u in adj[v]:
		if vis[u]==2:
			continue
		if vis[u] == 1:
			black.add((v,u)) 
			continue
		yield dfs(u,adj,vis,black)
	vis[v] = 2
	yield


def solution(a,n):
	yen = 1000
	stock = 0
	mx = 0
	for i in range(n-1):
		if a[i] < a[i+1] and yen:
			stock += yen // a[i]
			yen = yen % a[i]
		elif a[i] > a[i+1] and stock:
			yen += stock * a[i]
			stock = 0

	if stock > 0:
		yen += stock*a[n-1]
	return yen
def main():
	T = 1
	
	for i in range(T):
		n = ri()
		
		a = ria()
		
		
		
		
		
		
		
		
		

		x = solution(a,n)

		
		if 'xrange' not in dir(__builtins__):
			print(x) 
		else:
			print >>output,str(x)
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()

if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()




if __name__ == '__main__':
	main()

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

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
money=1000
i=0
while i<N-1:
    k=1
    while A[i]==A[i+k]:
        if i+k==N-1:
            i=i+k
            break
        else:
            k+=1
    if i==N-1:
        break
    if A[i+k]>A[i]:
        kabu=money//A[i]
        money-=kabu*A[i]
        money+=kabu*A[i+k]
        i=i+k
    elif A[i+k]<A[i]:
        i=i+k

print(money)

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

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

read = sys.stdin.buffer.read

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

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

Solution (Python):

import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N_all = int(readline())
A_all = list(map(int,readline().split()))
A = [A_all[0]]
for i in range(1,N_all):
    if A[-1] != A_all[i]:
        A.append(A_all[i])
N = len(A) 
if N == 1:
    print(1000)
    sys.exit()
money = 1000
kabu = 0 
for i in range(N):
    if i == 0:
        if A[i] > A[i+1]:
            continue
        else:
        	kabu = money // A[i]
        	money -= kabu * A[i]
    elif i == N-1:
        money += A[i]*kabu
        kabu = 0
    else:
        if A[i-1] < A[i] and A[i] > A[i+1]:
            money += A[i]*kabu
            kabu = 0
        if A[i-1] > A[i] and 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()))
now = 1000
for i in range(n-1):
    if A[i] < A[i+1]:
        stocks = now // A[i]
        now += (A[i+1] - A[i])*stocks
print(now)

Solution (Python):
n=int(input())
a=[int(j) for j in input().split()]
l=a[:2]
if a[0]<=a[1]:b=True
else:b=False
for i,j in zip(a,a[1:]):
    if i<j:
        if b:
            l[-1]=j
        else:
            l.append(j)
            b=True
    elif i>j:
        if b:
            l.append(j)
            b=False
        else:
            l[-1]=j
ans=1000
for i,j in zip(l,l[1:]):
    if i<j:
        ans=(ans//i)*j+ans%i
print(ans)

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]:
        money = (money // a[i-1]) * a[i] + money % a[i-1]
    else:
        pass

print(money)

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

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

state_of_up_or_down = False
money = 1000
min_price = a[0]
max_price = a[0]
for i in range(1, n):
    if a[i] > a[i - 1]:
        
        max_price = a[i]
        state_of_up_or_down = True
        if i == n - 1:
            money = (money // min_price) * max_price + money % min_price
    elif a[i] == a[i - 1]:
        if i == n - 1:
            money = (money // min_price) * max_price + money % min_price        
        pass
    else:
        if state_of_up_or_down:
            money = (money // min_price) * max_price + money % min_price
            state_of_up_or_down = False
        
        min_price = a[i]
    
print(money)

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

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

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

dp=[[0]*2 for i in range(n)]
dk=[[0]*2 for i in range(n)]


dp[0][0]=1000
dk[0][0]=0

dp[0][1]=1000%a[0]
dk[0][1]=1000//a[0]

for k in range(1,n):
    dp[k][0]=max(dp[k-1][0],dp[k-1][1]+dk[k-1][1]*a[k])
    dk[k][0]=0

    dpk1=dp[k-1][0]%a[k]
    dkk1=dp[k-1][0]//a[k]
    v1=dk[k-1][1]*a[k]+dp[k-1][1]
    v2=dkk1*a[k]+dpk1

    if v2>v1:
        dk[k][1]=dkk1
        dp[k][1]=dpk1
    else:
        dp[k][1]=dp[k-1][1]
        dk[k][1]=dk[k-1][1]

print(dp[n-1][0])

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

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

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

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

dp = [0 for _ in range(N+1)]
dp[0] = 1000
for i in range(1, N):
    dp[i] = dp[i-1]
    for j in range(0, i):
        stock = dp[j] // A[j]
        money = dp[j] % A[j] + A[i] * stock
        
        dp[i] = max(dp[i], money)

print(dp[N-1])

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

stock = 0
rest  = 0
value = 1000

for i in range(1, n + 1):
    value = max(value, stock * a[i - 1] + rest)
    stock = value // a[i - 1]
    rest = value % a[i - 1]
print(value)

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

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

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

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

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

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

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

for i in range(N-1) :
    bk = m//A[i]
    bm = m - A[i] * bk
    am = bm + bk*A[i+1]
    ak = 0
    if m <= am :
        m = am
        k = ak
    else :
        pass

print(m)

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

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

Solution (Python):


n=int(input())

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


l = [[a[0]]]
for i in range(n-1):
    if a[i] > a[i+1]:
        if a[i] != l[-1][0]:
            l[-1] += [a[i]]
        else:
            del l[-1]
        l += [[a[i+1]]]
if a[-1] != l[-1][0]:
    l[-1] += [a[-1]]
else:
    del l[-1]

m = 1000
for i in range(len(l)):
    k = m // l[i][0]
    m %= l[i][0]
    m += k * l[i][1]
print(m)

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

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

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

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

B = []
for i in range(n-1):
    B.append(A[i+1]/A[i])

s = 1000
for i in range(n-1):
    if B[i] > 1.0:
        val = s // A[i]
        s = s - A[i] * val
        s = s + A[i+1] * val
print(s)

Solution (Python):
def solve():
  ans = 0
  N = int(input())
  A = [float('inf')]+list(map(int, input().split()))+[-float('inf')]
  UD = [0]*(N+1)
  for i in range(N+1):
    if A[i]>A[i+1]:
      UD[i] = -1
    elif A[i]<A[i+1]:
      UD[i] = 1
    else:
      UD[i] = UD[i-1]
  UD2 = [0]*N
  for i in range(N):
    if UD[i]>UD[i+1]:
      UD2[i] = -1
    elif UD[i]<UD[i+1]:
      UD2[i] = 1
  stock = 0
  money = 1000
  if -1 not in UD2:
    ind = -1
  else:
    ind = (N-1)-UD2[::-1].index(-1)
  for i in range(N):
    if UD2[i]==-1:
      money += A[i+1]*stock
      stock = 0
      if i==ind:
        break
    elif UD2[i]==1:
      stock,money = divmod(money,A[i+1])
  return money
print(solve())

Solution (Python):
n = int(input())
A = [*map(int, input().split())] + [0]
yen = 1000
kabu_yen = kabu_n = 0
for i in range(n):
    if A[i] < A[i+1]: 
        m = yen // A[i]
        cost = m * A[i]
        yen -= cost
        kabu_yen += cost
        kabu_n += m
    elif A[i] > A[i+1]: 
        yen += kabu_n * A[i]
        kabu_yen = kabu_n = 0
print(yen)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    dp = [0 for _ in range(N + 1)]
    dp[0] = 1000
    for i in range(N):
        dp[i + 1] = max(dp[i], dp[i - 1])
        for j in range(0, i):
            a = dp[j] // A[j] * A[i] + dp[j] % A[j]
            dp[i + 1] = max(dp[i + 1], a)
    print(dp[N])


def main():
    
    
    solve()


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N, *A = map(int, open(0).read().split())
    money, left, right = 1000, 0, 0
    while right < N:
        if A[right] > A[left]:
            stock, money = divmod(money, A[left])
            money += A[right] * stock
        left = right
        right += 1
    print(money)


if __name__ == "__main__":
    main()

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

    inc_list = [1 if (A[i] < A[i+1]) else 0 for i in range(n-1)]
    for i in range(n):
        if(i < n-1 and inc_list[i] == 1):
            if(stock == 0):
                stock = int(account / A[i])
                account %= A[i]
        else:
            if(stock != 0):
                account += stock * A[i]
                stock = 0
    print(account)

if __name__ == "__main__":
    resolve()

Solution (Python):
n = int(input())
A = [*map(int, input().split())] + [0]
yen = 1000
kabu_yen = kabu_n = 0
for i in range(1,n+1):
    if A[i-1] < A[i]: 
        m = yen // A[i-1]
        cost = m * A[i-1]
        yen -= cost
        kabu_yen += cost
        kabu_n += m
    elif A[i-1] > A[i]: 
        yen += kabu_n * A[i-1]
        kabu_yen = kabu_n = 0
print(yen)

Solution (Python):
n = int(input())
A = [*map(int, input().split())] + [0]
yen = 1000
kabu_yen = kabu_n = 0
for i in range(1,n+1):
    if A[i-1] < A[i]: 
        m = yen // A[i-1]
        cost = m * A[i-1]
        yen -= cost
        kabu_yen += cost
        kabu_n += m
    elif A[i-1] > A[i]: 
        yen += A[i-1] * kabu_n
        kabu_yen = 0
        kabu_n = 0
print(yen)

Solution (Python):
n, *a = map(int, open(0).read().split())
m = 1000
for a, b in zip(a, a[1:]):
  if a < b:m = m // a * b + m % a
print(m)

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

for i in range(n-1):
    if (lst_1[i]<lst_1[i+1]):
        k=ans//lst_1[i]
        ans+=(lst_1[i+1]-lst_1[i])*k
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
money  = 1000
stock = 0
min_price = a[0]
max_price = a[0]
is_first_time_of_drop = False
for i in range(1, n):
    if a[i] > max_price:
        max_price = a[i]
        is_first_time_of_drop = True
        if i == n - 1:
            money = (money // min_price) * max_price + money % min_price
    elif a[i] == max_price:
        if i == n - 1:
            money = (money // min_price) * max_price + money % min_price
        continue
    else:
        if is_first_time_of_drop:
            money = (money // min_price) * max_price + money % min_price
            min_price = a[i]
            max_price = a[i]
            is_first_time_of_drop = False
        else:
            if a[i] < min_price:
                min_price = a[i]
                max_price = a[i]
            elif a[i] == min_price:
                continue
            else:
                is_first_time_of_drop = True
print(money)

Solution (Python):
a = int(input())
b = list(map(int, input().split()))
d = 0
c = 1000

while d+1 < a:
   if b[d+1] > b[d]:
       c = c - (b[d] * (c//b[d])) + ((c//b[d]) * (b[d+1]))
   else: pass
   d += 1

print(c)

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

money = 1000
stack = 0

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

Solution (Python):
def laod_to_mill():
    days = int(input())
    prices = tuple(map(int, input().split()))

    total = 1000
    ks = 0

    for d in range(days):
        if d == days - 1:
            total += ks * prices[d]
            break

        if prices[d] < prices[d + 1]:
            buy = total // prices[d]
            total -= buy * prices[d]
            ks += buy

        elif prices[d] > prices[d + 1]:
            total += ks * prices[d]
            ks = 0

    print(total)

def main():
    laod_to_mill()


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n=int(input())
    A=tuple(map(int,input().split()))
    ans=1000
    num=0
    for i in range(n-1):
        ans+=num*A[i]
        num=0
        if A[i]<A[i+1]:
            num=ans//A[i]
            ans%=A[i]
    ans+=num*A[-1]
    print(ans)
    
if __name__=='__main__':
    main()

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

m=1000
for i in range(n-1):
    if B[i]<B[i+1]:
        m=(m//B[i])*B[i+1]+m%B[i]
print(m)

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

dp = [1000]

for i in range(1,n):
	maxdp = max(dp)
	kabu = max([ m%a[j] + (a[i]*(m // a[j]) ) for j, m in enumerate(dp) ] )
	dp.append( max( maxdp, kabu ) ) 
print(dp[-1])

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

ans = 1000
for i in range(n - 1):
    x = a[i]
    y = a[i + 1]
    if x < y:
        k = ans // x
        ans %= x
        ans += k * y

print(ans)

Solution (Python):


n=int(input())

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


l = [[a[0]]]
for i in range(n-1):
    if a[i] > a[i+1]:
        if a[i] != l[-1][0]:
            l[-1] += [a[i]]
        else:
            del l[-1]
        l += [[a[i+1]]]
if a[-1] != l[-1][0]:
    l[-1] += [a[-1]]
else:
    del l[-1]

m = 1000
for i in range(len(l)):
    k = m // l[i][0]
    m %= l[i][0]
    m += k * l[i][1]
print(m)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
CurrentMoney = 1000
for i in range(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):
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    _A=list(mi())
    A = []

    for a in _A:
        if len(A) > 0 and A[-1] == a: continue
        A.append(a)
    
    N = len(A)
    bottoms = []
    
    if N < 2:
        print(1000)
        exit()

    if A[0] < A[1]:
        bottoms.append(0)

    for i in range(N-1):
        if not i+2 < len(A): continue
        
        if A[i] > A[i+1] and A[i+1] < A[i+2]:
            bottoms.append(i+1)
    
    money = 1000
    kabu = 0
    
    for bi in bottoms:
        bottom = A[bi]
        i = bi
        while i < N-1 and A[i] < A[i+1]:
            i += 1
        
        top = A[i]

        
        
        kabu += money//bottom
        money -= money//bottom * bottom
        
        money += kabu * top
        kabu = 0
        
    
    print(money)

    

if __name__ == "__main__":
    main()

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

print(money)

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

money = 1000
stock = 0

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

print(money)

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

money = 1000
stock = 0
cnt = 0
buy = True    

while True:
    if buy == False:
        while True:
            if cnt >= N-1:
                break
            if A[cnt+1] < A[cnt]:
                break
            cnt += 1
        if cnt >= N-1:
            break
        buy = True
        money += (stock*A[cnt])
        stock = 0
    else:
        while True:
            if cnt >= N-1:
                break
            if A[cnt+1] > A[cnt]:
                break
            cnt += 1
        if cnt >= N-1:
            break
        buy = False
        stock += (money//A[cnt])
        money %= A[cnt]
    if cnt >= N-1:
        break
money += (stock*A[-1])
print(max(money,1000))

Solution (Python):
N = int(input())
valls = list(map(int,input().split()))
 
money = 1000
have = 0

for i in range(N-1):
    if valls[i] < valls[i+1]:   
        have += money // valls[i]
        money = money % valls[i]
    elif valls[i] > valls[i+1]:
        money = money + have*valls[i]
        have = 0

money = money + have*valls[-1]
print(money)

Solution (Python):
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import sys

n=int(input())
A=INPUT()
money=1000
for i in range(n-1):
    stocks=0
    if A[i]<A[i+1]:
        stocks=money//A[i]
    money+=(A[i+1]-A[i])*stocks
print(money)

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

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

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

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

print(m)

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

print(cash)

Solution (Python):
from itertools import groupby
n = int(input())
A = list(map(int, input().split()))

A = groupby(A)
G = []
for i, _ in A:
    G.append(i)

p = 1000
for i in range(len(G)-1):
    if G[i] < G[i+1]:
        tmp1 = p // G[i]
        tmp2 = p % G[i]
        p = tmp1 * G[i+1] + tmp2

print(p)

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

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

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

syozi = 1000
kabu = 0

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

syozi += A[-1] * kabu

print(syozi)