N = int(input()) A = list(map(int, input().split())) def kado(a, b, c): if len(set([a, b, c])) != 3: return False m = sorted([a, b, c])[1] if a == m or c == m: return True return False ans = 0 for i in range(N - 2): ans += int(kado(*A[i:i+3])) print(ans)