n=input() a=map(int,raw_input().split()) c=0 for i in range(n-2): k=a[i:i+3] m=sorted(k)[1] if k[0]!=k[1] and k[0]!=k[2] and k[1]!=k[2] and(k[0]==m or k[2]==m): c+=1 #print k print c