n = int(input()) array = list(map(int,input().split())) count=0 for i in range(0,n-2): v_i = array[i:i+3] v = list(sorted(v_i)) if len(list(set(v)))==3 and (v[1]==v_i[0] or v[1]==v_i[2]): count+=1 print(count)