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