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 = [int(e) for e in input().split()]

#極大・極小のところのみを取り出す
compressed_A = list()
compressed_A.append(A_list[0])
for i in range(1,N-1):
    if A_list[i-1] <= A_list[i] >= A_list[i+1] or A_list[i-1] >= A_list[i] <= A_list[i+1]:
        compressed_A.append(A_list[i])
        
if len(compressed_A)>=2:
    if compressed_A[-2] <= compressed_A[-1] < A_list[-1]:
        compressed_A.pop(-1)
        compressed_A.append(A_list[-1])
else:
    compressed_A.append(A_list[-1])
    
#重複の削除
more_compressed_A = list()
for i in range(len(compressed_A)-1):
    if compressed_A[i] != compressed_A[i+1]:
        more_compressed_A.append(compressed_A[i])
if compressed_A[-2] != compressed_A[-1]:
    more_compressed_A.append(compressed_A[-1])

#実際に売買する
money = 1000
for i in range(len(more_compressed_A)-1):
    if more_compressed_A[i] < more_compressed_A[i+1]:
        money += (more_compressed_A[i+1]-more_compressed_A[i])*(money//more_compressed_A[i])

print(money)

Submission status: Wrong Answer

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

flag = [-1]*n
t = 1
for i in range(n-1, -1, -1):
  if t == 1:
    if a[i-1] < a[i]:
      flag[i] = t
      t = 0
  else:
    if a[i] < a[i-1]:
      flag[i] = t
      t = 1
    
t = 0
s = 0
ans = 1000
for i in range(n):
  if flag[i] == 0:
    t = 1-t
    s = ans//a[i]
    ans %= a[i]
  elif flag[i] == 1:
    t = 1-t
    ans += s*a[i]
    s = 0
print(ans)

Submission status: Wrong Answer

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

flag = [-1]*n
t = 1
for i in range(n-1, -1, -1):
  if t == 1:
    if a[i-1] < a[i]:
      flag[i] = t
      t = 0
  else:
    if a[i] < a[i-1]:
      flag[i] = t
      t = 1
      
t = 0
s = 0
ans = 1000
for i in range(n):
  if t == 0 and t == flag[i]:
    t = 1-t
    s = ans//a[i]
    ans %= a[i]
  elif t == 1 and t == flag[i]:
    t = 1-t
    ans += s*a[i]
    s = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 1000
stock = 0

for i, a in enumerate(A):
    if i > 0 and i < N + 1:
        if A[i-1] > a and A[i+1] >= a:
            stock += ans // a
            ans -= a * (ans // a)

        if A[i-1] < a and A[i+1] <= a:
            ans += stock * a
            stock = 0
        
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    a = LI()

    money = 1000
    mn, mx = a[0], a[0]
    up = True

    for price in a:
        if mx <= price:
            up = True
            mx = price
        else:
            if up:
                money = money//mn * mx
            up = False
            mn, mx = price, price

    money = money//mn * mx
    
    print(money)
            

main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    A = list(map(int,input().split()))
    kabu = 0
    kane = 1000
    for i in range(n-1):
        if A[i+1] > A[i]:
            kabu = kane // A[i]
            kane %= A[i]
        elif A[i+1] < A[i]:
            kane += kabu * A[i]
            kabu = 0
    kane += kabu * A[n-1]
    print(kane)

if __name__=='__main__':
    main()

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 = dp[-1]
    for j in range(i):
        u = K[j] * A[i] + C[j]
        v = max(u, v)
    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()))
dp = [0]*(n)
dp[0] = 1000

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

print(dp[n-1])

Submission status: Wrong Answer

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

buy, sell = [], []
for i in range(n):
    if a[i] < a[i+1]:
        buy.append(i)
    if buy != [] and a[i] > a[i+1]:
        sell.append(i)

cash = 1000
for i, j in zip(buy, sell):
    stock, rest = divmod(cash, a[i])
    cash = stock * a[j] + rest

print(cash)

Submission status: Wrong Answer

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

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

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

