We have a permutation p = {p_1,\ p_2,\ ...,\ p_n} of {1,\ 2,\ ...,\ n}.
Print the number of elements p_i (1 < i < n) that satisfy the following condition:
 - p_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}.

-----Constraints-----
 - All values in input are integers.
 - 3 \leq n \leq 20
 - p is a permutation of {1,\ 2,\ ...,\ n}.

-----Input-----
Input is given from Standard Input in the following format:
n
p_1 p_2 ... p_n

-----Output-----
Print the number of elements p_i (1 < i < n) that satisfy the condition.

-----Sample Input-----
5
1 3 5 4 2

-----Sample Output-----
2

p_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.

Difficulty: introductory

Starter code:

Solutions:
n = int(input())
p = list(map(int, input().split()))
s = 0
for i in range(n - 2):
    if p[i] < p[i + 1] < p[i + 2] or p[i] > p[i + 1] > p[i + 2]:
        s += 1
print(s)


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

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

cnt = 0
for i in range(1,n-1):
    second = p[i]
    scope = sorted([ p[i-1], p[i], p[i+1] ])
    if scope[0] < second and second < scope[2]:
        cnt += 1

print(cnt)

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

ans = 0
for i in range(1, n-1):
    if sorted(p[i-1:i+2])[1] == p[i]:
        ans += 1
print(ans)

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

count = 0
for i in range(1,len(P)-1):
    p_ = [P[i-1], P[i], P[i+1]]
    if (P[i] != min(p_)) and (P[i] != max(p_)):
        count+= 1

print(count)


n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(1, n - 1):
    if min(a[i - 1], a[i], a[i + 1]) != a[i] and max(a[i - 1], a[i], a[i + 1]) != a[i]:
        ans += 1
print(ans)


n = int(input())
p = list(map(int, input().split()))
cnt = 0

for i in range(0, n-2):
    if p[i] < p[i + 1] < p[i + 2] or p[i + 2] < p[i + 1] < p[i]:
        cnt+=1

print(cnt)

n = int(input())
list01 = list(map(int, input().split()))
list02 = []
list03 = []
a = 0
for i in range(n-2):
    list02 = [list01[i], list01[i+1], list01[i+2]]
    list03 = sorted(list02)
    if list02[1] == list03[1]:
        a += 1
print(a)

n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1,n-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
        ans += 1

print(ans)

n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
    if p[i-1]<=p[i]<=p[i+1]:
        ans+=1
    if p[i+1]<=p[i]<=p[i-1]:
        ans+=1
print(ans)

n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(1,n-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:

        ans += 1
    
print(ans)

n = int(input())

pn = list(map(int,input().split()))
count = 0
for x in range(1,n-1):
  if pn[x+1] > pn[x] > pn[x-1] or pn[x-1] > pn[x] > pn[x+1]:
    count += 1
print(count)

n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, n-1):
  if p[i-1] < p[i] and p[i] < p[i+1]: ans += 1
  if p[i-1] > p[i] and p[i] > p[i+1]: ans += 1
print(ans)

n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1,n-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
        ans += 1

print(ans)

n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(1, n-1):
  p1, p2, p3 = p[i-1], p[i], p[i+1]
  if p1 < p2 < p3 or p3 < p2 < p1:
    count += 1
print(count)

n = int(input())
p = list(map(int,input().split()))
ans_list = []

for i in range(1,n-1):
    if p[i-1]<p[i]<p[i+1] or p[i+1] < p[i] < p[i-1] :
        ans_list.append(i)
print(len(ans_list))

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

answer = 0
for i in range(n - 2):
    if p[i] < p[i + 1] < p[i + 2]:
        answer += 1
    if p[i] > p[i + 1] > p[i + 2]:
        answer += 1
print(answer)

n = int(input())
list_p = [int(i) for i in input().split()]
count = 0
for i in range(1, n - 1):
    if min(list_p[i - 1], list_p[i], list_p[i + 1]) !=list_p[i] and \
            max(list_p[i - 1], list_p[i], list_p[i + 1]) != list_p[i]:
        count += 1
print(count)

n=int(input())
a=list(map(int,input().split()))

ans=0
for i in range(1,n-1):
  ans+=1 if a[i-1]<a[i]<a[i+1] or a[i+1]<a[i]<a[i-1] else 0
  
