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

class Trade():
    def __init__(self):
        self.money = 1000
        self.option = 0

    def buy(self, price):
        if self.money == 0:
            return
        self.option = self.money // price
        self.money -= self.option * price

    def sell(self, price):
        if self.option == 0:
            return
        self.money += self.option * price
        self.option = 0


trade = Trade()

for i in range(n):
    if i == n-1:
        continue
    if A[i] < A[i+1]:
        trade.buy(A[i])
    else:
        trade.sell(A[i])

trade.sell(A[-1])

print(trade.money)

Submission status: Wrong Answer

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

stockNo = 0
money = 1000
procedure = []

for i in range(N):
  if i == 0:
    if a[i] < a[i+1]:
      procedure.append("buy")
    else:
      procedure.append("stay")
  elif i <= N-2:
    if a[i] <= a[i-1] and a[i] >= a[i+1]:
      procedure.append("cell")
    elif a[i] >= a[i-1] and a[i] <= a[i+1]:
      procedure.append("buy")
    else:
      procedure.append("stay")
  else:
    procedure.append("cell")    
    
for i in range(N):
  if procedure[i] == "buy":
    while money >= a[i]:
      money -= a[i]
      stockNo += 1
  if procedure[i] == "cell":
    while stockNo > 0:
      money += a[i]
      stockNo -= 1
print(money)

Submission status: Wrong Answer

Solution code:
"""
AtCoder :: M-Solutions Programming Contest 2020 :: Road to Millionaire
https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d
"""
import sys


def find_buy_day(curr_day, prices):
    for day in range(curr_day, len(prices)-1):
        if prices[day] < prices[day+1]:
            return day
    return -1


def find_sell_day(curr_day, prices):
    for day in range(curr_day, len(prices)-1):
        if prices[day] > prices[day+1]:
            return day
    if prices[-1] > prices[-2]:
        return len(prices)-1
    return -1


def solve(prices):
    """Solve puzzle."""
    prev_yen = yen = 1000
    day = find_buy_day(0, prices)
    while day >= 0:
        prev_yen = yen
        shares, yen = divmod(yen, prices[day])
        day = find_sell_day(day, prices)
        if day == -1:
            return prev_yen
        yen += shares * prices[day]
        day = find_buy_day(day, prices)
    return yen


def main():
    """Main program."""
    N = int(sys.stdin.readline())
    prices = [int(i) for i in sys.stdin.readline().split()]
    print(solve(prices))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
souba=list(map(int,input().split()))
urikaiba=list()
money=1000
num=0
for i in range(1,N-1):
    if (souba[i]-souba[i-1])*(souba[i+1]-souba[i])<=0 and ((souba[i]-souba[i-1])!=0 or (souba[i+1]-souba[i])!=0) and (souba[i]-souba[i-1])!=0:
        urikaiba.append(souba[i])
urikaiba.insert(0,souba[0])
urikaiba.append(souba[N-1])
for i in range(len(urikaiba)-1):
    if urikaiba[i+1]-urikaiba[i]>0:
        num=money//urikaiba[i]
        money=money-num*urikaiba[i]
    elif urikaiba[i+1]-urikaiba[i]<0:
        money=money+num*souba[i]
        num=0
if num==0:
    print(money)
else:
    print(money+num*souba[N-1])

Submission status: Wrong Answer

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



counter = 0
while True:
    if A[counter]<A[counter+1]:
        break
    counter +=1
    if counter >= N-2:
        print(1000)
        exit()
    
value = A[counter]
num = 1000//A[counter]
flag = 1
max_ = 1000
posess = 1000%A[counter]


for i in range(counter+1,N):
    ok = A[i]
    if flag:
       
        if ok > value:
            posess += num*ok
            max_ = max(max_,posess)
            num = 0
            flag = 0
            value = ok
    else:
        if ok < value :
            num = posess//ok
            posess %= ok
            flag = 1
            value = ok

            
print(max_)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
money  = 1000
stock = 0
min_price = 200
max_price = 100

