Problem:
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?

Incorrect submission (verdict: Wrong Answer):
import numpy as np
import itertools
#from scipy import signal


n = int(input())
ajs = input().split()
ajs = [int(aj) for aj in ajs]
ajs = np.array(ajs)

#actions = itertools.product([-1, 0, 1], repeat=n)
#for action in actions:

ajs_delta = ajs[1:] - ajs[:-1]
print(ajs_delta)
for i in range(1, ajs_delta.shape[0]):
  if ajs_delta[i] == 0:
    ajs_delta[i] = ajs_delta[i-1]
    
print(ajs_delta)
  
kyokuchi = {'lower':[], 'upper':[]}


first_value = 0
for aj_delta in ajs_delta:
  if aj_delta != 0:
    first_value = aj_delta
    break

if ajs_delta[0] > 0:
  kyokuchi['lower'].append(0)
elif ajs_delta[0] < 0:
  kyokuchi['upper'].append(0)
elif ajs_delta[0]  == 0 and first_value > 0:
  kyokuchi['lower'].append(0)

for i in range(0, ajs_delta.shape[0]-1):
  if ajs_delta[i] * ajs_delta[i+1] < 0:
    if ajs_delta[i] > 0:
      kyokuchi['upper'].append(i+1)
    else:
      kyokuchi['lower'].append(i+1)

if ajs_delta[-1] > 0:
  kyokuchi['upper'].append(n-1)
else:
  kyokuchi['lower'].append(n-1)


kyokuchi_s = sorted(kyokuchi['upper'] + kyokuchi['lower'])
  
current_money = 1000
pos = 0

for idx in kyokuchi_s:
  if pos >= 0:
    stock = int(current_money / ajs[idx])
    current_money = current_money % ajs[idx]
    pos = -1
  else:
    current_money += stock * ajs[idx]
    stock = 0
    pos = 1
    
print(current_money)

Fixed, accepted submission:
import numpy as np
import itertools
#from scipy import signal


n = int(input())
ajs = input().split()
ajs = [int(aj) for aj in ajs]
ajs = np.array(ajs)

#actions = itertools.product([-1, 0, 1], repeat=n)
#for action in actions:

ajs_delta = ajs[1:] - ajs[:-1]

for i in range(1, ajs_delta.shape[0]):
  if ajs_delta[i] == 0:
    ajs_delta[i] = ajs_delta[i-1]
    

  
kyokuchi = {'lower':[], 'upper':[]}


first_value = 0
for aj_delta in ajs_delta:
  if aj_delta != 0:
    first_value = aj_delta
    break

if ajs_delta[0] > 0:
  kyokuchi['lower'].append(0)
elif ajs_delta[0] < 0:
  #kyokuchi['upper'].append(0)
  pass
elif ajs_delta[0]  == 0 and first_value > 0:
  kyokuchi['lower'].append(0)

for i in range(0, ajs_delta.shape[0]-1):
  if ajs_delta[i] * ajs_delta[i+1] < 0:
    if ajs_delta[i] > 0:
      kyokuchi['upper'].append(i+1)
    else:
      kyokuchi['lower'].append(i+1)

if ajs_delta[-1] > 0:
  kyokuchi['upper'].append(n-1)
else:
  #kyokuchi['lower'].append(n-1)
  pass


kyokuchi_s = sorted(kyokuchi['upper'] + kyokuchi['lower'])

current_money = 1000
pos = 0

for idx in kyokuchi_s:
  if pos >= 0:
    stock = int(current_money / ajs[idx])
    current_money = current_money % ajs[idx]
    pos = -1
  else:
    current_money += stock * ajs[idx]
    stock = 0
    pos = 1
    
print(current_money)