n = int(input()) a = list(map(int, input().split())) res = 0 for i in range(n - 2): b = a[i:i+3] bs = sorted(b) if (bs[1] == b[0] or bs[1] == b[2]) and bs[0] != bs[1] and bs[1] != bs[2]: res += 1 print(res)