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


stock=0
money=1000
bottom=A[0]
peak=A[0]
trend="NONE"

if peak < A[1]:
    trend="UP"
    stock=money//A[0]
    money=money-stock*A[0]    
elif bottom > A[1]:
    trend="DOWN"

for i in range(1,N):
    # print(stock,money,trend)
    if peak < A[i] and trend=="UP":
        peak=A[i]
    elif bottom > A[i] and trend=="DOWN":
        bottom=A[i]
    elif bottom < A[i] and trend=="DOWN":
        #底打ち
        stock=money//bottom
        money=money-stock*bottom
        peak=A[i]
        trend="UP"
    elif peak > A[i] and trend=="UP":
        #天井
        money=money+stock*peak
        stock=0
        bottom=A[i]
        trend="DOWN"
print(stock*peak+money)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

money = 1000
stock = 0

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

print(money + stock * A[N-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

A_list = [int(n) for n in input().split()]

import numpy as np

A_array = np.array(A_list)

last_num = np.min(np.where(A_array == np.max(A_array)))

if last_num == 0:
  print(1000)

else:  
  A_real = A_array[:last_num + 1]

  d_array = A_real[1:] - A_real[:-1]

  mai = int(np.floor(1000/A_real[0]))
  en = 1000
  
  for i in range(len(d_array)+1):
  
    if i == 0:
      if d_array[i] > 0:
        en += d_array[i] * mai
      
      else:
        en = en    
        
    elif i == len(d_array):
      en += d_array[i-1] * mai
    
    elif (mai != 0) & (d_array[i-1] >= 0) & (d_array[i] >= 0):
      en += d_array[i] * mai
    
    elif (d_array[i-1] >= 0) & (d_array[i] < 0):  
      mai = 0
    
    elif (mai == 0) & (d_array[i-1] <= 0) & (d_array[i] > 0):
      mai = int(np.floor(en/A_real[i]))
    else:
      mai = mai
      en = en   
      
  print(en)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a_cur = a[0]

m = 1000
s = 0

for i in range(1, n):
  a_next = a[i]
  if a_cur < a_next:
    # buy current and sell next
    s = m // a_cur
    m += s * (a_next - a_cur)
    a_cur = a_next
if s > 0:
  m += s * a[-1]
print(m)

Submission status: Wrong Answer

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


stock=0
money=1000
bottom=A[0]
peak=A[0]
trend="NONE"

if peak < A[1]:
    trend="UP"
    stock=money//A[0]
    money=money-stock*A[0]    
elif bottom > A[1]:
    trend="DOWN"

for i in range(1,N):
    # print(stock,money,trend)
    if peak < A[i] and trend=="UP":
        peak=A[i]
    elif bottom > A[i] and trend=="DOWN":
        bottom=A[i]
    elif bottom < A[i] and trend=="DOWN":
        #底打ち
        stock=money//bottom
        money=money-stock*bottom
        peak=A[i]
        trend="UP"
    elif peak > A[i] and trend=="UP":
        #天井
        money=money+stock*peak
        stock=0
        bottom=A[i]
        trend="DOWN"
print(stock*A[N-1]+money)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a_cur = a[0]

m = 1000
s = 0

for i in range(1, n):
  a_next = a[i]
  if a_cur < a_next:
    # buy current and sell next
    s = m // a_cur
    m += s * (a_next - a_cur)
    a_cur = a_next
    if s > 0:
      m += s * a[-1]
      print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

money = 1000
kabu = 0

if A[0] == max(A):
    print(1000)
    exit()

else:
    for i in range(len(A)-1):
        if kabu != 0:
            if A[i] >= A[i + 1]:
                money += kabu * A[i]
                kabu = 0

        else:
            if A[i] < A[i + 1]:
                kabu = money // A[i]
                money -= kabu * A[i]

if kabu != 0:
    money += kabu * A[len(A) - 1]
    
print(money)

Submission status: Wrong Answer

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

buy = 0
money = 1000
for i in range(N-1):
    if buy != 0:
        money += buy*A[i]

    if A[i] < A[i+1]:
        buy = money // A[i]
        money -= buy * A[i]

if buy != 0:
    money += buy*A[-1]

print(money)

Submission status: Wrong Answer

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

M = 1000
X = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        X = int(M/A[i])
        M = int(M - X * A[i])
    
    M = M + X * A[i+1]

print(int(M))

Submission status: Wrong Answer

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

kabu = 0
money = 1000
for i in range(n):
    if i == n-1:
        money += kabu*a[i]
        kabu = 0
    elif a[i] < a[i+1]:
        # while money >= a[i]:
        #     kabu += 1
        #     money -= a[i]
        kabu = money // a[i]
        money = money - a[i]*kabu
    else:
        money += kabu*a[i]
        kabu = 0
    
print(money)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

money = 1000
kabu = 0

if A[0] == max(A):
    print(1000)
    exit()

else:
    for i in range(1,len(A)-1):
        if kabu != 0:
            if A[i] >= A[i + 1]:
                money += kabu * A[i]
                kabu = 0

        else:
            if A[i] < A[i + 1]:
                kabu = money // A[i]
                money -= kabu * A[i]

if kabu != 0:
    money += kabu * A[len(A) - 1]
    
print(money)

Submission status: Wrong Answer

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

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

if buy != 0:
    money += buy*A[-1]

print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

money = 1000
kabu = 0

if A[0] == max(A):
    print(1000)
    exit()

else:
    kabu += money // A[0]
    money -= kabu * A[0]
    for i in range(1,len(A)-1):
        if kabu != 0:
            if A[i] >= A[i + 1]:
                money += kabu * A[i]
                kabu = 0

        else:
            if A[i] < A[i + 1]:
                kabu = money // A[i]
                money -= kabu * A[i]

if kabu != 0:
    money += kabu * A[len(A) - 1]
    
print(money)

Submission status: Wrong Answer

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

money = 1000
stock = 0

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

print(money + stock * A[N-1])

Submission status: Wrong Answer

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

money = 1000
stock = 0

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

print(money)

Submission status: Wrong Answer

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

#print(N)
#print(A)

syozi = float(1000)
kabu = 0

for i in range(N):
#  print(str(i)+': '+ str(A[i]) + ', ' + str(kabu) + ', ' + str(syozi) )
  if i == N-1:
    syozi += A[i] * kabu
    kabu = 0
  elif A[i] < A[i+1]:
    kabu = int( syozi / A[i] )
    syozi = int( syozi % A[i] )
  elif A[i] > A[i+1]:
    syozi += A[i] * kabu
    kabu = 0
  else:
    pass
#  print( str(i)+': '+str(A[i]) + ', ' + str(kabu) + ', ' + str(syozi) )

print(syozi)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
genkin = 1000
kabu = 0

kabusaidai = a.index(max(a))
if kabusaidai == 0:
    print(genkin)
    exit(0)

for i in range(kabusaidai):
    # すべて現金
    genkin_tmp = genkin + a[i] * kabu

    # すべて株
    kazu = genkin//a[i]
    kabu_tmp = genkin - kazu * a[i] + kazu * a[i+1]

    if genkin_tmp > kabu_tmp:
        genkin = genkin + kabu * a[i]
        kabu = 0
    elif genkin_tmp < kabu_tmp:
        genkin = genkin - kazu * a[i]
        kabu = kabu + kazu
    
    if i == kabusaidai:
        break

print(genkin + kabu * a[kabusaidai])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

print(m)

Submission status: Wrong Answer

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

kabu = 0
money = 1000
for i in range(N-1):
  if A[i] < A[i+1]:
    mod,money = divmod(money , A[i])
    kabu += mod
  else:
      money = money + A[i+1] * kabu
      kabu = 0

money = money + A[N-1]*kabu
print(money)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

cnt = 0
money = 1000
b = 0
for i in range(n):
    if i!=0:
        if A[i-1] == A[i]: continue
    if b == 0:
        cnt += money//A[i]
        money %= A[i]
        b = A[i]
    elif b < A[i]:
        money += cnt * A[i]
        cnt = 0
        b = 0
if cnt > 0:
    money += cnt * b
print(money)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = LI()
buy = [0] * n

katamuki = 0
for i in range(n-1):
    if katamuki == 0:
        if mylist[i+1] > mylist[i]:
            buy[0] = "buy"
            katamuki = 1
        elif mylist[i+1] < mylist[i]:
            katamuki = -1
    elif katamuki == -1 and mylist[i+1] > mylist[i]:
        buy[i] = "buy"
        katamuki = 1
    elif katamuki == 1 and mylist[i+1] < mylist[i]:
        buy[i] = "sell"
        katamuki = -1
        
result = 1000
stock = 0
price = 0    
for i in range(n):
    if buy[i] == "buy":
        stock = result // mylist[i]
        result -= mylist[i] * stock
    elif buy[i] == "sell":
        result += mylist[i] * stock
        stcok = 0
    elif i == n-1:
        result += mylist[i] * stock
print(result)

Submission status: Wrong Answer

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

money = 1000
stock = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        stock = money // A[i]
        money = money - A[i] * stock
        # print("buy stocks; money=",money,", stock=",stock)
    else:
        money = money + A[i] * stock
        stock = 0
        # print("sell stocks; money=",money,", stock=",stock)

if stock != 0:
    # print("last;money stock",money,stock)
    # print(A[-1])
    money = money + A[-1] * stock
    stock = 0

# print("money=",money,", stock=",stock)

print(money)

Submission status: Wrong Answer

Solution code:
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 += total//A[i]
        total -= kabu*A[i]
    elif(A[i] >= A[i+1]):
        total += (kabu*A[i])
        kabu = 0
 
 
#最後
i += 1
total += (kabu * A[i])
kabu = 0
print(total)

Submission status: Wrong Answer

Solution code:
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 += total//A[i]
        total -= kabu*A[i]
    elif(A[i] > A[i+1]):
        total += (kabu*A[i])
        kabu = 0
 
 
#最後
i += 1
total += (kabu * A[i])
kabu = 0
print(total)

Submission status: Wrong Answer

Solution code:
def judgeFinalSellDay(x):
  max = 0
  ret=0
  for i in range(n-1,-1,-1):
    if x[i] > max:
      max =x[i]
      ret=i
    elif x[i] < max:
      break
  return ret

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

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

Submission status: Wrong Answer

Solution code:
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 += total//A[i]
        total -= kabu*A[i]
    elif(A[i]==A[i+1]):
        pass
    elif(A[i] > A[i+1]):
        total += (kabu*A[i])
        kabu = 0
 
 
#最後
i += 1
total += (kabu * A[i])
kabu = 0
print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

money = 1000
kabu = 0

if A[0] == max(A):
    print(1000)
    exit()

else:
    kabu += money // A[0]
    money -= kabu * A[0]
    for i in range(1,len(A)-1):
        if kabu != 0:
            if A[i] >= A[i + 1]:
                money += kabu * A[i]
                kabu = 0

        else:
            if A[i] != max(A[i + 1 :]):
                kabu += money // A[i]
                money -= kabu * A[i]
            else:
                break

if kabu != 0:
    money += kabu * A[len(A) - 1]
    
print(money)

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*urikaiba[i]
        num=0
if num==0:
    print(money)

else:
    print(money+num*souba[N-1])

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]:
            if i == N -1:
                have_money, have_stock, have_stock_valuation = sell_stock(have_money, have_stock, have_stock_valuation,  A[i])
                break

            if A[i] < A[i+1]:
                continue
            else:
                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:
import sys
from collections import deque
input = sys.stdin.readline


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


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


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


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


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

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

    print(b)
    # 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 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:
            a_compact.append(kabuka)
        elif i == len(a)-1:
            if a[-2] != 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:
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])
print(*urikaiba)
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*urikaiba[i]
        num=0