print(ans)


n=int(input())
p=list(map(int, input().split()))
o=0

for i in range(1,n-1):
    if p[i-1]>p[i]>p[i+1] or p[i+1]>p[i]>p[i-1]:
        o+=1
print(o)







permutation_number = int(input())
permutation = list(map(int, input().split()))
conditional_permutation = 0
for i in range(permutation_number - 2):
    if permutation[i] < permutation[i + 1] < permutation[i + 2] or permutation[i] > permutation[i + 1] > permutation[i + 2]:
        conditional_permutation += 1
print(conditional_permutation)

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

cnt=0
for i in range(1,n-1):
    if (p[i-1]<p[i]<p[i+1] or p[i+1]<p[i]<p[i-1]):
        cnt+=1
print(cnt)


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

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

cnt = 0
for i in range(1,n-1):
    l = [p[i-1],p[i],p[i+1]]
    if l[1] == sorted(l)[1]:
        cnt += 1

print(cnt)

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

ans = 0
for i in range(1, n-1):
    if (p[i] - p[i - 1]) * (p[i] - p[i + 1]) < 0:
        ans += 1

print(ans)


n = int(input());
arr = list(map(int, input().split()));
count = 0;
for i, num in enumerate(arr):
  if(i == 0 or i == (n - 1)): 
    continue;
  
  target_arr = [arr[i-1], arr[i], arr[i+1]]
  if(sorted(target_arr)[1] == arr[i]):
  	count+=1;

print(count)


n = int(input())
data = list(map(int,input().split()))
point = 0
i = 1
while i <= len(data) - 2:
    if data[i-1] < data[i] and data[i] < data[i+1]:
        point += 1
    if data[i - 1] > data[i] and data[i] > data[i + 1]:
        point += 1
    i += 1

print(point)

n = int(input())
p = list(map(int, input().split()))
cnt = 0

for i in range(1, n-1):
  if (p[i-1] > p[i] and p[i] > p[i+1]) or (p[i-1] < p[i] and p[i] < p[i+1]):
    cnt += 1
    
print(cnt)    



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

cnt = 0
for i in range(1, N - 1):
    l = [P[i - 1], P[i], P[i + 1]]
    l.sort()
    if l[1] == P[i]:
        cnt += 1

print(cnt)

n = int(input())
li = list(map(int,input().split()))
cnt = 0
for i in range(1,n-1):
    if li[i-1] < li[i] and li[i] < li[i+1]:
        cnt += 1
    elif li[i-1] > li[i] and li[i] > li[i+1]:
        cnt += 1

print(cnt)

n = int(input())
a = [int(num) for num in input().split()]
count = 0
for i in range(1, n-1):
    if a[i-1] < a[i] and a[i] < a[i+1]:
        count += 1
    elif a[i-1] > a[i] and a[i] > a[i+1]:
        count += 1
print(count)


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

ans = 0
for i in range(n):
    if(i == 0):
        pass
    elif (i == n - 1):
        pass
    else:
        a = p[i - 1]
        b = p[i]
        c = p[i + 1]
        lst = [a, b ,c]
        lst.sort()
        if (lst[1] == b):
            ans = ans + 1
print(ans)


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

cnt = 0
for i in range(1,n-1):
    if min(P[i-1],P[i],P[i+1]) < P[i] and max(P[i-1],P[i],P[i+1]) > P[i]:
        cnt += 1

print(cnt)

n = int(input())
lst = list(map(int, input().split()))

if lst[0] > lst[1]:
    di = 1

else:
    di = -1

ans = 0
now = lst[1]

for i in range(2, n):
    if di == 1 and now > lst[i]:
            ans += 1

    elif di == -1 and now < lst[i]:
            ans += 1

    else:
        di = -di

    now = lst[i]

print(ans)


n = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(n-2):
    if (p[i] < p[i+1] and p[i+1] < p[i+2]) or (p[i] > p[i+1] and p[i+1] > p[i+2]):
        c += 1
print(c)

n = int(input())
p = list(map(int,input().split()))
count = 0

for i in range(1,n-1):
    if p[i-1] <= p[i] < p[i+1] or p[i+1] <= p[i] < p[i-1]:
        count += 1

print(count)

from typing import Tuple


