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()))
money=1000
stock=0
#1日目
if A[0]<=A[1]:
    stock=int(money/A[0])
    money=money-stock*A[0]
    #print(0,money,stock)

for i in range(1,N-1):
    #買い戦略
    if A[i-1]>=A[i] and A[i] <=A[i+1]:
        stock=int(money/A[i])
        money=money-stock*A[i]
        #print(i,money,stock)
    #売り戦略
    if A[i-1]<=A[i] and A[i] >=A[i+1]:
        money=money+stock*A[i]
        stock=0
       # print(i,money,stock)

#N日目
if  A[N-2]<A[N-1]:
    money=money+stock*A[N-1]
if A[N-2]>=A[N-1]:
    money=money+stock*A[N-2]
#print(N-1,money,stock)
print(money)

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int, input().split()))
money=1000
stock=0
#1日目
if A[0]<=A[1]:
    stock=int(money/A[0])
    money=money-stock*A[0]
    #print(0,money,stock)

for i in range(1,N-1):
    #買い戦略
    if A[i-1]>A[i] and A[i] <=A[i+1]:
        stock=int(money/A[i])
        money=money-stock*A[i]
        #print(i,money,stock)
    #売り戦略
    if A[i-1]<A[i] and A[i] >=A[i+1]:
        money=money+stock*A[i]
        stock=0
       # print(i,money,stock)

#N日目
if  A[N-2]<A[N-1]:
    money=money+stock*A[N-1]
if A[N-2]>=A[N-1]:
    money=money+stock*A[N-2]
#print(N-1,money,stock)
print(money)

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int, input().split()))
money=1000
stock=0
#1日目
if A[0]<=A[1]:
    stock=int(money/A[0])
    money=money-stock*A[0]
    #print(1,money,stock)

for i in range(1,N-2):
    #買い戦略
    if A[i-1]>A[i] and A[i] <=A[i+1]:
        stock=int(money/A[i])
        money=money-stock*A[i]
        #print(i,money,stock)
    #売り戦略
    if A[i-1]<A[i] and A[i] >=A[i+1]:
        money=money+stock*A[i]
        stock=0
        #print(i,money,stock)
#N日目
if A[N-2]<A[N-1]:
    money=money+stock*A[N-1]
if A[N-2]>=A[N-1]:
    money=money+stock*A[N-2]
#print(N-1,money,stock)
print(money)

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int, input().split()))
money=1000
stock=0
#1日目
if A[0]<A[1]:
    stock=int(money/A[0])
    money=money-stock*A[0]
    #print(1,money,stock)

for i in range(1,N-2):
    #買い戦略
    if A[i-1]>A[i] and A[i] <=A[i+1]:
        stock=int(money/A[i])
        money=money-stock*A[i]
        #print(i,money,stock)
    #売り戦略
    if A[i-1]<A[i] and A[i] >=A[i+1]:
        money=money+stock*A[i]
        stock=0
        #print(i,money,stock)
#N日目
if A[N-2]<A[N-1]:
    money=money+stock*A[N-1]
if A[N-2]>=A[N-1]:
    money=money+stock*A[N-2]
#print(N-1,money,stock)
print(money)

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int, input().split()))
money=1000
stock=0
#1日目
if A[0]<A[1]:
    stock=int(money/A[0])
    money=money-stock*A[0]
    print(1,money,stock)

for i in range(1,N-2):
    #買い戦略
    if A[i-1]>A[i] and A[i] <=A[i+1]:
        stock=int(money/A[i])
        money=money-stock*A[i]
        print(i,money,stock)
    #売り戦略
    if A[i-1]<A[i] and A[i] >=A[i+1]:
        money=money+stock*A[i]
        stock=0
        print(i,money,stock)
#N日目
if A[N-2]<A[N-1]:
    money=money+stock*A[N-1]
if A[N-2]>=A[N-1]:
    money=money+stock*A[N-2]
print(N-1,money,stock)
print(money)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
a = rl()
m = 1000
s = 0
for i in range(n-1):
    if a[i+1] > a[i]:
        s = m//a[i]
        m -= s*a[i]
    else:
        m += s*a[i]
        s = 0
else:
    m += s*a[-1]
