n,D,a=int(input()),list(map(int,input().split())),0 for i in range(n-2): A=D[i:i+3] a+=(len(set(A))==3)*(A[1]!=sorted(A)[1]) print(a)