def answer(n: int, p: Tuple[int]) -> int:
    count = 0
    for i in range(1, n - 1):
        max_ = max(p[i - 1], p[i + 1])
        min_ = min(p[i - 1], p[i + 1])
        if min_ < p[i] < max_:
            count += 1

    return count


def main():
    n = int(input())
    p = tuple(map(int, input().split()))
    print(answer(n, p))


def __starting_point():
    main()
__starting_point()

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

cnt = 0
for i in range(n-2):
  if (p[i]<p[i+1] and p[i+1]<p[i+2]) or (p[i]>p[i+1] and p[i+1]>p[i+2]):
    cnt += 1
print(cnt)

n=int(input())
a=list(map(int,input().split()))
count=0
for i in range(n-2):
  #print(a[i],a[i+1],a[i+2])
  if a[i]<a[i+1]<a[i+2] or a[i]>a[i+1]>a[i+2]:
    count+=1
print(count)

n = int(input())
p = list(map(int, input().split()))
cnt = 0

for i in range(n-2):
    if p[i] < p[i+1] < p[i+2] or p[i] > p[i+1] > p[i+2]:
        cnt += 1
print(cnt)


n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(n-2):
    List=p[i:i+3]
    P=List[1]
    num=sorted(List)[1]
    if P==num:
        ans+=1
        
print(ans)

n=int(input())
P=list(map(int,input().split()))
count=0
for i in range(1,n-1):
  if P[i-1]>P[i] and P[i]>P[i+1]:
    count+=1
  elif P[i-1]<P[i] and P[i]<P[i+1]:
    count+=1
print(count)

n = int(input())
S = map(int,input().split())
Number = list(S)
count_number = 0

for i in range(n-2):
    if Number[0] > Number[1] > Number[2] or Number[2] > Number[1] > Number[0]:
        count_number += 1
    del Number[0]

print(count_number)

n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i - 1] > p[i] > p[i + 1]:
        ans += 1
print(ans)

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


n = int(input())
p = [int(i) for i in input().split()]
ans = 0

for i in range(1,n-1):
    if((p[i-1] < p[i] and p[i] < p[i+1]) or (p[i-1] > p[i] and p[i] > p[i+1])):
        ans += 1

print(ans)

a=int(input())
b=list(map(int,input().split()))
c=0
for i in range(a-2):
  if (b[i+1]-b[i])*(b[i+2]-b[i+1])>0:
    c=c+1
print(c)

#ABC132 B

n = int(input())
P = list(map(int,input().split()))
K = 0
for i in range(n-2):
    if (P[i] < P[i+1] and P[i+1] < P[i+2]) or (P[i+2] < P[i+1] and P[i+1] < P[i]):
        K += 1
        
print(K)

import collections
n = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(n-2):
    if (p[i] < p[i+1] and p[i+1] < p[i+2]) or (p[i] > p[i+1] and p[i+1] > p[i+2]):
        c += 1
print(c)

n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(1,n-1):
  pl = [p[i-1],p[i],p[i+1]]
  if p[i] != max(pl) and p[i] != min(pl):
    ans += 1
print(ans)

n = int(input())
p = [int(s) for s in input().split()]
count = 0
for i in range(len(p)-2):
    if p[i] < p[i+1] < p[i+2] or p[i] > p[i+1] > p[i+2] :
        count += 1
print(count)

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

n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(0, n - 2):
    if p[i] < p[i + 1] < p[i + 2] or p[i] > p[i + 1] > p[i + 2]:
        ans += 1
print(ans)

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

count = 0

for i in range(1, n - 1):
    a_list = [p[i-1], p[i], p[i+1]]
    b_list = sorted(a_list)

    if a_list[1] == b_list[1]:
        count += 1

print(count)

n = int(input())
plist = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
    if max(plist[i-1], plist[i], plist[i+1]) != plist[i] and min(plist[i-1], plist[i], plist[i+1]) != plist[i]:
        ans += 1
print(ans)

n = int(input())
p = input().split(' ')
for i in range(len(p)):
    p[i] = int(p[i])
cnt = 0
for i in range(1,n-1):
    if p[i-1] < p[i] and p[i] < p[i+1]:
        cnt += 1
    elif p[i+1] < p[i] and p[i] < p[i-1]:
        cnt += 1
print(cnt)        


