# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def check(peaks, A, k):
start, i = 0, -1
while start < len(A):
end = start + k
while i < len(peaks) - 1:
i += 1
if start <= peaks[i] < end:
break
else:
return False
start += k
return True
def solution(A):
# write your code in Python 3.6
if len(A) < 3:
return 0
peaks = []
for i in range(len(A)-2):
if A[i] < A[i+1] and A[i+1] > A[i+2]:
peaks.append(i+1)
if len(peaks) == 0:
return 0
for i in range(len(peaks), 0, -1):
if len(A) % i == 0 and check(peaks, A, len(A)//i):
return i