import sys

import numpy as np



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N = ir()

P = np.array(lr())



P_diff = np.diff(P)

P_diff = P_diff > 0

series = P_diff[:-1] == P_diff[1:]

answer = series.sum()

print(answer)

# 23
N = int(eval(input()))

P = list(map(int, input().split()))

answer = sum(x>y>z or x<y<z for x, y, z in zip(P[:-2], P[1:-1], P[2:]))

print(answer)

    
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
P = np.array(lr())
P_diff = np.diff(P)
P_diff = P_diff > 0
series = P_diff[:-1] == P_diff[1:]
answer = series.sum()
print(answer)
# 23

N = int(eval(input()))
P = list(map(int, input().split()))
answer = sum(x > y > z or x < y < z for x, y, z in zip(P[:-2], P[1:-1], P[2:]))
print(answer)

-import sys -import numpy as np - -sr = lambda: sys.stdin.readline().rstrip() -ir = lambda: int(sr()) -lr = lambda: list(map(int, sr().split())) -N = ir() -P = np.array(lr()) -P_diff = np.diff(P) -P_diff = P_diff > 0 -series = P_diff[:-1] == P_diff[1:] -answer = series.sum() +N = int(eval(input())) +P = list(map(int, input().split())) +answer = sum(x > y > z or x < y < z for x, y, z in zip(P[:-2], P[1:-1], P[2:])) -# 23