# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def create_peaks(A):
N = len(A)
peaks = [False] * N
for i in range(1, N-1):
if A[i] > max(A[i-1],A[i+1]):
peaks[i] = True
return peaks
def next_peak(A):
N, peaks = len(A), create_peaks(A)
next = [0] * N
next[N-1] = -1
for i in range(N-2,-1,-1):
if peaks[i]:
next[i] = i
else:
next[i] = next[i+1]
return next
def solution(A):
# write your code in Python 3.6
N, next = len(A), next_peak(A)
i, result = 1, 0
while (i-1)*i <= N:
pos, num = 0, 0
while pos < N and num < i:
pos = next[pos]
if pos == -1:
break
num += 1
pos += i
result = max(result, num)
i += 1
return result