n = int(input())
p = list(map(int, input().split()))
ans =  0
for i in range(1, n-1):
  if p[i-1] < p[i] < p[i+1] or p[i+1] < p[i] < p[i-1]:
    ans += 1
print(ans)

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

result = 0

for i in range(1, n - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i + 1] < p[i] < p[i - 1]:
        result += 1

print(result)

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

"""
問題文 { 1 , 2 , . . . , n } の順列 p = { p 1 , p 2 , . . . , p n } があります。
以下の条件を満たすような p i ( 1 < i < n ) がいくつあるかを出力してください。
p i − 1 , p i , p i + 1 の 3 つの数の中で、 p i が 2 番目に小さい。
制約 入力は全て整数である。
3 ≤ n ≤ 20 p は { 1 , 2 , . . . , n } の順列である。
入力 入力は以下の形式で標準入力から与えられる。
n
p 1 p 2 . . . p n
"""

n = int(input())
a = list(map(int,input().split()))
count = 0

for i in range(1,n-1):
    if a[i-1] < a[i] <a[i+1] or a[i+1] < a[i] < a[i-1]:
        count += 1
print(count)

n = int(input())
x = list(map(int,input().split()))
ans = 0
for i in range(1, n-1):
  if x[i-1] <= x[i] <= x[i+1] or x[i+1] <= x[i] <= x[i-1]:
    ans += 1
print(ans)

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

answer = 0
for i in range(n - 2):
    if p[i] < p[i + 1] < p[i + 2]:
        answer += 1
    if p[i] > p[i + 1] > p[i + 2]:
        answer += 1

print(answer)

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

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

n=int(input())
p=list(map(int,input().split()))
c=0
for i in range(n-2):
    l=[]
    l2=[]
    l.append(p[i])
    l.append(p[i+1])
    l.append(p[i+2])
    l2.append(p[i])
    l2.append(p[i+1])
    l2.append(p[i+2])
    l2.remove(max(l))
    l2.remove(min(l))
    if l2[0]==l[1]:
        c+=1
print(c)



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


n = int(input())
perm_list = list(map(int, input().split()))
ans = 0

for i in range(n-2):
    a = perm_list[i]
    b = perm_list[i + 1]
    c = perm_list[i + 2]
    if a < b < c or c < b < a:
        ans += 1

print(ans)

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

ans = 0
for i in range(0,n-2):
    if p[i] < p[i + 1] <p[i + 2] or p[i] >  p[i + 1] > p[i + 2]:
        ans += 1
print(ans)

n = int(input())
p = list(map(int, input().split()))
 
ans = 0
for i in range(1, n-1):
  M = max(p[i-1], p[i], p[i+1])
  m = min(p[i-1], p[i], p[i+1])
  if p[i] != M and p[i] != m: ans += 1

print(ans)

n = int(input())
p = list(map(int, input().split()))
c = 0

for i in range(1, n-1):
  s = [p[i-1], p[i], p[i+1]]
  if p[i] != min(s) and p[i] != max(s):
    c += 1
  
print(c) 

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

ans=0
for i in range(n-2):
	a=P[i]
	b=P[i+1]
	c=P[i+2]
	
	if (a<b and b<c) or (c<b and b<a):
		ans+=1

print(ans)

n = int(input())
p = list(map(int, input().split()))
 
ans = 0
for i in range(1, n-1):
  if p[i-1] > p[i] >p[i+1] or p[i-1] < p[i] < p[i+1]: ans += 1

print(ans)

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

count = 0
for i in range(1, n - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i + 1] < p[i] < p[i - 1]:
        count += 1

print(count)


n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, n-1):
  if p[i] != min(p[i-1], p[i], p[i+1]) and p[i] != max(p[i-1], p[i], p[i+1]):
    ans += 1
print(ans)

N = int(input())
n = list(map(int, input().split()))

cnt = 0
for i in range(N - 2):
    if max(n[0 + i], n[1 + i], n[2 + i]) \
            > n[1 + i] \
            > min(n[0 + i], n[1 + i], n[2 + i]):
        cnt += 1

print(cnt)

n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(n-2):
    if (p[i] < p[i + 1] and p[i+1] <p[i+2]) or (p[i + 2] < p[i + 1] and p[i+ 1] < p[i]) :
        ans+=1
print(ans)

