n=int(input());c=0 a=[*map(int,input().split())] for i in range(n-2): b=a[i:i+3] if len({*b})>2 and (b[1]!=sum(b)-max(b)-min(b)): c+=1 print(c)