n = int(input()) a = list(map(int, input().split())) count = 0 for i in range(n - 2): x, y, z = a[i], a[i+1], a[i+2] if len({x, y, z}) != 3: continue sorted_three = sorted([x, y, z], reverse=True) mid = sorted_three[1] if mid == x or mid == z: count += 1 print(count)