N = int(input()) A = list(map(int, input().split())) count = 0 for i in range(3, N + 1): k = A[i-3:i] sk = sorted(k) if k.index(sk[1]) % 2 == 0 and len(set(k)) == len(k): count += 1 print(count)