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