print(m)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]


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



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [0] + [*map(int, input().split())]
dp_stock = [0]*(n+1)
dp_yen = [0]*(n+1)
dp_yen[0] = 1000
for day in range(1, n+1):
    dp_stock[day] = max(dp_stock[day-1], dp_yen[day-1]) // A[day]
    remain = dp_yen[day-1] - dp_stock[day-1]*A[day-1]
    dp_yen[day] = max(dp_yen[day-1], remain + dp_stock[day-1] * A[day])
print(dp_yen[n])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
prev = a[0]
up = False
staks = 0
money = 1000
for i in a[1:]:
    if i > prev and not up:
        staks = money//prev
        money = money % prev
        up = not up
    if i < prev and up:
        money += prev*staks
        stacks = 0
        up = not up
    prev = i
if staks:
    money += prev*staks

print(money)

Submission status: Wrong Answer

Solution code:
def sell(rate, kabu):
    return rate * kabu
    
def buy(rate, money):
    kabu = money//rate
    otsuri = money % rate
    return kabu, otsuri
    
N,*A = map(int, open(0).read().split())
money = 1000
have_kabu = 0
for i in range(N-1):
    if A[i] < A[i+1]: #買う
        have_kabu, money = buy(A[i], money)
    if A[i] > A[i+1]: #売る
        money += sell(A[i], have_kabu)
        have_kabu = 0
money += sell(A[-1], have_kabu)        
print(money)

Submission status: Wrong Answer

Solution code:
def sell(rate,kabu):
    money = rate * kabu
    return money
    
def buy(rate,money):
    kabu = money//rate
    otsuri = money % rate
    return kabu,otsuri
    
N,*A = map(int,open(0).read().split())
before_money = 1000
have_money = 1000
have_kabu = 0
for i in range(N-1):
    if A[i] < A[i+1]: #買う
        before_money = max(before_money,have_money)
        have_kabu,have_money = buy(A[i],have_money)
    if A[i] > A[i+1]: #売る
        before_money = have_money
        have_money += sell(A[i],have_kabu)
        have_kabu = 0
have_money += sell(A[-1],have_kabu)        
print(max(before_money,have_money))

Submission status: Wrong Answer

Solution code:
def sell(rate,kabu):
    money = rate * kabu
    return money
    
def buy(rate,money):
    kabu = money//rate
    otsuri = money % rate
    return kabu,otsuri
    
N,*A = map(int,open(0).read().split())
before_money = 1000
have_money = 1000
have_kabu = 0
for i in range(N-1):
    if A[i] < A[i+1]: #買う
        before_money = have_money
        have_kabu,have_money = buy(A[i],have_money)
    if A[i] > A[i+1]: #売る
        before_money = have_money
        have_money += sell(A[i],have_kabu)
        have_kabu = 0
have_money += sell(A[-1],have_kabu)        
print(max(before_money,have_money))

Submission status: Wrong Answer

Solution code:
# D - Road to Millionaire
def good_time_to_sell(price):
  global stock
  global purchase_price
  global A
  
  if stock > 0:
    if purchase_price < price:
      if max(A) < price:
        return True
      else:
        is_down = False
    
        for a in A:
          if a < price:
            is_down = True
          elif price < a and is_down:
            return True
    
  return False


def sell(price):
  global money
  global stock
  
  money += price * stock
  stock = 0


def good_time_to_buy(price):
  global money
  global A
  
  if price <= money:
    if price < min(A):
      return True
    else:
      for a in A:
        if a < price:
          return False
        elif price < a:
          return True
  
  return False


def buy(price):
  global money
  global stock

  stock += money // price
  money %= price


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

money = 1000
stock = 0
purchase_price = 0

for i in range(N):
  a = A.pop(0)
  
  if i == N - 1:
    sell(a)
  elif good_time_to_sell(a):
    sell(a)
  elif good_time_to_buy(a):
    buy(a)
    purchase_price = a

print(money)

Submission status: Wrong Answer

Solution code:
def sell(rate,kabu):
    money = rate * kabu
    return money
    
def buy(rate,money):
    kabu = money//rate
    otsuri = money % rate
    return kabu,otsuri
    