print(dp[-1])

Submission status: Wrong Answer

Solution code:
from sys import stdin
inp = lambda : stdin.readline().strip()

n= int(inp())
prices = [int(x) for x in inp().split()]

money= 1000
buy = -1
if prices[0] <=money: 
    buy = prices[0]
for i in range(1, len(prices)):
    if prices[i] > prices[i - 1]:
        if buy != -1:
            money = money%buy + (money//buy)*prices[i]
    else:
        if prices[i] < buy and prices[i] < money:
            buy = prices[i]
print(money)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
A = list(readInts())
ln = len(A)
i = 1
ans = 1000
money = 1000
kabu = 0
prv = A[0]
while i < ln:
    #print(prv)
    if prv < A[i]:
        kabu += money//prv
        money -= prv * kabu
    else:
        money += kabu * prv
        kabu = 0
        ans = max(money, ans)
    prv = A[i]
    i += 1
print(max(money + kabu * prv, ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
c = 1000  # cash
s = 0  # stock
up = False
for i in range(n-1):
    if A[i] < A[i+1]:
        if not up:
            s, c = divmod(c, A[i])
            up = True
            print(A[i], c, s)
    elif A[i] > A[i+1]:
        if up:
            c += s * A[i]
            s = 0
            up = False
            print(A[i], c, s)
    else:
        pass
else:
    c += s * A[-1]
print(c)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
A.append(0)
L=[[0]*2 for _ in range(N+1)]
L[0][0]=1000

# 下がり切ったら全買い 上がりきったら全売り
for i in range(1,N+1):
    if A[i-1]<A[i]:
        n=L[i-1][0]//A[i-1] + L[i-1][1]
        L[i][0]=L[i-1][0]-n*A[i-1]
        L[i][1]=n
    elif A[i-1]>A[i]:
        L[i][0]=L[i-1][0]+L[i-1][1]*A[i-1]
    else:
        L[i][0]=L[i-1][0]
        L[i][1]=L[i-1][1]
# print(A)
# print(L)
print(L[N][0])

Submission status: Wrong Answer

Solution code:
days = int(input())
price = list(map(int,input().split()))
money = 1000
stock = 0

for i in range(days - 1):
  if price[i] < price[i + 1]:
    new = (money // price[i])
    stock += new
    money -= (new * price[i])
    
  else:
    money += stock * price[i]
    stock = 0
  print(money,stock) 
print(money + stock * price[-1])

Submission status: Wrong Answer

Solution code:
days = int(input())
price = list(map(int,input().split()))
money = 1000
stock = 0

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

Submission status: Wrong Answer

Solution code:
days = int(input())
price = list(map(int,input().split()))
money = 1000
stock = 0

for i in range(days - 1):
  if price[i] < price[i + 1]:
    stock += (money // price[i])
    money -= (stock * price[i])
    
  elif price[i] > price[i + 1]:
    money += stock * price[i]
    stock = 0
  
  else:
    pass
print(money + stock * price[-1])

Submission status: Wrong Answer

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()+[0]

money=1000
ans=1000
kabu=0

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

print(money)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()+[0]

money=1000
ans=1000
kabu=0

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

  ans=max(ans,money)

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()+[0]

money=1000
ans=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

  ans=max(ans,money)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
money = 1000
cnt = 0
x = ""
b = ""
for a in A:
    if b == "": b = a
    else:
        if b == a: continue
        else: b = a
    
    if x != "" and a < x:
        money += cnt * x
        cnt = 0
        x = ""

    if x == "":
        cnt = money//a
        money -= cnt * a
        x = a
    else:
        if a > x:
            money += cnt * a
            cnt = 0
            x = ""
if cnt > 0: money += cnt * x
print(money)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
money = 1000
cnt = 0
x = ""
b = ""
for a in A:
    if b == "": b = a
    else:
        if b == a: continue
        else: b = a

    if x == "":
        cnt = money//a
        money -= cnt * a
        x = a
    else:
        if a > x:
            money += cnt * a
            cnt = 0
            x = ""
if cnt > 0: money += cnt * x
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])*A[i]
  else:
    m +=s*A[i+1]
    s = 0
if 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 -= (m//A[i])*A[i]
  else:
    m +=s*A[i+1]
    s = 0
if s>0:
  m+=A[-1]*s
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
zandaka = 1000
kabu = 0
mode = 0

for i in range(N):
  if i == 0:
    if A_list[i + 1] > A_list[i]:
      kabu = 1000 // A_list[i]
      zandaka -= kabu * A_list[i]
      mode = 1
    else:
      continue
  elif i == N - 1:
    zandaka += kabu * A_list[i]
  else:
    if mode == 1:
      if A_list[i] >= A_list[i - 1]:
        zandaka += kabu * A_list[i]
        kabu = 0
        mode = 0
      else:
        continue
    else:
      if A_list[i] < A_list[i + 1]:
        kabu = zandaka // A_list[i]
        zandaka -= kabu * A_list[i]
        mode = 1
      else:
        continue

if zandaka >= 1000:
  print(zandaka)
else:
  print(1000)

Submission status: Wrong Answer

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

m=1000

if A[0]<max(A[1:]):
    tmp = A[0]
    stock=m//A[0]
    m-=A[0]*stock
    
    for i,ai in enumerate(A[1:]):
        if tmp>ai:
            m+=tmp*stock
            stock=0
            if ai < max(A[i:]):
                stock=m//ai
                m-=ai*stock
        tmp = ai
    print(m+stock*A[-1])
else:
    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(1, N):
  if A[i-1] < A[i]:
    if S == 0:
      S = M // A[i-1]
      M = M % A[i-1]
      if i == N-1:
        M += S * A[i]
  elif A[i-1] > A[i]:
    if S > 0:
      M += S * A[i-1]
      S = 0  
print(M)

Submission status: Wrong Answer

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

for i in range(1, N):
  if A[i-1] < A[i]:
    K = M // A[i-1]
    M = M % A[i-1]
    if i == N-1:
      M += K * A[i]
  elif A[i-1] > A[i]:
    if K > 0:
      M += K * A[i-1]
      K = 0  
print(M)

Submission status: Wrong Answer

Solution code:
import copy, sys
n = int(input())
a_ls = list(map(int, input().split()))
b_ls = []
for i in range(n-1):
    if a_ls[i] != a_ls[i+1]:
        b_ls.append(a_ls[i])
if a_ls[-1] != a_ls[-2]:
    b_ls.append(a_ls[-1])
if not b_ls:
    print(1000)
    sys.exit()
c_ls = [b_ls[0]]
for i in range(1,len(b_ls)-1):
    if not (b_ls[i-1] < b_ls[i] < b_ls[i+1] or b_ls[i-1] > b_ls[i] > b_ls[i+1]):
        c_ls.append(b_ls[i])
c_ls.append(b_ls[-1])
money = 1000
stock = 0
m = len(c_ls)
for i in range(m-1):
    if c_ls[i] > c_ls[i+1]:
        money += c_ls[i] * stock
        stock = 0 
    else:  
        if money > 0:
            stock, money = divmod(money, c_ls[i])
if len(c_ls) > 1 and c_ls[-1] > c_ls[-2]:
    money += c_ls[-1] * stock
print(money)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
# init
tmp = a[0]
bit_buy = 1
init_bit = 1
money = 1000
ans = money
stock_num = 0
for i in range(1, n):
    if bit_buy and a[i] > a[i - 1]:
        # a[i-1] で現在の所持金で変えるだけ買う
        # ただし最後は買わない。
        stock_num = money // a[i - 1]
        money = money - stock_num * a[i - 1]
        tmp = a[i - 1]
        bit_buy = 0
        init_bit = 0
    if (init_bit and i == n - 1) or (bit_buy == 0 and (a[i] < a[i - 1])):
        # 全部うる
        money += stock_num * a[i - 1]
        ans = max(ans, money)
        bit_buy = 1
        stock_num = 0
    print(i, a[i], money)
money += stock_num * tmp
ans = max(ans, money)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.append(0)
m = 1000
s = 0

for i in range(n):
    if a[i] < a[i + 1]: #翌日上がるなら最大限買う
        s = m//a[i]
        m -= a[i]*s
    else:               #翌日同じか下がるなら全て売る
        m += a[i]*s
        s = 0

print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.append(0)
m = 1000
s = 0

for i in range(n):
    if a[i] < a[i + 1]:
        s = m//a[i]
        m = m - a[i]*s
    else:
        m = m + a[i]*s
        s = 0

print(m)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
dp = [0]*(N+1)
dp[0] = 1000

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

print(max(dp))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
n = int(input())
a = list(map(int, input().split()))

money = 1000
kabu = 0 

for i in range(n-1):
    s = a[i]
    t = a[i+1]
    if s < t:
        k = money//s
        money %= s
        money += k*t 
        print('i =', i)
        print('money =', money)

print(money)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
n = int(input())
given_a = list(map(int, input().split()))

a = []
for k in given_a:
    if len(a) > 0 and a[-1] == k:
        continue
    else:
        a.append(k)

money = 1000
kabu = 0 

n = len(a)

if n == 1:
    print(money)
    exit()

for i in range(n):
    if n == 0:
        if a[i] > a[i+1]:
            continue
        else:
            kabu += money//a[i]
            money %= a[i]
    elif i == n-1:
        money += kabu*a[i]
        kabu = 0 
    else:
        if a[i] > a[i-1] and a[i] > a[i+1]:
            money += kabu*a[i]
            kabu = 0 
        if a[i] < a[i-1] and a[i] < a[i+1]:
            kabu += money//a[i]
            money %= a[i]

print(money)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
n = int(input())
given_a = list(map(int, input().split()))

a = []
for k in given_a:
    if len(a) > 0 and a[-1] == k:
        continue
    else:
        a.append(k)

money = 1000
kabu = 0 

n = len(a)

if n == 1:
    print(money)
    exit()

for i in range(n):
    if n == 0:
        if a[i] > a[i+1]:
            continue
        else:
            kabu += money//a[i]
            money %= a[i]
    elif i == n-1:
        money += kabu*a[i]
        kabu = 0 
    else:
        if a[i] > a[i-1] and a[i] > a[i+1]:
            money += kabu*a[i]
            kabu = 0 
        elif a[i] < a[i-1] and a[i] < a[i+1]:
            kabu += money//a[i]
            money %= a[i]

print(money)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
n = int(input())
given_a = list(map(int, input().split()))

a = []
for k in given_a:
    if len(a) > 0 and a[-1] == k:
        continue
    else:
        a.append(k)

money = 1000
kabu = 0 

n = len(a)
for i in range(n):
    if n == 0:
        if a[i] > a[i+1]:
            continue
        else:
            kabu += money//a[i]
            money %= a[i]
    elif i == n-1:
        money += kabu*a[i]
        kabu = 0 
    else:
        if a[i] > a[i-1] and a[i] > a[i+1]:
            money += kabu*a[i]
            kabu = 0 
        elif a[i] < a[i-1] and a[i] < a[i+1]:
            kabu += money//a[i]
            money %= a[i]

print(money)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    *A, = map(int, input().split())

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

    for i, a in enumerate(A):
        dp[i + 1] = dp[i]
        for j in range(i):
            buy, rest = divmod(dp[j], A[j])
            dp[i + 1] = max(dp[i], buy * A[i] + rest)

    print(dp[-1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
stocks = [int(x) for x in input().split()]
mymoney = 1000
mystock = 0

for i in range(0,len(stocks)-1):     # コメントアウト部分はデバッグ用コード
      #print(stocks[i],stocks[i+1],end=":")
      if stocks[i] < stocks[i+1]:    # 明日の方が株価が高くなる場合は、今日のうちに株を買えるだけ買う
            #print("buying",end=" ")
            mystock = mymoney//stocks[i]
            mymoney = mymoney%stocks[i]
      elif stocks[i] >= stocks[i+1]:  # 明日の方が株価が安くなる場合には、今日のうちに手持ちの株を売却
            #print("selling",end=" ")
            mymoney += mystock*stocks[i]
            mystock = 0
      #print(mymoney,mystock)

i += 1
mymoney += mystock * stocks[i]      # 最終日に手持ちの株をすべて売却して現金化
mystock = 0

print(mymoney)

Submission status: Wrong Answer

Solution code:
n = int(input())
stocks = [int(x) for x in input().split()]
mymoney = 1000
mystock = 0

for i in range(0,len(stocks)-1):     # コメントアウト部分はデバッグ用コード
      #print(stocks[i],stocks[i+1],end=":")
      if stocks[i] < stocks[i+1]:    # 明日の方が株価が高くなる場合は、今株を買えるだけ買う
            #print("buying",end=" ")
            mystock = mymoney//stocks[i]
            mymoney -= mystock*stocks[i]
      elif stocks[i] > stocks[i+1]:  # 明日の方が株価が安くなる場合には、今日のうちに手持ちの株を売却
            #print("selling",end=" ")
            mymoney += mystock*stocks[i]
            mystocks = 0
      else:
            #print("through",end=" ")
            continue
      #print(mymoney,mystock)

i += 1
mymoney += mystock * stocks[i]      # 最終日に手持ちの株をすべて売却して現金化
mystocks = 0

print(mymoney)

Submission status: Wrong Answer

Solution code:
num = int(input())
kabu = [int(x) for x in input().split()]
kabu.append(-1)
mkabu = 0
max = 0
money = 1000
MAX = 0
 
for i in range(num):
    if MAX < kabu[i]:
        MAX = kabu[i]
 
 
for i in range(num):
    if kabu[i] == -1:
        bleak
    if max < kabu[i]:
        max = kabu[i]
    if kabu[i+1] < max or kabu[i] == MAX: #売る
        money = money + kabu[i] * mkabu
        mkabu = 0
#        print("売る", money)
#    print("MAX", max)
    if max < kabu[i+1]: #買う
        mkabu = money // kabu[i]
        money = money % kabu[i]
#        print("買う", money)
 
if 0 < mkabu:
    money = money + kabu[-1] * mkabu
 
print(money)

Submission status: Wrong Answer

Solution code:
num = int(input())
kabu = [int(x) for x in input().split()]
kabu.append(-1)
mkabu = 0
max = 0
money = 1000
MAX = 0

for i in range(num):
    if MAX < kabu[i]:
        MAX = kabu[i]


for i in range(num):
    if kabu[i] == -1:
        bleak
    if max < kabu[i]:
        max = kabu[i]
    if kabu[i+1] < max or kabu[i] == MAX: #売る
        money = money + kabu[i] * mkabu
        mkabu = 0
#        print("売る", money)
#    print("MAX", max)
    if max < kabu[i+1]: #買う
        mkabu = money // kabu[i]
        money = money % kabu[i]
#        print("買う", money)


print(money)

Submission status: Wrong Answer

Solution code:
num = int(input())
kabu = [int(x) for x in input().split()]
kabu.append(-1)
mkabu = 0
max = 0
money = 1000
MAX = 0

for i in range(num):
    if MAX < kabu[i]:
        MAX = kabu[i]


for i in range(num):
    if kabu[i] == -1:
        bleak
    if max < kabu[i]:
        max = kabu[i]
    if max < kabu[i+1]: #買う
        mkabu = money // kabu[i]
        money = money % kabu[i]
#        print("買う", money)
    if kabu[i+1] < max or kabu[i] == MAX: #売る
        money = money + kabu[i] * mkabu
        mkabu = 0
#        print("売る", money)
#    print("MAX", max)

print(money)

Submission status: Wrong Answer

Solution code:
num = int(input())
kabu = [int(x) for x in input().split()]
kabu.append(-1)
mkabu = 0
max = 0
money = 1000
MAX = 0

for i in range(num):
    if MAX < kabu[i]:
        MAX = kabu[i]


for i in range(num):
    if kabu[i] == -1:
        bleak
    if max < kabu[i]:
        max = kabu[i]
    if max < kabu[i+1]: #買う
        mkabu = money // kabu[i]
        money = money % kabu[i]
#        print("買う", money)
    if kabu[i+1] < max: #売る
        money = money + kabu[i] * mkabu
        mkabu = 0
#        print("売る", money)
#    print("MAX", max)

print(money)

Submission status: Wrong Answer

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

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

print(money)

Submission status: Wrong Answer

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

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

    # 翌日のほうが安いならスキップ
    if i < N-2 and A[i] >= A[i+1]:
        continue

    # 翌日以降に値上がりするか
    for j in range(i+1, N):
        # 値上がりするなら買えるだけ買う
        if A[i] < A[j]:
            kabu = money//A[i]
            money -= (money//A[i])*A[i]

            # 売る日を求める
            for k in range(i+1, N):
                if A[k-1] <= A[k]:
                    sell = k
                else:
                    break
            break
print(money)

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

Submission status: Wrong Answer

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

print(mon)

Submission status: Wrong Answer

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

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

print(money)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = list(map(int, 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]
        elif A[i] > A[i + 1]:
            money += stock * A[i]
            stock = 0

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())  # N日間
A = list(map(int, input().split()))  # i日目の株の値段
money = 1000
stocks = 0
for i in range(N-1):
    # 次の日に上がるなら有り金全部株と交換する
    if A[i+1] > A[i]:
        # i日目に株を買う
        stocks = money // A[i]
        money -= (money // A[i])*A[i]
    # 次の日に下がる&今株を持っているのであれば，全部お金にする
    if A[i+1] < A[i] and stocks > 0:
        money += stocks*A[i]
        stocks = 0
print(money + stocks*A[-1])

Submission status: Wrong Answer

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

        except:
            if i==0:
                if a[i]<=a[i+1]:
                    stock+=money//a[i]
                    money%=a[i]
            else:
                money+=a[i]*stock
                stock=0
print(money)

Submission status: Wrong Answer

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

    except:
        if i==0:
            if a[i]<=a[i+1]:
                stock+=money//a[i]
                money%=a[i]
        else:
            money+=a[i]*stock
            stock=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] < a[1]:
    flg = 'kau'
else:
    flg = 'uru'
for i in range(1,n):
    if a[i-1] < a[i]:
        if flg == 'kau':
            kabu = money // a[i-1]
            money -= kabu * a[i-1]
            flg = 'uru'
    elif a[i-1] > a[i]:
        if flg == 'uru':
            money += kabu * a[i-1]
            kabu = 0
            flg = 'kau'
    else:
        pass
if kabu > 0:
    money += kabu * 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] < a[1]:
    flg = 'uru'
else:
    flg = 'kau'
for i in range(1,n):
    if a[i-1] < a[i]:
        if flg == 'uru':
            kabu = money // a[i-1]
            money -= kabu * a[i-1]
            flg = 'kau'
    elif a[i-1] > a[i]:
        if flg == 'kau':
            money += kabu * a[i-1]
            kabu = 0
            flg = 'uru'
    else:
        pass
if kabu > 0:
    money += kabu * a[-1]
print(money)

Submission status: Wrong Answer

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

money = 1000
stock = 0

stock += 1000//A[0]
money -= stock*A[0]

now = A[0]
for i in range(1,n):
    if i == n-1:
        money += A[i]*stock
        break
    if A[i] >= now:#上がったら、nowは買いのタイミングだった
        if stock == 0:
            stock += money//now
            money -= now*stock
        now = A[i]
    else:#下がったら、nowは売りのタイミングだった
        money += now*stock
        stock = 0
        now = A[i]
        
print(max(1000, money))