if num==0:
    print(money)

else:
    print(money+num*souba[N-1])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

n = inN()
a = inL()

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

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

Submission status: Wrong Answer

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

ud = [0] * (N-1)
for i in range(1,N):
    if A[i] > A[i-1]:
        ud[i-1] = 1
    if A[i] < A[i-1] :
        ud[i-1] = -1
    else:
        continue
        
tmp =0
bs = [''] * N
if ud[0] == 1:
    bs[0] = 'b'
    tmp = 1
if ud[0] == -1:
    tmp = -1

for i in range(1,len(ud)):
    if tmp == 0 and ud[i] != 0:
        tmp = ud[i]
    elif ud[i] == 0:
        continue
    elif tmp == -1 and ud[i] == 1:
        bs[i] = 'b'
        tmp = ud[i]
    elif tmp == 1 and ud[i] == -1:
        bs[i] = 's'
        tmp = ud[i]

bs[0] = 'b'
bs[-1] = 's'

kabu = 0
zan = 1000
for i in range(N):
    if bs[i] == 'b':
        kabu = zan // A[i]
        zan -= kabu * A[i]
    if bs[i] == 's':
        zan += kabu * A[i]
        kabu = 0
print(max(1000,zan))

Submission status: Wrong Answer

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

A_l.append(0)