N,*A = map(int,open(0).read().split())
before_money = 1000
have_money = 1000
have_kabu = 0
for i in range(N-1):
    if A[i] < A[i+1]: #買う
        before_money = have_money
        have_kabu,have_money = buy(A[i],have_money)
    if A[i] > A[i+1]: #売る
        before_money = have_money
        have_money += sell(A[i],have_kabu)
have_money += sell(A[-1],have_kabu)        
print(max(before_money,have_money))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def function(N, A):
    money = 1000
    kabu = 0
    for i in range(N-1):
        if (i == 0) & (A[0] < A[1]):
            kabu = int(1000/A[0])
            money = 1000-kabu*A[0]
        elif (A[i] < A[i+1]):
            kabu = int(money/A[i])
            money = money-kabu*A[i]
        elif (A[i-1] <= A[i]) & (A[i] > A[i+1]):
            money = money+kabu*A[i]
            kabu = 0
    print(money+kabu*A[N-1])


if __name__ == '__main__':
    N = int(input())
    A = input().split()
    A = [int(a) for a in A]
    function(N, A)

Submission status: Wrong Answer

Solution code:
def function(N, A):
    money = 1000
    kabu = 0
    for i in range(N-1):
        if (i == 0) & (A[0] < A[1]):
            kabu = int(1000/A[0])
            money = 1000-kabu*A[0]
        elif (A[i] <= A[i+1]):
            kabu = int(money/A[i])
            money = money-kabu*A[i]
        elif (A[i] > A[i+1]):
            money = money+kabu*A[i]
            kabu = 0
    print(money+kabu*A[N-1])


if __name__ == '__main__':
    N = int(input())
    A = input().split()
    A = [int(a) for a in A]
    function(N, A)

Submission status: Wrong Answer

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

dp = [1000]
K = [0]
C = [0]

for i in range(N):
    k, c = divmod(dp[-1], A[i])
    v = max(dp[-1], K[-1] * A[i] + C[-1])

    K.append(k)
    C.append(c)
    dp.append(v)

print(dp[-1])

Submission status: Wrong Answer

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

sa=[a[i+1]-a[i] for i in range(n-1)]
hr=0
for i in range(n-1):
    if hr ==0:
        if sa[i]>0:
            kabu += kane//a[i]
            kane=kane%a[i]
            hr=1
        elif sa[i]==0:
            hr=0
        else:
            kane+=kabu*a[i]
            kabu=0
            hr=2
    elif hr==1:
        if sa[i]>0:
            hr=1
        elif sa[i]==0:
            hr=0
        else:
            kane +=kabu*a[i]
            kabu=0
            hr=1
    else:
        if sa[i]>0:
            kabu += kane//a[i]
            kane=kane%a[i]
            hr=1
        elif sa[i]==0:
            hr=0
        else:
            hr=2

print(kane+kabu*a[n-1])

Submission status: Wrong Answer

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

for i in range(N):
    if i == N - 1:
        if stock > 0:
            cMoney += A[i] * stock
            stock = 0
        continue

    if A[i] >= A[i+1]:
        if stock > 0:
            cMoney += A[i] * stock
            stock = 0
    else:
        stock = cMoney // A[i]
        cMoney -= stock * A[i]

print(cMoney)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split())) + [0]
kabu = 0
money = 1000

for p in range(N):
    #株がない時
    if A[p] < A[p+1]:
        kabu = money//A[p]
        money -= kabu*A[p]
    
    #株があるとき
    elif A[p] > A[p+1]:
        money += kabu*A[p]
        kabu = 0

print(money)

Submission status: Wrong Answer

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

sa=[a[i+1]-a[i] for i in range(n-1)]
hr=0
for i in range(n-1):
    if hr ==0:
        if sa[i]>0:
            kabu = kane//a[i]
            kane=kane%a[i]
            hr=1
        elif sa[i]==0:
            hr=0
        else:
            kane+=kabu*a[i]
            kabu=0
            hr=2
    elif hr==1:
        if sa[i]<0:
            kane +=kabu*a[i]
            kabu=0
            hr=2
        elif sa[i]==0:
            hr=0
        else:
            hr=1
    else:
        if sa[i]>0:
            kabu = kane//a[i]
            kane=kane%a[i]
            hr=1
        elif sa[i]==0:
            hr=0
        else:
            hr=2

print(kane+kabu*a[n-1])

Submission status: Wrong Answer

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

