N=int(input()) A=list(map(int,input().split())) tmp=[] cnt=0 for i in range(N-2): a=A[i] b=A[i+1] c=A[i+2] tmp=[a,b,c] tmp.sort(reverse=True) if (tmp[1]==a or tmp[1]==c) and (a!=b and b!=c and c!=a): cnt+=1 print(cnt)