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
34
35
36
37
n = int(input())
music = list(map(int, input().split(' ')))
minimum = -10**9
maximum = 10**9

count = 0
i = 0
while i < n:
    end = min(i + 3, n)
    triple = music[i:end]
    if len(triple) == 2 and triple[0] == triple[1]:
        count += 1
        triple[1] = maximum
        maximum -= 1
        music[i] = triple[0]
        music[i + 1] = triple[1]
    if len(triple) == 3:
        a, b, c = triple
        if a >= b:
            if b > c:
                count += 1
                triple[0] = minimum
                minimum += 1
            elif a == b or b == c:
                count += 1
                triple[1] = maximum
                maximum -= 1
        elif b <= c:
            count += 1
            triple[2] = minimum
            minimum += 1
        music[i] = triple[0]
        music[i + 1] = triple[1]
        music[i + 2] = triple[2]
    i += 1

print(count)