N=int(raw_input()) A=map(int,raw_input().split()) ans=0 for i in range(len(A)-2): if A[i]A[i+2] and A[i]!=A[i+2]: ans+=1 if A[i]>A[i+1] and A[i+1]