n=int(input()) a=list(map(int,input().split())) ct=0 for i in range(n-2): x=a[i];y=a[i+1];z=a[i+2] l=[x,y,z] l.sort() if x!=y and y!=z and z!=x and (l[1]==x or l[1]==z): ct+=1 print(ct)