money = 1000
stock = 0

for i in range(N):

    if A_l[i] < A_l[i+1]:
        stock = money // A_l[i]
        money = money % A_l[i]
    if A_l[i] > A_l[i+1] and stock != 0:
        money = stock * A_l[i] + money
        stock = 0


print(money)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
genkin = 1000
kabu = 0

kabusaidai = a.index(max(a))

for i in range(n-1):
    # すべて現金
    genkin_tmp = genkin + a[i] * kabu

    # すべて株
    kazu = genkin//a[i]
    kabu_tmp = genkin - kazu * a[i] + kazu * a[i+1]

    if genkin_tmp > kabu_tmp:
        genkin = genkin + kabu * a[i]
        kabu = 0
    elif genkin_tmp < kabu_tmp:
        genkin = genkin - kazu * a[i]
        kabu = kabu + kazu
    
    if i == kabusaidai:
        break

print(genkin + kabu * a[-1])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
money = 1000
start = 0
while True:
    for i in range(start,N):
        if A[i] > A[start]:
            stock = money // min(A[start:i])
            amari = money % min(A[start:i])
            for j in range(i,N):
                if j == N-1:
                    money = amari + stock*max(A[i:j+1])
                    print(money)
                    exit()
                if A[j] < A[i] or j == N-1:
                    money = amari + stock*max(A[i:j])
                    stock = 0
                    amari = 0
                    start = j
                    break
            break
        if i == N-1:
            print(money)
            exit()