n = int(input())
p = list(map(int, input().split()))
memo = 0
for i in range(n-2):
  if((p[i]>p[i+1] and p[i+1]>p[i+2]) or (p[i]<p[i+1] and p[i+1]<p[i+2])):
    memo+=1
print(memo)

n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(2, n):
    a = [p[i-2], p[i-1], p[i]]
    b = sorted(a)
    if a[1] == b[1]:
        count += 1
print(count)

n = int(input())
l_n = list(map(int, input().split()))
ans_count = 0

for i in range(n - 2):
    a = l_n[i]
    b = l_n[i + 1]
    c = l_n[i + 2]
    if a <= b <= c or c <= b <= a:
        ans_count += 1

print(ans_count)

N = int(input())
Ps = list(map(int,input().split()))
cnt = 0
for i in range(1,N-1):
  if Ps[i-1] < Ps[i]<Ps[i+1] or Ps[i+1] < Ps[i]<Ps[i-1]:
    cnt+=1
print(cnt)

n = int(input())
p = list(map(int, input().split()))
 
ans = 0
for i in range(1, n-1):
  if p[i-1] > p[i] > p[i+1] or p[i-1] < p[i] < p[i+1]: ans += 1

print(ans)

n = int(input())
p = list(map(int,input().split()))
ans = 0

for i in range(1,n - 1):
    if p[i - 1] <= p[i] <= p[i + 1] or p[i + 1] <= p[i] <= p[i - 1]:
        ans += 1
print(ans)


n=int(input())
l=[int(x) for x in input().split()]
ans=0
for i in range(1,n-1):
    if l[i-1]<l[i]<l[i+1] or l[i-1]>l[i]>l[i+1]:
        ans+=1
    
print(ans)


n = int(input())
l_n = list(map(int, input().split()))
ans_count = 0

for i in range(n - 2):
    a = l_n[i]
    b = l_n[i + 1]
    c = l_n[i + 2]
    if a <= b <= c or c <= b <= a:
        ans_count += 1

print(ans_count)

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

n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(n-2):
    if max(p[i],p[i+1],p[i+2]) != p[i+1] and min(p[i],p[i+1],p[i+2]) != p[i+1]:
        ans += 1
print(ans)

input()
P = list(map(int, input().split()))
print(sum(A < B < C or C < B < A for A, B, C in zip(P, P[1:], P[2:])))

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

Y = 0
i = 0

while i < n - 2:
    nums = p[i:i+3]
    if sorted(nums)[-2] == nums[1]:
        Y += 1
    i += 1
print(Y)


n=int(input())
p=list(map(int, input().split()))
c=0

for i in range(0,n-2):
  
        if p[i]<p[i+1]<p[i+2] or p[i+2]<p[i+1]<p[i]:
            c+=1
print(c)


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

answer = 0
for i in range(n-2):
    if p[i] < p[i+1] < p[i+2] or p[i+2] < p[i+1] < p[i]:
        answer += 1

print(answer)


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


n = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(1, n-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1] :
        c += 1
print(c)


n=int(input())
p=list(map(int, input().split()))
ans=0
for i in range(1,n-1):
  if p[i-1]<p[i]<p[i+1] or p[i-1]>p[i]>p[i+1]:
    ans+=1
print(ans)

n=int(input())
P=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  if sorted([P[i-1],P[i],P[i+1]]).index(P[i]) == 1:
    ans += 1
print(ans)

N=int(input())
P=list(map(int,input().split()))
count=0
for i in range(0,N-2):
  max_P=max(P[i],P[i+1],P[i+2])
  min_P=min(P[i],P[i+1],P[i+2])
  if P[i+1] != max_P and P[i+1] != min_P:
    count+=1
print(count)

a = input()
n = int(a)
p = list(map(int,input().split()))
count = 0

for i in range(1,n-1):
    if (p[i-1] < p[i] and p[i] <= p[i+1]) or (p[i+1] < p[i] and p[i] <= p[i-1]):
        count = count + 1
print(count)

n=int(input())
P=str(input())

def ans132(n:int, P:str):
    P=list(map(int,P.split()))
    jugde_count=0
    for i in range(1,n-1):
        n_list=sorted([P[i-1],P[i],P[i+1]])
        if n_list[1]==P[i]:
            jugde_count+=1
    return jugde_count

print(ans132(n,P))