1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import sys

def run(a,n,d):
    x = a[0]
    t = 0
    for i in range(1, n):        
        y = a[i]
        if d > 0 and y <= x:
            x = 1000001+i
            t +=1 
        elif d < 0 and y >= x:
            x = -1000001-i
            t +=1
        else:
            x = y
        d = -d
    return t

lines = sys.stdin.read().splitlines()
n = int(lines[0])
a = [int(s) for s in lines[1].split()]
t1 = run(a,n,1)
t2 = run(a,n,-1)
sys.stdout.write(str(min(t1,t2))+"\n")