N = int(input()) A = [int(i) for i in input().split()] t = 0 for i in range(2, N): if len(set(A[i-2:i+1])) == 3 and (A[i-1] == max(A[i-2:i+1]) or A[i-1] == min(A[i-2:i+1])): t += 1 print(t)