n=int(input()) D=list(map(int,input().split())) ans=0 for i in range(n-2): a,b,c=D[i:i+3] # print(a,b,c) if len(set([a,b,c]))!=3:continue check=[a,b,c] mx=max([a,b,c]) mn=min([a,b,c]) check.remove(mx) check.remove(mn) if a==check[0] or c==check[0]:ans+=1 print(ans)