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.



Sample input:
7
100 130 130 130 115 115 150


Sample output:
1685

Submission status: Wrong Answer

Solution code:
N= int(input())
A = list(map(int,input().split()))
A.insert(0,A[0])
A.append(0)
 
money = 1000
previous_tendency = "remain"
current_tendency = "remain"
count = 1

print(A)

for n in range(1,len(A)-1):
    if A[n] < A[n+1]:
        current_tendency = "up"
    elif A[n] > A[n+1]:
        current_tendency = "down"
    else:
        current_tendency = "remain"
        
    if previous_tendency != "down" and current_tendency != "up":
        #print(n,"chance",max(A[count:n+1]),min(A[count:n+1]),previous_tendency, current_tendency)
        money += (money//min(A[count:n+1]))*(max(A[count:n+1])-min(A[count:n+1]))
        #print(money)
        count = n + 1
    #print(A[n],max_price,min_price,previous_tendency,current_tendency)
    previous_tendency = current_tendency
print(money)

Submission status: Wrong Answer

Solution code:
N= int(input())
A = list(map(int,input().split()))
A.insert(0,A[0])
A.append(0)
 
money = 1000
previous_tendency = "remain"
current_tendency = "remain"
count = 1

print(A)

for n in range(1,len(A)-1):
    if A[n] < A[n+1]:
        current_tendency = "up"
    elif A[n] > A[n+1]:
        current_tendency = "down"
    else:
        current_tendency = "remain"
        
    if previous_tendency != "down" and current_tendency != "up":
        print(n,"chance",max(A[count:n+1]),min(A[count:n+1]),previous_tendency, current_tendency)
        money += (money//min(A[count:n+1]))*(max(A[count:n+1])-min(A[count:n+1]))
        #print(money)
        count = n + 1
    #print(A[n],max_price,min_price,previous_tendency,current_tendency)
    previous_tendency = current_tendency
print(money)

Submission status: Wrong Answer

Solution code:
N= int(input())
A = list(map(int,input().split()))
A.insert(0,A[0])
A.append(A[-1])
 
money = 1000
previous_tendency = "remain"
current_tendency = "remain"
count = 0


for n in range(1,len(A)-1):
    if A[n] < A[n+1]:
        current_tendency = "up"
    elif A[n] > A[n+1]:
        current_tendency = "down"
    else:
        current_tendency = "remain"
        
    if previous_tendency != "down" and current_tendency != "up":
        #print(n,"chance",max(A[count:n+1]),min(A[count:n+1]),previous_tendency, current_tendency)
        money += (money//min(A[count:n+1]))*(max(A[count:n+1])-min(A[count:n+1]))
        #print(money)
        count = n + 1
    #print(A[n],max_price,min_price,previous_tendency,current_tendency)
    if current_tendency != "none":
        previous_tendency = current_tendency
print(money)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i in range(n-1):
    if(a[i] < a[i+1]):
        #if(b[i-1] < 1):
        b[i] = 1
        #else:
        #    b[i] = 2
    if(a[i] > a[i+1]):
        #if(b[i-1] > -1):
        b[i] = -1
        #else:
        #    b[i] = -2
    #else:
        #if(b[i-1] > 0):
    #       b[i] = 2
     #   else:
      #      b[i] = -2
b[-1] = -1
print(b)
h = [1000,0]
for i in range(n):
    if(b[i] == 1):
        h[1] += h[0]//a[i]
        h[0] %= a[i]
    elif(b[i] == -1):
        h[0] += h[1]*a[i]
        h[1] *= 0
    #print(h)
print(h[0])

Submission status: Wrong Answer

Solution code:
N= int(input())
A = list(map(int,input().split()))
A.insert(0,A[0])
A.append(A[-1])
 
money = 1000
previous_tendency = "none"
current_tendency = "none"
count = 0


for n in range(1,len(A)-1):
    if A[n] < A[n+1]:
        current_tendency = "up"
    elif A[n] > A[n+1]:
        current_tendency = "down"
    else:
        current_tendency = "none"
        
    if previous_tendency != "down" and current_tendency != "up":
        #print(n,"chance",max(A[count:n+1]),min(A[count:n+1]),previous_tendency, current_tendency)
        money += (money//min(A[count:n+1]))*(max(A[count:n+1])-min(A[count:n+1]))
        #print(money)
        count = n
    #print(A[n],max_price,min_price,previous_tendency,current_tendency)
    if current_tendency != "none":
        previous_tendency = current_tendency
print(money)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()
sign = [-1]*n

for i in range(1,n):
    if a[i] > a[i - 1]:
        sign[i] = 1
    elif a[i] < a[i - 1]:
        sign[i] = -1
    else:
        sign[i] = 0
pre = -1
for i in range(1,n):
    if sign[i] == 0:
        continue
    if sign[i] == pre:
        sign[i] = pre
    pre = sign[i]


money = 1000
stock = 0
for i in range(n):
    if sign[i] == 0 or (i != n-1 and sign[i] == sign[i + 1]):
        continue

    if sign[i] == 1:
        #売る
        money += a[i] * stock
        stock = 0
    elif sign[i] == -1:
        flg = False
        if [j for j in sign[i:] if j == 1]:
            flg = True
        #買う
        if flg == True:
            buy =  money // a[i]
            stock += buy
            money -= a[i] * buy
print(money)

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
n= int(input())
arr = [int(x) for x in input().strip().split()]

@lru_cache(None)
def helper(i, mon, stk):
    if i==len(arr):
        return mon
    
    ans = helper(i+1, mon, stk)
    buy = 1
    while True:
        if arr[i]*buy<=mon:
            ans = max(ans, helper(i+1, mon - arr[i]*buy, stk+buy))
        else:
            break
        
        buy += 1
    
    for s in range(1, stk+1):
        ans = max(ans, helper(i+1, mon+arr[i]*s, stk-s))
    
    return ans

Submission status: Wrong Answer

Solution code:
N = int(input())

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

dp = [0] * 1000
dp[0] = 1000

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

print(dp[-1])

Submission status: Wrong Answer

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

bs = [0]*n
bs1 = [0]*n

for i in range(1, n):
    if a[i-1] < a[i]:
        bs[i] = bs[i-1] + 1
    elif a[i-1] == a[i]:
        bs[i] = bs[i-1]
    else:
        bs[i] = bs[i-1] - 1

start = None
end = None
#どこで最初に買うか
for i in range(1, n):
    if bs[i] > bs[i-1]:
        start = i-1
        break

#どこで最後に売るか
for i in range(n-1, 0, -1):
    if bs[i-1] < bs[i]:
        end = i+1
        break

if start is not None:
    bs1[start] = -1
    bs1[end-1] = 1
    for i in range(start+1, end-2):
        if bs[i]-bs[i-1] > bs[i+1]-bs[i]:
            bs1[i] = 1 #売る
        elif bs[i]-bs[i-1] == bs[i+1]-bs[i]:
            bs1[i] = 0 #何もしない
        else:
            bs1[i] = -1 #買う

if start is None:
    start = 0
if end is None:
    end = n
money = 1000
stock = 0
for i in range(start, end):
    if bs1[i] == 1:
        money += stock * a[i]
        stock = 0
    elif bs1[i] == -1:
        stock = money // a[i]
        money = money % a[i]
    

print(money)

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
list_N = [0]
money = 1000
for i in range(1, n):
    if list_A[i-1] < list_A[i]:
        list_N.append(1)
    else:
        list_N.append(0)


for k in range(1, n):
    if list_N[k-1] == 0 and list_N[k] == 1:
        roll = money // list_A[k-1]
        money = money % list_A[k-1]
        money += list_A[k]*roll


print(money)

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
list_N = [0]
money = 1000
for i in range(1, n):
    if list_A[i-1] < list_A[i]:
        list_N.append(1)
    else:
        list_N.append(0)


k = 0
while True:
    if k == n-1:
        break
    k += 1
    if list_N[k-1] == 0 and list_N[k] == 1:
        l = k-1
        roll = money // list_A[l]
        money = money % list_A[l]
        money += list_A[k]*roll

print(money)

Submission status: Wrong Answer

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


# dp[i]: 
# i日目時点で，
# あらゆる売買の組み合わせを考慮したときの
# 最適な(最大化された)所持金の値
dp = [0] * N

dp[0] = 1000 # 初日は1000円が最適
for i in range(1, N):
  
  for j in range(0, i):
    # j日目に買える最大株数vは？
    v = int(dp[j] / A[j])
    
    # j日目にv株買って(マイナスv*A[j]円)，
    # i日目までガチホして，
    # i日目の株価で全部売った時(プラスv*A[i]円)，
    # i日目の所持金wはいくらになる？
    w = dp[j] - v*A[j] + v*A[i]
    
    print(v, w)
    
    dp[i] = max(dp[i-1], w)
    
print(dp)

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
list_N = [0]
money = 1000
for i in range(1, n):
    if list_A[i-1] < list_A[i]:
        list_N.append(1)
    else:
        list_N.append(0)


k = 0
while True:
    if k == n-1:
        break
    k += 1
    if list_N[k-1] == 0 and list_N[k] == 1:
        l = k-1
        while True:
            if k+1 == n or list_N[k] == 0:
                break
            k += 1
        roll = money // list_A[l]
        money = money % list_A[l]
        money += list_A[k]*roll

print(money)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()

money = 1000
stock = 0
pivot = []
upflag = 0
dnflag = 1

if(int(a[1]) - int(a[0]) > 0): # initial
    stock = int(money // (int(a[0])))
    money = int(money % (int(a[0])))
    upflag = 1
    dnflag = 0

for i in range(n-2): # i=0,1,,,,n-3 (for n=7, n-3=4)
    if(int(a[i+1]) == int(a[i])):
        if((int(a[i+2]) - int(a[i+1]) < 0) and upflag == 1): # i+1 is local max so that to sell stock
            money = money + stock * (int(a[i+1]))
            stock = 0
            upflag = 1
            dnflag = 0
        elif((int(a[i+2]) - int(a[i+1]) > 0) and dnflag == 1): # i+1 is local min so that to sell stock
            stock = int(money // (int(a[i+1])))
            money = int(money % (int(a[i+1])))
            upflag = 0
            dnflag = 1

    elif(int(a[i+1]) - int(a[i]) > 0):
        upflag = 1
        if(int(a[i+2]) - int(a[i+1]) < 0): # i+1 is local max so that to sell stock
            money = money + stock * (int(a[i+1]))
            stock = 0
            upflag = 0

    elif(int(a[i+1]) - int(a[i]) < 0):
        dnflag = 1
        if(int(a[i+2]) - int(a[i+1]) > 0): # i+1 is local min so that to buy stock
            stock = int(money // (int(a[i+1])))
            money = int(money % (int(a[i+1])))
            dnflag = 0

if(int(a[n-1]) - int(a[n-2]) > 0): # sell @ final
    money = money + stock * (int(a[n-1]))
    stock = 0

print(money)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()

money = 1000
stock = 0
upflag = 0
dnflag = 0

if(int(a[1]) - int(a[0]) > 0): # initial
    stock = int(money // (int(a[0])))
    money = int(money % (int(a[0])))
    upflag = 1

for i in range(n-2): # i=0,1,,,,n-3 (for n=7, n-3=4)
    if(int(a[i+1]) == int(a[i])):
        if((int(a[i+2]) - int(a[i+1]) < 0) and upflag == 1): # i+1 is local max so that to sell stock
            money = money + stock * (int(a[i+1]))
            stock = 0
            upflag = 1
            dnflag = 0
        elif((int(a[i+2]) - int(a[i+1]) > 0) and dnflag == 1): # i+1 is local min so that to sell stock
            stock = int(money // (int(a[i+1])))
            money = int(money % (int(a[i+1])))
            upflag = 0
            dnflag = 1

    elif(int(a[i+1]) - int(a[i]) > 0):
        upflag = 1
        if(int(a[i+2]) - int(a[i+1]) < 0): # i+1 is local max so that to sell stock
            money = money + stock * (int(a[i+1]))
            stock = 0
            upflag = 0

    elif(int(a[i+1]) - int(a[i]) < 0):
        dnflag = 1
        if(int(a[i+2]) - int(a[i+1]) > 0): # i+1 is local min so that to buy stock
            stock = int(money // (int(a[i+1])))
            money = int(money % (int(a[i+1])))
            dnflag = 0

if(int(a[n-1]) - int(a[n-2]) > 0): # sell @ final
    money = money + stock * (int(a[n-1]))
    stock = 0

print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = {
        'stack':0,
        'money':1000
    }

for i in range(N):
    if i == N-1:
        if M['stack'] != 0:
            M['money'] += A[i] * M['stack']
        break
    if A[i] < A[i + 1]:
        # 株購入
        if M['money'] != 0:
            M['stack'] = M['money'] // A[i]
            M['money'] %= A[i]
    
    elif A[i] > A[i + 1]:
        # 株売却
        M['money'] += A[i] * M['stack']
        if M['stack'] != 0:
            M['stack'] = 0
print(M['money'])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

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

m = max(a)
ans = 1000
stock = 0 
for i in range(n):
    if a[i] == m:  
        ans += stock*a[i]
        stock = 0 
        break

    if i == 0: # buy
        stock += ans//a[i]
        ans -= ans//a[i] * a[i]
    
    else:
        # 安くなっているとき、買える分は買う
        if a[i] < a[i-1]:
            stock += ans//a[i]
            ans -= ans//a[i] * a[i]
        # 高くなっているとき、売れる分は売る
        elif a[i] > a[i-1]:
            ans += stock*a[i]
            stock = 0 

    # print('ans =', ans)
    # print('stock =', stock)

print(ans)

Submission status: Wrong Answer

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

kane=1000
kabu =0

for i in range(n-1):
    if a[i]<a[i+1]:
        kabu,kane=divmod(kane,a[i])
    elif a[i]>a[i+1]:
        kane+=kabu*a[i]
    else:
        continue
print(kane+kabu*a[n-1])

Submission status: Wrong Answer

Solution code:
import sys

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

pre = 300
money = 1000
num = 0

for i, a in enumerate(A):
    if a < pre and not all([a > aa for aa in A[i + 1:]]):
        pre = a
        num = money // a
        money %= a
    elif a > pre:
        pre = a
        money += num * a
        num = 0

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

Submission status: Wrong Answer

Solution code:
N = int(input()) #1行目のNを取得する
Input = list(map(int, input().split()))

Stock = 0
Money = 1000
  
for i in range(N):
  j = i + 1
  
  if j == 1:
    if Input[i] < Input[i+1]:
      Stock = Money // Input[i]
      Money = Money % Input[i]
     
    continue
   
  if j == N:
    if Stock != 0:
      Money = Money + Stock * Input[i]
    continue
  
  if Input[i - 1] < Input[i]:
    Money = Money + Stock * Input[i]
  
  if Input[i + 1] > Input[i]:
    Stock = Money // Input[i]
    Money = Money % Input[i]

    
print(Money)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0]+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)
'''

dp = [0] * (n + 10)
dp[1] = 1000
for i in range(2, n + 1):
    dp[i] = dp[i - 1]
    for j in range(1, i - 1):
        x = dp[j] // a[j]
        y = dp[j] + (a[i] - a[j]) * x
        dp[i] = max(dp[i], y)

ans = dp[n]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] + 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)
'''

dp = [0] * (n + 10)
dp[1] = 1000
for i in range(2, n + 1):
    dp[i] = dp[i - 1]
    for j in range(1, i - 2):
        x = dp[j] // a[j]
        y = dp[j] + (a[i] - a[j]) * x
        dp[i] = max(dp[i], y)

ans = dp[n]
print(ans)

Submission status: Wrong Answer

Solution code:
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)
'''

dp = [0] * (n + 10)
dp[0] = 1000
for i in range(1, n):
    dp[i] = dp[i - 1]
    for j in range(i - 1):
        x = dp[j] // a[j]
        y = dp[j] + (a[i] - a[j]) * x
        dp[i] = max(dp[i], y)

ans = dp[n - 1]
print(ans)

Submission status: Wrong Answer

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

prev = a[0]
mon = 1000
stc = 0

for i in range(1, n):
    #print(prev)
    if prev < a[i]:
        stc = mon // prev
        mon = mon - stc * prev
        #print("stc = {} mon = {}" .format(stc, mon))
    elif prev >= a [i]:
        mon = mon + stc * prev
        stc = 0
        #print("stc = {} mon = {}" .format(stc, mon))
    prev = a[i]

mon = mon + stc * a[n - 1]

print(mon)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
money=1000
stock=0
flag=0
price=0
for i in range(n):
  if i==0:
    if A[i]==max(A):
      flag=1
    else:
      stock=money//A[i]
      money-=stock*A[i]
      price=A[i]
  else:
    if A[i]>price and stock>0 and flag==0:
      money+=stock*A[i]
      stock=0
      price=A[i]
      if price==max(A[i:n+1]):
        flag=1
    elif A[i]<price and stock==0 and flag==0:
      stock=money//A[i]
      money-=stock*A[i]
      price=A[i]
print(money)

Submission status: Wrong Answer

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

prev = a[0]
mon = 1000
stc = 0

for i in range(1, n):
    #print(prev)
    if prev < a[i]:
        stc = mon // prev
        mon = mon - stc * prev
        #print("stc = {} mon = {}" .format(stc, mon))
    elif prev > a [i]:
        mon = mon + stc * prev
        stc = 0
        #print("stc = {} mon = {}" .format(stc, mon))
    prev = a[i]

mon = mon + stc * a[n - 1]

print(mon)

Submission status: Wrong Answer

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

prev = a[0]
mon = 1000
stc = 0

for i in range(1, n):
    #print(prev)
    if prev < a[i]:
        stc = mon // prev
        mon = mon - stc * prev
        #print("stc = {} mon = {}" .format(stc, mon))
    elif prev > a [i]:
        mon = mon + stc * prev
        stc = 0
        #print("stc = {} mon = {}" .format(stc, mon))
    prev = a[i]

if stc != 0:
    mon = mon + stc * a[n - 1]

print(mon)

Submission status: Wrong Answer

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

prev = a[0]
mon = 1000
stc = 0

for i in range(1, n):
    print(prev)
    if prev < a[i]:
        stc = mon // prev
        mon = mon - stc * prev
        print("stc = {} mon = {}" .format(stc, mon))
    elif prev > a [i]:
        mon = mon + stc * prev
        stc = 0
        print("stc = {} mon = {}" .format(stc, mon))
    prev = a[i]

if stc != 0:
    mon = mon + stc * a[n - 1]

print(mon)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i in range(n-1):
    if(a[i] < a[i+1]):
        if(b[i-1] < 1):
            b[i] = 1
        else:
            b[i] = 2
    if(a[i] > a[i+1]):
        if(b[i-1] > -1):
            b[i] = -1
        else:
            b[i] = -2
    else:
        if(b[i-1] > 0):
            b[i] = 2
        else:
            b[i] = -2
b[-1] = -1
#print(b)
h = [1000,0]
for i in range(n):
    if(b[i] == 1):
        h[1] = h[0]//a[i]
        h[0] %= a[i]
    elif(b[i] == -1):
        h[0] += h[1]*a[i]
        h[1] *= 0
    #print(h)
print(h[0])

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
a += 1,
m = 1000
from itertools import*
for i in [list(k) for p, k in groupby(range(n+1), key = lambda j:a[j] >= a[j-1]) if p]:
  m = m // a[i[0]] * a[i[-1]] + m % a[i[0]]
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
 
money = 1000
stock = 0
pivot = []
flag = 0
 
for i in range(n-1):
    pivot.append(int(a[i+1]) - int(a[i]))
 
pivot.append(-1)
pivot.append(-1)
 
i=0
 
for j in range(n):
    if(pivot[j]>0):
        i = j
        break
    else:
        flag = -1
 
if(flag != -1):
    stock = int(money//(int(a[i])))
    money = int(money%(int(a[i])))
 
i+=1
if(flag != -1):
    while(i<n):
        if(i==n-1):
            if(pivot[i]>0):
                money = money + stock*int(a[i+1])
                stock = 0
            break
 
        elif(pivot[i]<0):
            while(pivot[i+1]<=0 and flag != -1):
                if(i==n-2):
                    flag = -1
                i+=1
            if(flag != -1):
                stock = int(money//(int(a[i+1])))
                money = int(money%(int(a[i+1])))
                i+=1
        else:
            while(pivot[i+1]>=0 and flag != -1):
                if(i==n-2):
                    flag = -1
                i+=1
            money = money + stock*int(a[i+1])
            stock = 0
            i+=1
 
print(money)

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
a += 1,
m = 1000
from itertools import*
for i in [list(k) for _, k in groupby(range(n + 1), key = lambda j:a[j] >= a[j - 1])]:
  m = m // a[i[0]] * a[i[-1]] + m % a[i[0]]
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))

budget = 1000
stock = 0
for i in range(n-1):
    if l[i] < l[i+1]:
        stock = budget // l[i]
        budget = budget % l[i]
    elif l[i] > l[i+1]:
        budget = budget + stock * l[i]
        stock = 0
else:
    budget += stock*l[-1]
    stock = 0

print(budget)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()

money = 1000
stock = 0
pivot = []
flag = 0

for i in range(n-1):
    pivot.append(int(a[i+1]) - int(a[i]))

pivot.append(-1)
pivot.append(-1)

i=0

for j in range(n):
    if(pivot[j]>0):
        i = j
        break
    else:
        flag = -1

if(flag != -1):
    stock = int(money//int(a[i]))
    money = int(money%int(a[i]))

i+=1
if(flag != -1):
    while(i<n):
        if(i==n-1):
            if(pivot[i-1]>0):
                money = money + stock*int(a[i])
                stock = 0
            break

        elif(pivot[i]<0):
            print("i=",i)
            while(pivot[i+1]<=0 and flag != -1):
                if(i==n-2):
                    flag = -1
                i+=1
            if(flag != -1):
                stock = int(money//int(a[i+1]))
                money = int(money%int(a[i+1]))
                i+=1
        else:
            while(pivot[i+1]>=0 and flag != -1):
                if(i==n-2):
                    flag = -1
                i+=1
            money = money + stock*int(a[i+1])
            stock = 0
            i+=1

print(money)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
now=1000
cnt=0
flag=0

for i in range(n-1):
    if flag==1:
        now+=cnt*a[i]
        cnt=0
        flag=0
        continue

    if a[i]<a[i+1]:
        cnt=now//a[i]
        now=now-cnt*a[i]
        flag=1

if flag==1:
    now+=cnt*a[n-1]
print(now)

Submission status: Wrong Answer

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

yen = 1000
stocks = 0

for i in range(N):
  if i == N-1:
    yen += stocks * A[i]
    stocks = 0
    break
  
  if A[i] > A[i-1]:
    # sell everything
    yen += stocks * A[i]
    stocks = 0
  else:
    # buy everything
    num = yen // A[i]
    stocks += num
    yen -= A[i] * num

print(yen)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = list(map(int, input().split()))

curr = 1000
stock = 0

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

curr += stock * ls[i + 1]
stock = 0

print(curr)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = list(map(int, input().split()))

curr = 1000
stock = 0

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

curr += stock * ls[i + 1]
stock = 0

print(curr)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = list(map(int, input().split()))

curr = 1000
stock = 0

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

if ls[i+1] > ls[i]:
    curr += stock * ls[i + 1]
    stock = 0

print(curr)

Submission status: Wrong Answer

Solution code:
def 買う(株, 金, 株価):
    株 = 金 // 株価
    金 = 金 - 株*株価
    return 株, 金

def 売る(株, 金, 株価):
    金 = 金 + 株*株価
    株 = 0
    return 株, 金

n = int(input())
株価 = [int(i) for i in input().split()]
株価.append(-1)

株 = 0
金 = 1000

for i in range(n):
    if 株価[i] < 株価[i+1]:
        株, 金 = 買う(株, 金, 株価[i])
    else:
        株, 金 = 売る(株, 金, 株価[i])

print(金)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction

mod = 10 ** 9 + 7
mod1 = 998244353

# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase

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




# --------------------------------------------------binary------------------------------------
n=int(input())
l=list(map(int,input().split()))
tot=1000
sel=0
share=0
for i in range(n):
    if max(l[i:])==l[i]:
        #print(l[i],share)
        tot+=share*l[i]
        share=0
        break
    elif i!=0 and l[i]>l[i-1]:
        sel=max(sel,l[i])
    elif l[i]<l[i+1]:
        tot+=sel*share
        share=0
        sel=0
        share+=tot//l[i]
        tot=tot%l[i]
if share!=0:
    tot += sel * share
print(tot)