n = int(input()) a = [int(i) for i in input().split()] count = 0 for i in range(n-2): x = a[i] y = a[i+1] z = a[i+2] if x != y and y != z and z != x: if y == max(x,y,z) or y == min(x,y,z): count += 1 print(count)