sa=[a[i+1]-a[i] for i in range(n-1)]
hr=0
for i in range(n-1):
    if hr ==0:
        if sa[i]>0:
            kabu = kane//a[i]
            kane=kane%a[i]
            hr=1
        elif sa[i]==0:
            hr=0
        else:
            kane+=kabu*a[i]
            hr=2
    elif hr==1:
        if sa[i]<0:
            kane +=kabu*a[i]
            kabu=0
            hr=2
        elif sa[i]==0:
            hr=0
        else:
            hr=1
    else:
        if sa[i]>0:
            kabu = kane//a[i]
            kane=kane%a[i]
            hr=1
        elif sa[i]==0:
            hr=0
        else:
            hr=2

print(kane+kabu*a[n-1])

Submission status: Wrong Answer

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

sa=[a[i+1]-a[i] for i in range(n-1)]
hr=0
for i in range(n-1):
    if hr ==0:
        if sa[i]>0:
            kabu = kane//a[i]
            kane=kane%a[i]
            hr=1
        elif sa[i]==0:
            hr=0
        else:
            kane+=kabu*a[i]
            hr=2
    elif hr==1:
        if sa[i]<0:
            kane +=kabu*a[i]
            hr=2
        elif sa[i]==0:
            hr=0
        else:
            hr=1
    else:
        if sa[i]>0:
            kabu = kane//a[i]
            kane=kane%a[i]
            hr=1
        elif sa[i]==0:
            hr=0
        else:
            hr=2

