1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
n = int(input())
lista = list(map(int, input().split()))
lista = lista + lista

l = [-1] * (2 * n)
stos = []

for i in range(2 * n):
    while stos and lista[stos[-1]] < lista[i]:
        stos.pop()
    if stos:
        l[i] = stos[-1]
    stos.append(i)

rekord = [0] * (n + 1)
for i in range(2 * n): 
    start_min = max(i - n + 1, l[i] + 1)
    start_max = i
    
    s_low = max(0, start_min)
    s_high = min(n - 1, start_max)
    if s_low <= s_high:
        rekord[s_low] += 1
        rekord[s_high + 1] -= 1

max_r = 0
akt_r = 0
for i in range(n):
    akt_r += rekord[i]
    if akt_r > max_r:
        max_r = akt_r
        
print(max_r)