n = int(eval(input()))

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

cnt = 0

for i in range(n - 2):

    l = p[i:i+3]

    L = sorted(l)

    if l[1] == L[1]:

        cnt += 1

        

print(cnt)
n =  int(eval(input()))

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

cnt = 0



for i in range(n-2):

    P = p[i:i+3]

    if P[0] < P[1] < P[2]:

        cnt += 1

    elif P[2] < P[1] < P[0]:

        cnt += 1

        

print(cnt)
n = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
for i in range(n - 2):
    l = p[i : i + 3]
    L = sorted(l)
    if l[1] == L[1]:
        cnt += 1
print(cnt)

n = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
for i in range(n - 2):
    P = p[i : i + 3]
    if P[0] < P[1] < P[2]:
        cnt += 1
    elif P[2] < P[1] < P[0]:
        cnt += 1
print(cnt)

-    l = p[i : i + 3] -    L = sorted(l) -    if l[1] == L[1]: +    P = p[i : i + 3] +    if P[0] < P[1] < P[2]: +        cnt += 1 +    elif P[2] < P[1] < P[0]: