class Problem0116: def solve(this): n = int(input()) a = list(map(int, input().split())) res = 0 for i in range(len(a) - 2): c = a[i:i+3] if len(c) != len(set(c)): continue if c[0] < c[1] and c[2] < c[1] or c[1] < c[0] and c[1] < c[2]: res += 1 print(res) if __name__ == "__main__": problem = Problem0116() problem.solve()