n = int(input()) a=[int(i) for i in input().split(" ")] i=0 j=0 while i+3<=n: b=a[i:i+3] c=sorted(a[i:i+3]) if (c[1]==b[0] or c[1]==b[-1]) and b[0]!=b[1] and b[1]!=b[2] and b[0]!=b[2]: j+=1 else: j+=0 i+=1 print(j)