for i in range(n):
    if a[i] < min_price:
        min_price = a[i]
    else:
        if a[i] >= max_price:
            max_price = a[i]
            if i == n - 1:
                money = (money // min_price) * max_price + money % min_price
        else:
            money = (money // min_price) * max_price + money % min_price
            min_price = a[i]
            max_price = 100
print(money)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    deff_list = [0]
    for i in range(1,N):
        deff_list.append(As[i] - As[i-1])

    res_list = []
    is_first = True
    any_plus = False
    for i in range(1,N):
        if deff_list[i] > 0:
            any_plus = True
        
        if is_first and any_plus and deff_list[i] < 0 :
            res_list.append([i-1, As[i-1]])
            is_first = False

        if deff_list[i-1] > 0 and deff_list[i] < 0:
            res_list.append([i-1, As[i-1]])
        


    else:
        if deff_list[N-1] >= 0 and any_plus:
            res_list.append([N-1, As[N-1]])

    prev = 0
    res = 1000
    for i, val in res_list:
        if prev < i:
            temp_min = min(As[prev:i])
            temp_num = res //  temp_min
            res = temp_num * val + res % temp_min

        prev = i

    print(res)



if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    A_org = list(map(int,input().split()))
    A = [A_org[0]]
    isPosPrev = False
    for i in range(N-1):
        if A_org[i] == A_org[i+1]:
            continue

        isPosNow = True if A_org[i] < A_org[i+1] else False

        if i == 0:
            isPosPrev = isPosNow

        if isPosNow != isPosPrev:
            A.append(A_org[i])
        
        isPosPrev = isPosNow
    else:
        A.append(A_org[-1])
    
    if A[0] > A[1]:
        A = A[1:]

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

Submission status: Wrong Answer

Solution code:
import itertools
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_compact = []
    sabun = []
    for i in range(1, n):
        sabun.append(a[i] - a[i-1])
    for i, kabuka in enumerate(a):
        if i == 0 or i == len(a)-1:
            a_compact.append(kabuka)
        else:
            if sabun[i-1] != 0:
                check = sabun[i-1] * sabun[i]
                if check <= 0:
                    a_compact.append(kabuka)
    sabun_compact = []
    for i in range(1, len(a_compact)):
        sabun_compact.append(a_compact[i] - a_compact[i-1])
    money = 1000
    kabu = 0
    for i, s in enumerate(sabun_compact):
        # print(i)
        # print('money' + str(money))
        # print('kabunum' + str(kabu))
        if s > 0:
            kabu = money//a_compact[i]
            money -= a_compact[i]*kabu
        else:
            money += a_compact[i]*kabu
            kabu = 0
    money += a_compact[-1]*kabu
    print(money)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
input = sys.stdin.readline


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


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


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


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


def main():
    N = readint()
    A = list(readnums())
    d = deque(A)
    d.appendleft(201)
    d.append(0)
    # ans = 1000 + (max(A) - min(A)) * (1000 // min(A))
    il = []
    for i in range(N):
        if d[i] <= d[i + 1] and d[i + 1] > d[i + 2]:
            il.append(i)
        elif d[i] >= d[i + 1] and d[i + 1] < d[i + 2]:
            il.append(i)

    # print(il)
    if len(il) <= 1:
        print(1000)
    else:
        b = 1000
        s = 0
        if A[il[0]] < A[il[1]]:
            for i, v in enumerate(il):
                if not i % 2:
                    s += b // A[v]
                    b -= s * A[v]
                else:
                    b += s * A[v]
                    s = 0
                # print(b, s)
        else:
            for i, v in enumerate(il):
                if i % 2:
                    s += b // A[v]
                    b -= s * A[v]
                else:
                    b += s * A[v]
                    s = 0
                # print(b, s)
        if s:
            b = A[il[-1]] * s

        print(max(b, 1000))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    n = II()
    aa = MII()
    balance = 1000
    ss = []
    idxs = []
    minv = aa[0]
    minv_idx = 0
    for i in range(1, n):
        if minv > aa[i]:
            minv = aa[i]
            minv_idx = i
        elif minv < aa[i]:
            ss.append(minv)
            idxs.append(minv_idx)
            minv = 200
    if not idxs:
        print(1000)
        exit()
    idxs.append(n)
    for i in range(len(idxs)-1):
        buy = ss[i]
        sell = max(aa[idxs[i]:idxs[i+1]])
        num = balance // buy
        balance -= num * buy
        balance += sell * num
    print(balance)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    deff_list = [0]
    for i in range(1,N):
        deff_list.append(As[i] - As[i-1])

    res_list = []
    is_first = True
    any_plus = False
    for i in range(1,N):
        if deff_list[i] > 0:
            any_plus = True
        
        if is_first and any_plus and deff_list[i] < 0 :
            res_list.append([i-1, As[i-1]])
            is_first = False

        if deff_list[i-1] > 0 and deff_list[i] < 0:
            res_list.append([i-1, As[i-1]])
        


    else:
        if deff_list[N-1] >= 0 and any_plus:
            res_list.append([N-1, As[N-1]])

    prev = 0
    res = 1000
    for i, val in res_list:
        if prev != i:
            temp_min = min(As[prev:i])
            temp_num = res //  temp_min
            res = temp_num * val + res % temp_min
            prev = i

    print(res)



if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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



counter = 0
while True:
    if A[counter]<A[counter+1]:
        break
    counter +=1
    if counter >= N-2:
        print(1000)
        exit()
    
value = A[counter]
num = 1000//A[counter]
flag = 1
max_ = 1000
posess = 1000%A[counter]


for i in range(counter+1,N):
    ok = A[i]
    if flag:
        print(ok,value)
        if ok > value:
            posess += num*ok
            max_ = max(max_,posess)
            num = 0
            flag = 0
            value = ok
    else:
        if ok < value :
            num = posess//ok
            posess %= ok
            flag = 1
            value = ok

            
print(max_)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = 1000
b = 0
for i in range(n):
  if i == 0:
    if a[i] == max(a):
      print(x)
      exit()
    else:
      if a[i]<a[i+1]:
        b += x//a[i]
        x -= a[i]*(x//a[i])
  else:
    if a[i] == max(a):
      x += a[i]*b
      if x>= 1000:
        print(x)
        exit()
      else:
        print(1000)
        exit()
    else:
      if a[i]>a[i+1]:
        x += b*a[i]
        b = 0
      elif a[i]<a[i+1]:
        b += x//a[i]
        x -= (x//a[i])*a[i]
      elif a[i]==a[i+1]:
        pass
      elif a[i] == min(a):
        b += x//a[i]
        x -= a[i]*(x//a[i])

Submission status: Wrong Answer

Solution code:
_ = int(input())
kakaku = list(map(int, input().split()))

money = 1000
num_item = 0

up_flag = False
down_flag = False

if kakaku[0] < kakaku[1]:
    up_flag = True
else:
    down_flag = True

dp = []

if up_flag:
    dp.append(kakaku[0])

# 減=>増=>減....の形にする
for i in range(1, len(kakaku)):
    # いま増加中or下後中
    if kakaku[i - 1] > kakaku[i]:
        if down_flag:
            pass
        else:
            down_flag=True
            up_flag=False
            dp.append(kakaku[i-1])
        down_flag = True
    elif kakaku[i-1] < kakaku[i]:
        if up_flag:
            pass
        else:
            down_flag = False
            up_flag = True
            dp.append(kakaku[i-1])
        up_flag = True
    # print('up', up_flag, 'down', down_flag, 'now item',kakaku[i], 'dp', dp)

if kakaku[-2] < kakaku[-1]:
    if len(dp) >= 3 and kakaku[-3] < kakaku[-2]:
        dp[-1] = kakaku[-1]
    else:
        dp.append(kakaku[-1])

# print(dp)

for i in range(len(dp)):
    if i % 2 == 0:
        num_item += money // dp[i]
        money -= dp[i] * num_item
    else:
        money += dp[i] * num_item
        num_item = 0
if num_item != 0:
    money += num_item * dp[-1]

print(money)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-07-25 21:25:14 +0900
# LastModified: 2020-07-25 22:33:12 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n = int(input())
    a = list(map(int, input().split()))
    have = 1000
    pivot_index = 0
    obj_index = -1
    while pivot_index < n:
        tmp = -1
        for i in range(pivot_index+1, n):
            if a[i] - a[pivot_index] > 0:
                tmp = i
                break
        if tmp == -1:
            print(have)
            return
        obj_index = tmp
        tmp = obj_index
        for i in range(tmp+1, n):
            if a[i] - a[tmp] <= 0:
                break
            else:
                obj_index = i
        min_flactu = min(a[pivot_index:obj_index+1])
        have = have % min_flactu + have // min_flactu * a[obj_index]
        pivot_index = obj_index+1
    print(have)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

money = 1000
stock = 0
cnt = 1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
#N = 7
#A = [100, 130, 130, 130, 115, 115, 150]
Y = 1000
K = 0



def buy(i):
    global K,Y
    K += Y // A[i]
    Y -= K * A[i]

def sell(i):
    global K,Y
    Y += K * A[i]
    K = 0

# 初日は必ず買う
buy(0)
#print(i,K,Y)
#
for i in range(1,N-1):
    if A[i] < A[i+1]:
        buy(i)
    else:
        sell(i)
    #print(i,K,Y)
    
# 最終日は必ず売る
sell(N-1)
print(Y)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n = int(input())
a = list(map(int,input().split()))
money = 1000
have = 0
buy = 0
c = []
check = a[0]
start = False
check2 = -1
for i in range(1,n):
    if check2 > a[i] and start:
        c.append((check,check2))
        check = a[i]
        check2 = -1
        #print(i)
    elif check2 <= a[i] and start:
        check2 = a[i]
    elif check < a[i] and not start:
        check2 = a[i]
        start = True
    elif check >= a[i] and not start:
        check = a[i]
    #print(check,check2)
if check2 != -1 and check != check2:
    c.append((check,check2))
#print(c)
for i in c:
    have = money//i[0]
    money -= i[0]*have
    money += have * i[1]
print(money)

Submission status: Wrong Answer

Solution code:
N = 2
ARR = [157, 193]

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

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

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

# N = 5
# ARR = [111, 111, 111, 111, 111]

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

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

    money = 1000
    num = 0
    history = []
    for res in result:
        type = res.get('type')
        value = res.get('value')
        if type == 0:
            num += money // value
            money -= num * value
        else:
            money += num * value
            history.append(money)
            num = 0

    if len(history) == 0:
        print(money)
    else:
        print(max(history))

calculate(ARR)

Submission status: Wrong Answer

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

n = int(readline())
lst1 = list(map(int,readline().split()))
ct = 1000
stock = 0
#次の日に上がるか下がるか
lst2 = [0]*n
for i in range(n-1):
    if lst1[i] < lst1[i+1]:
        lst2[i] = 1
    elif lst1[i] > lst1[i+1]:
        lst2[i] = -1
for i in range(n):
    if lst2[i] == 1:
        stock = ct//lst1[i]
        ct %= lst1[i]
    elif lst2[i] == -1:
        ct += stock*lst1[i]


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

Submission status: Wrong Answer

Solution code:
#D - Road to Millionaire
N= int(input())
A= list(map(int,input().split()))
A_s = [0]
B = 1000
C = 0
B_1 = 0
C_1 = 0
for j in range(N-1):
    A_s.append(A[j+1]-A[j])
#print(A_s)

for i in range(N-1):
    if A_s[i+1] > 0:
        B_1 = B - (B // A[i])*A[i]
        C_1 = C + B // A[i]
        B = B_1
        C = C_1
    elif A_s[i+1] <= 0:
        if C > 0:
            B_1 = B + C * A[i + 1]
            C = 0
            B = B_1
    else:
        pass
if C > 0:
    B = B +C*A[N-1]

print(B)

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
#min_price = A[0]
#max_price =A[0]
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
        previous_tendency = "none"
        current_tendency = "none"
    #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()))
money = 1000
kabu = 0
kazu = 0
count = 0
for i in range(N-1):
    #print("min",min(A[i:]),A[i])
    if min(A[i:]) == A[i]:
        kazu = int(money/A[i])
        kabu += kazu
        money -= kazu * A[i]
        if kazu != 0:
            syutoku = A[i]
            count += 1
        #print(kabu,syutoku,money)
    if kazu != 0:
        if  syutoku < A[i]:
            money += kabu*A[i]
            kabu = 0
            #print(kabu,syutoku,money)
if count != 0:
    if syutoku < A[N-1]:
        money += kabu*A[N-1]
        kabu = 0
    #print(kabu,syutoku,money)

print(money)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-07-25 21:25:14 +0900
# LastModified: 2020-07-25 22:32:40 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n = int(input())
    a = list(map(int, input().split()))
    have = 1000
    pivot_index = 0
    obj_index = -1
    while pivot_index < n:
        tmp = -1
        for i in range(pivot_index+1, n):
            if a[i] - a[pivot_index] > 0:
                tmp = i
                break
        if tmp == -1:
            print(have)
            return
        obj_index = tmp
        tmp = obj_index
        for i in range(tmp+1, n):
            if a[i] - a[tmp] <= 0:
                break
            else:
                obj_index = i
        min_flactu = min(a[pivot_index:obj_index+1])
        have = have % min_flactu + have // min_flactu * a[obj_index]
        pivot_index = obj_index+1
#    print(have)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

stockNo = 0
money = 1000
procedure = []

for i in range(N):
  if i == 0:
    if a[i] < a[i+1]:
      procedure.append("buy")
    else:
      procedure.append("stay")
  elif i <= N-2:
    if a[i] <= a[i-1] and a[i] > a[i+1]:
      procedure.append("cell")
    elif a[i] >= a[i-1] and a[i] < a[i+1]:
      procedure.append("buy")
    else:
      procedure.append("stay")
  else:
    procedure.append("cell")
    
for i in range(N):
  if procedure[i] == "buy":
    while money >= a[i]:
      money -= a[i]
      stockNo += 1
  if procedure[i] == "cell":
    while stockNo > 0:
      money += a[i]
      stockNo -= 1
print(money)

Submission status: Wrong Answer

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

kai=[]
uri=[]
sokone=A[0]
takane=A[0]
for i in range(1,N):
    if A[i-1]<=A[i]:
        takane=A[i]
        if i==(N-1) and takane>sokone:
            uri.append(takane)
            kai.append(sokone)
    else:
        if sokone<A[i-1]:
            uri.append(takane)
            kai.append(sokone)
            sokone=A[i]

kabu=0
money=1000
for i in range(len(kai)):
    #kabu+=money//kai[i]
    money=money%kai[i]+uri[i]*(money//kai[i])
  

print(money)

Submission status: Wrong Answer

Solution code:
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 A[i] < np.max(A[i:]):
            if A[i] > np.min(A[i:]) and np.argmin(A[i:]) < np.argmax(A[i:]):
                continue
            else:
                have_money, have_stock, have_stock_valuation = buy_stock(have_money, have_stock, have_stock_valuation, A[i])
                call_status = False
    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

print(have_money)

Submission status: Wrong Answer

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

money = 1000
num = 0

for i in range(N - 1):
    if A[i] < A[i + 1]:
        num += money // A[i]
        money -= (A[i] * num)
    if A[i] > A[i + 1]:
        money += (A[i] * num)
        num = 0
    if num != 0 and i + 2 == N:
        money += A[i + 1] * num

print(money)

Submission status: Wrong Answer

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

money = 1000
num = 0
buy_p = 0
i = 0

for i in range(N-1):
    if A[i] >= A[i+1]:
        i += 1
        continue
    elif i == N-2:
        if A[i] < A[N-1]:
            num, money = divmod(money, A[i])
            money += A[N-1] * num
        break
    for j in range(i+2, N):
        if A[j-1] > A[j]:
            num, money = divmod(money, A[i])
            money += A[j-1] * num
            i = j
            break

print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())
rate = input().split(" ")
for i in range(N):
  rate[i] = int(rate[i])

kabu = 0
money = 1000

for day in range(N):
  if kabu > 0:
    if rate[day-1] < rate[day]:
      money = money + kabu*rate[day]
      kabu = 0
    else:
      None
  else:
    if day == N-1:
      None
    elif rate[day] < rate[day+1]:
      kabu = money // rate[day]
      money = money - kabu*rate[day]
      
print(money)

Submission status: Wrong Answer

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

yen = 1000
kabu = 0

max_day = A.index(max(A))

if max_day == 0:
    print(yen)
    exit()

for i in range(max_day):
    if A[i] < A[i+1]:
        #株式購入
        kabu = kabu + yen//A[i]
        yen = yen - kabu*A[i]
    elif A[i] > A[i+1]:
        #株式売却
        yen = yen + kabu*A[i]
        kabu = 0

print(yen+kabu*A[max_day])

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 1000
    s = 0
    n = int(input())
    a = list(map(int, input().split()))
    b = [""]*n
    for i in reversed(range(n)):
        if a[i]>a[i-1]:
            b[i]="sell"
        elif a[i]<=a[i-1]:
            b[i]="buy"
    if a[0] <= a[1]:
      b[0] = "buy"
    elif a[0] > a[1]:
      b[0] = "sell"
    for i in range(n):
        if b[i] == "sell":
            ans += s*a[i]
            s = 0
        elif b[i] == "buy" and i != n-1 and b[i+1] != "buy":
            s += ans//a[i]
            ans -= s*a[i]
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# cook your dish here
n = int(input())
l = list(map(int, input().split()))
small = l[0]
ans = 1000
for i in range(1, n):
    if l[i]<small:
        small = l[i]
    elif l[i]>small:
        ans = ans + (ans//small)*(l[i]-small)
        if i<n-1:
            small = l[i+1]
            i=i+1
if ans<1000:
    print("1000")
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
LIST_A = list(map(int,input().split()))

flag = True
money = 1000
i = 0
distance = 0
upstair = False
while flag == True:
  
  #print("i:",i,"distance:",distance)
  if LIST_A[distance+1] - LIST_A[distance] >= 0:
    #print(LIST_A[1+distance])
    #print(LIST_A[distance])
    if LIST_A[distance+1] - LIST_A[distance] > 0:
      upstair = True
    else:
      upstair = "updown"
    distance += 1
    
  else:
    #print("down")
    if upstair == True or upstair == "updown":
      money += (money//LIST_A[i])*(LIST_A[distance]-LIST_A[i])
      #print(money)
      upstair = False
    	
    i = distance+1
    distance += 1
    
  	
    
  if N <= distance+1:
    if upstair == True:
      #print("distance+1",distance+1)
      #print(money)
      money += (money//LIST_A[i])*(LIST_A[distance]-LIST_A[i])
    print(money)
    sys.exit()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
S = defaultdict(int)
max_flag = False
min_flag = True
max_v = 0
min_v = 0
for i in range(1,n):
    if min_flag and not max_flag:
        if a[min_v] >= a[i]:
            min_v = i
        elif a[min_v] < a[i]:
            S[min_v] = 'kau'
            min_flag = False
            max_flag = True
            if i == n-1:
                S[i] = 'uru'
    if not min_flag and max_flag:
        if a[max_v] <= a[i]:
            max_v = i
        elif a[max_v] > a[i]:
            S[max_v] = 'uru'
            min_flag = True
            max_flag = False
            min_v = i
            max_v = i

fee = 1000
kabu = 0
for i in range(n):
    if S[i] == 'kau':
        b,c = divmod(fee,a[i])
        fee = c
        kabu += b
    if S[i] == 'uru':
        fee += kabu * a[i]
        kabu = 0
print(fee)

Submission status: Wrong Answer

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