N = int(input()) L = list(map(int, input().split())) C = 0 for i in range(N-2): X = L[i:i+3] if len(set(X)) == 3 and X[1] != sorted(X)[1]: C += 1 print(C)