print(kane+kabu*a[n-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
I=list(map(int,input().split()))
num=1000
for i in range(n-1):
    if I[i]<I[i+1]:
        num-=(num//I[i])*I[i]
        num+=(num//I[i])*I[i+1]

print(num)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# D - Road to Millionaire
def is_time_to_sell(price):
  global A
  global purchase_price
  
  if purchase_price < price:
    if max(A) < price:
      return True
    else:
      is_down = False
    
      for a in A:
        if a < price:
          is_down = True
        elif price < a and is_down:
          return True
    
      return False


def sell(price):
  global money
  global stock
  
  money += price * stock
  stock = 0


def is_time_to_buy(price):
  global money
  global A
  
  if price <= money:
    if price < min(A):
      return True
    else:
      for a in A:
        if a < price:
          return False
        elif price < a:
          return True


def buy(price):
  global money
  global stock

  stock += money // price
  money %= price


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

money = 1000
stock = 0
purchase_price = 0

for i in range(N):
  a = A.pop(0)
  
  if i == N - 1:
    sell(a)
  elif is_time_to_sell(a):
    sell(a)
  elif is_time_to_buy(a):
    buy(a)
    purchase_price = a

print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = list(map(int, input().split()))
dp = [1000]*N
for i in range(1,N):
    dp[i] = max((dp[i-1]//arr[i-1])*arr[i]+dp[i-1]%arr[i-1],dp[i-1])
print(dp)

Submission status: Wrong Answer

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

dp=[0]*(n+1)
dp[0] = 1000

for i in range(1,n):
  dp[i]=dp[i-1]
  for j in range(i-1):
    v = dp[j] // a[j]
    w = dp[j] + (a[i]-a[j])*v
    dp[i] = max(dp[i],w)
print(dp[n-1])

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(money,n,"chance",A[n],min(A[count:n+1]),previous_tendency, current_tendency)
        money += (money//min(A[count:n+1]))*(A[n]-min(A[count:n+1]))
        print(A[count:n+1],money)
        count = n + 1
        previous_tendency = "remain"
    #print(A[n],max_price,min_price,previous_tendency,current_tendency)
    
    if current_tendency != "remain":
      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
 


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(A[count:n+1],money)
        count = n + 1
        previous_tendency = "remain"
    #print(A[n],max_price,min_price,previous_tendency,current_tendency)
    
    #if current_tendency != "remain":
    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
 

 
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(A[count:n+1],money)
        count = n + 1
        previous_tendency = "remain"
    #print(A[n],max_price,min_price,previous_tendency,current_tendency)
    
    if current_tendency != "remain":
      previous_tendency = current_tendency
print(money)

Submission status: Wrong Answer

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

res = 1000

for i in range(n):
    tmp = 1000
    s = 0
    flag = 1
    price = 300
    for j in range(i, n):
        if flag and price > a[j]:
            s = tmp//a[j]
            tmp -= a[j]*s
            price = a[j]
            flag = 0
        elif flag == 0 and price < a[j]:
            tmp += a[j]*s
            s = 0
            price = a[j]
            flag = 1
        res = max(tmp, res)

print(res)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.append(0)
money=1000
buy=0
flag=0
for i in range(N):
    if A[i]<A[i+1]:
        buy=A[i]
        flag=1
    elif A[i]>A[i+1] and flag==1:
        b=money//buy
        money=money%buy+A[i]*b
        flag=0
print(money)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
money=1000
buy=201
for i in range(N):
    a=A[i]
    if buy>=a:
        buy=a
    else:
        b=money//buy
        money=money%buy+a*b
        buy=201
print(money)

Submission status: Wrong Answer

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

m = 1000
k = 0
up = False
down = False

for i in range(n-1):
  to = i+1
  if a[i] == a[to]:
    continue
  if a[i] > a[to]:
    while to+1 < n and a[to] < a[to+1]:
      to += 1
      
    if to == n-1:
      break
    i = to - 1
  else:
    while to+1 < n and a[to] < a[to+1]:
      to += 1
      
    k = m // a[i]
    m = m - k*a[i] + k*a[to]
    
    i = to - 1
    
print(m)

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 -= S*A[i]
  elif A[i]>A[i+1]:
    M += S*A[i]
    S = 0
M+=A[-1]*S
print(M)

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 -= S*A[i]
  elif A[i]>A[i+1]:
    M += S*A[i]
    S = 0
  print(M,S)
M+=A[-1]*S
print(M)

Submission status: Wrong Answer

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

kane=1000
kabu =0
sa=[a[i+1]-a[i] for i in range(n-1)]

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

print(kane+kabu*a[n-1])

Submission status: Wrong Answer

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

stock = 0
money = 1000

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

money += stock * a[n-1]

print(money)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
S = 1000
K = 0
b = 1
last = 0
			
for i in range(N):


	if i != N-1:
		if a[i]<a[i+1]:
			K = S // a[i]
			S -= K*a[i]
		elif a[i]==a[i+1]:
			pass
		else:
			S += a[i]*K
			K = 0
	else:

		S += a[i]*K
print(S)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
S = 1000
K = 0
b = 1
last = 0
			
for i in range(N):
	print(S)

	if i != N-1:
		if a[i]<a[i+1]:
			K = S // a[i]
			S -= K*a[i]
		elif a[i]==a[i+1]:
			pass
		else:
			S += a[i]*K
			K = 0
	else:

		S += a[i]*K
print(S)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
S = 1000
K = 0
b = 1
last = 0
			
for i in range(N):
	if i != N-1:
		if a[i]<=a[i+1]:
			K = S // a[i]
			S -= K*a[i]

		else:
			S += a[i]*K
			K = 0
	else:

		S += a[i]*K
print(S)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
S = 1000
K = 0
b = 1
last = 0
			
for i in range(N):
	if i != N-1:
		if a[i]<=a[i+1]:
			K = S // a[i]
			S -= K*a[i]
			last = i
		if a[i]>a[i+1]:
			S += a[i]*K
			K = 0
	else:
		if a[i]<=a[last]:
			S += a[last]*K
		else:
			S += a[i]*K
print(S)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
S = 1000
K = 0

			
for i in range(N):
	if i != N-1:
		if a[i]<=a[i+1]:
			K = S // a[i]
			S -= K*a[i]
		if a[i]>a[i+1]:
			S += a[i]*K
			K = 0
	else:
		S += a[i]*K
print(S)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
S = 1000
K = 0

for i in range(N):
	if i != N-1:
		if a[i]<=a[i+1]:
			K = S // a[i]
			S -= K*a[i]
		if a[i]>a[i+1]:
			S += a[i]*K
	else:
		S += a[i]*K
print(S)

Submission status: Wrong Answer

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

money = 1000
stocks = 0

for n in range(N-1):
  if A[n] < A[n+1]:
    stocks = money//A[n]
    money -= (money//A[n])*A[n]
  elif A[n] > A[n+1]:
    money += stocks*A[n]
    stocks = 0
money += stocks * A[-1]
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

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)