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)