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