Problem:
 Score : 200 points    Problem Statement 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 1 5
1 3 5 4 2      Sample Output 1 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.       Sample Input 2 9
9 6 3 2 5 8 7 4 1      Sample Output 2 5

Solution (Python):
N = int(input())
P= [int(x) for x in input().split()]

answer=0
for i in range(1,N-1):
  a,b,c=P[i-1:i+2]
  if b != max(a,b,c) and b!= min(a,b,c):
    answer+=1

print(answer)

Solution (Python):
N = int(input())
P = [int(x) for x in input().split()]

answer = 0
for i in range(1,N-1):
  
  a,b,c = P[i-1:i+2]
  if b != min(a,b,c) and b != max(a,b,c):
    
    answer += 1

print(answer)

Solution (Python):
n = int(input())
p = [int(x) for x in input().split()]

count = 0
for i in range(1, n-1):
  t = p[i-1:i+2]
  t.sort()
  if p[i] == t[1]:
    count += 1

print(count)

Solution (Python):
input()
*p,=map(int,input().split())
print(sum([p[i]==sorted(p[i-1:i+2])[1]for i in range(1,len(p)-1)]))

Solution (Python):
n = int(input())
array = list(map(int,input().split(" ")))
cnt = 0
for idx in range(0,len(array)-2,1):
    tmparr = array[idx:idx+3]
    Pi = tmparr[1]
    if Pi == sorted(tmparr)[1]:
        cnt+=1
print(cnt)

Solution (Python):
input()
*p, = map(int, input().split())
print(sum([p[i] == sorted(p[i - 1:i + 2])[1] for i in range(1, len(p) - 1)]))

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

Solution (Python):
n = int(input())
p = input().split()

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

Solution (Python):
n = int(input())
*l, = map(int,input().split())

f = 0
for i in range(len(l)-2):
  if l[i]<l[i+1] and l[i+1]<l[i+2]:
    f += 1
  elif l[i]>l[i+1] and l[i+1]>l[i+2]:
    f += 1
print(f)

Solution (Python):
n = int(input().rstrip())
p_string = input().rstrip().split()
p = [int(x) for x in p_string]

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

Solution (Python):
n = input()
p = []
input_first = input()
for ki in range(int(n)):
    p = input_first.rstrip().split(' ')
count = 0
for i in range(1,int(n)-1):
    if int(p[i]) > int(p[i-1]) and int(p[i]) < int(p[i+1]):
        count += 1
    elif int(p[i]) < int(p[i-1]) and int(p[i]) > int(p[i+1]):
        count += 1
    else:
        pass
print(count)

Solution (Python):
n = int(input())
p = [int(i) for i in input().split()]
print(len([p[i] for i in range(1, len(p)-1 , 1) if p[i-1] > p[i] > p[i+1] or p[i-1] < p[i] < p[i+1]]))

Solution (Python):
n = int(input())

numbers = list(map(int, input().split()))
comp_list = []
result = 0

for i in range(n-2):
    comp_list.clear()
    comp_list.append(numbers[i])
    comp_list.append(numbers[i+1])
    comp_list.append((numbers[i+2]))
    sorted_list = sorted(comp_list)
    if sorted_list[1] == numbers[i+1]:
        result += 1
print(result)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
a = 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]:
        a += 1
print(a)

Solution (Python):
def main():
    n = input()
    p_list = list(map(int, input().split()))
    count = 0

    for i in range(len(p_list) - 2):
        if check(p_list[i], p_list[i + 1], p_list[i + 2]):
            count += 1
    print(count)


def check(p1: int, p2: int, p3: int):
    return p1 < p2 < p3 or p1 > p2 > p3


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())

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

Solution (Python):
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

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

Solution (Python):
S=int(input())
L=list(map(int,input().split()))
ans = 0
for i in range(2,S):
  A,B,C = L[i-2 : i + 1]
  if (A >= B >= C) or (A <= B <= C ) :
    ans += 1
print(ans)

Solution (Python):
a = int(input())
b = [int(i) for i in input().split()]

res = 0
for i in range(1,a-1):
    if b[i-1] < b[i] < b[i+1] or b[i+1] < b[i] < b[i-1]:
        res += 1

print(res)

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

Solution (Python):
n = int(input())
l = [int(i) for i in input().split()]
cnt = 0
for i in range(1,n-1):
    three = [l[i-1],l[i],l[i+1]]
    three_sort_list = sorted(three)
    if three[1] == three_sort_list[1]:
        cnt += 1

print(cnt)

Solution (Python):
n=int(input())
L=list(map(int,input().split()))

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

Solution (Python):


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

for i in range(N - 2):
    if (a[i] > a[i + 1] & a[i + 1] > a[i + 2]):
        count += 1
    elif (a[i] < a[i + 1] & a[i + 1] < a[i + 2]):
        count += 1
print(count)

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

Solution (Python):
input()
p = [int(i) for i in input().split(' ')]
cnt = 0
for i in range(1, len(p) - 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)

Solution (Python):
N = int(input())
P =  list(map(int,input().split(' ')))
print(sum([ 1   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] ]))

Solution (Python):
n = int(input())
pp = list(map(int, input().split()))
c = 0
for i in range(1, n - 1):
    if sorted(list({pp[i - 1], pp[i], pp[i + 1]}))[1] == pp[i]:
        c += 1
print(c)

Solution (Python):
n = input()
n = int(n)
l=[]
l = input().split(" ")
ans=0
for i in range(1,n-1):
	a=int(l[i-1])
	b=int(l[i])
	c=int(l[i+1])
	if(b>=a and b<=c or b>=c and b<=a):
		ans=ans+1
print(ans)

Solution (Python):
n = int(input())
t = list(map(int, input().split()))
result = 0

for i in range(n-2):
  l = [t[i], t[i+1], t[i+2]]
  if min(l) != l[1] and max(l) != l[1]:
    result += 1
    
print(result)

Solution (Python):
inp0 = input()
inp = [int(x) for x in input().split(" ")]

ans = 0
for index in range(1, len(inp)-1):
    a = sorted([inp[index-1], inp[index], inp[index+1]])
    if min(a) == inp[index]:
        pass
    chk = list(set(a))
    
    if inp[index] == a[1]:
            ans = ans+1
    
    

print(ans)

Solution (Python):
n = int(input())
p = [int(i) for i in input().split()]
ans = 0
for i in range(1, n - 1):
  p_prev, p_cur, p_next = p[i-1], p[i], p[i+1]
  ans += (p_next - p_cur ) * (p_cur - p_prev) > 0
print(ans)

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

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

Solution (Python):
g = int(input())
data = [int(i) for i in input().split(" ")]

count = 0
for i in range(1,g-1):
    if (data[i] > data[i-1] and data[i] < data[i+1]) or (data[i] < data[i-1] and data[i] > data[i+1]):
        count += 1

print(count)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
last_num = 2
ans_count = 0
while last_num < n:
	if p[last_num - 2] < p[last_num - 1] and p[last_num - 1] < p[last_num]:
		ans_count += 1
	elif  p[last_num - 2] > p[last_num - 1] and p[last_num - 1] > p[last_num]:
		ans_count += 1
	last_num += 1
print(ans_count)

Solution (Python):
def check(l):
  return (l[2] - l[1]) * (l[1] - l[0]) > 0

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

print(sum([check(p[i:i+3]) for i in range(n-2)]))

Solution (Python):
N = int(input())

ls = []
P = map(int,input().split())
  
for i in P:
	ls.append(i)
  
ind_i = 0
ind_j = 1
ind_k = 2
cnt = 0
for p in range(N -2):
	i = ls[ind_i]
	j = ls[ind_j]
	k = ls[ind_k]
	if i < j < k or k < j < i:
		cnt += 1
	ind_i += 1
	ind_j += 1
	ind_k += 1
  
print(cnt)

Solution (Python):
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)

Solution (Python):
n=int(input())
p=[int(i) for i in input().split()]
ans=0
for i in range(n-2):
    a,b,c=p[i:i+3]
    if a<b<c or a>b>c:
        ans+=1
print(ans)

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

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

Solution (Python):



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

c = 0

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

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

print(sum([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]) else 0 for i in range(1, len(p)-1)]))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(1,N - 1):
  if A[i - 1] < A[i] and A[i] < A[i + 1]:
    ans += 1
  elif A[i - 1] > A[i] and A[i] > A[i + 1]:
    ans += 1
print(ans)

Solution (Python):
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]-p[i-1])>0:
		ans+=1
print(ans)

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

Solution (Python):
def solve():
  n = int(input())
  p = list(int(i) for i in input().split())
  ans = 0
  for i in range(n-2):
   query = [p[i],p[i+1],p[i+2]]
   query.sort()
   if query[1] == p[i+1]:
    ans += 1
  print(ans)
solve()

Solution (Python):
N = int(input())
row = list(map(int,(input().split())))
count = 0
for i in range(1,len(row) - 1):
  if row[i - 1] < row[i] < row[i + 1] or row[i - 1] > row[i] > row[i + 1]:
    count +=1
print(count)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n-2):
  count += (min(p[i], p[i+2]) < p[i+1] < max(p[i], p[i+2]))
print(count)

Solution (Python):
def resolve():
    n=int(input())
    p=list(map(int,input().split()))
    s=0
    for i in range(1,n-1):
        s+=p[i-1]<p[i]<p[i+1] or p[i+1]<p[i]<p[i-1]
    print(s)
        
resolve()

Solution (Python):
n, P = int(input()), list(map(int, input().split()))
print(sum([P[i + 1] == sorted(P[i: i + 3])[1] for i in range(n - 2)]))

Solution (Python):
N = int(input())
l = list(map(int,input().split()))
count = 0

for i in range(N - 2):
  if l[i] < l[i+1] < l[i+2] or l[i] > l[i+1] > l[i+2]:
    count += 1

print(count)

Solution (Python):
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)

Solution (Python):
n=int(input())
ls=list(map(int,input().split()))
j=0
for i in range(1,n-1):
    ls1=[ls[i-1],ls[i],ls[i+1]]
    ls2=sorted(ls1)
    if ls2[1]==ls[i]:
        j+=1
print(j)

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
ans=0
for i in range(N-2):
  A=L[i:i+3]
  t=A[1]
  A.sort()
  
  ans+=1 if t==A[1] else 0
print(ans)

Solution (Python):
n = int(input())
plist = list(map(int, input().split()))
counter = 0

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

print(counter)

Solution (Python):
def main():
  n = int(input())
  p = list(map(int,input().split()))
  res = 0
  for i in range(2, n):
    if p[i-2] == p[i-1] and p[i-1] == p[i]:
      pass
    elif p[i-2] == p[i-1] or p[i-1] == p[i] or p[i] == p[i-2]:
      if min(p[i-2], p[i-1], p[i]) < min(p[i-2], p[i-1], p[i]) < p[i-1] and p[i-1] <= max(p[i-2], p[i-1], p[i]):
        res += 1
      else:
        pass
    else:
      if min(p[i-2], p[i-1], p[i]) < p[i-1] and p[i-1] < max(p[i-2], p[i-1], p[i]):
        res += 1
      else:
        pass
  print(res)
  
if __name__ == "__main__":
  main()

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(N - 2):
    comp = p[i:i + 3]
    comp.sort()
    if p[i + 1] == comp[1]:
        count += 1

print(count)

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
comp = []
count = 0
for i in range(N - 2):
    comp = p[i:i + 3]
    comp.sort()
    if p[i + 1] == comp[1]:
        count += 1

print(count)

Solution (Python):
N=int(input())
a=[int(x) for x in input().split()]
ans=0
for i in range(1,N-1):
  if (a[i]>a[i-1] and a[i]<a[i+1]) or (a[i]<a[i-1] and a[i]>a[i+1]):
    ans+=1

print(ans)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
count = 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]):
    count += 1
    
print(count)

Solution (Python):
n = int(input())

p_list = [int(p) for p in input().split()]

c = 0
for i in range(1,n-1):
    p_1 = p_list[i-1]
    p_2 = p_list[i]
    p_3 = p_list[i+1]

    
    if (p_1 <= p_2 <= p_3) or (p_3 <= p_2 <= p_1):
        c += 1
        

print(c)

Solution (Python):
n = int(input())

L = [int(i) for i in input().split()]

Answer = int(0)
for i in range(n-2):
     if L[i]<L[i+1] and L[i+1]<L[i+2]:
             Answer = Answer + 1
     if L[i+2]<L[i+1] and L[i+1]<L[i]:
             Answer = Answer + 1
print(Answer)

Solution (Python):
n = int(input())

L = [int(i) for i in input().split()]

Answer = int(0)
for i in range(n-2):
     if L[i]<L[i+1] and L[i+1]<L[i+2]:
             Answer = Answer + 1
             continue
     if L[i+2]<L[i+1] and L[i+1]<L[i]:
             Answer = Answer + 1
             continue
print(Answer)

Solution (Python):
N = int(input())

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

ans = 0
for i in range(1, N-1):
    if (PPP[i] >= PPP[i-1] and PPP[i+1] > PPP[i]) or (PPP[i] >= PPP[i+1] and PPP[i-1] > PPP[i]):
        ans += 1

print(ans)

Solution (Python):
n=int(input())-2
hoge=list(map(int,input().split()))
ans=0
for i in range(n):
  a=hoge[i]
  b=hoge[i+1]
  c=hoge[i+2]
  if(a<b and b<c):
    ans+=1
  elif(a>b and b>c):
    ans+=1 
print(ans)

Solution (Python):
n=int(input())
p=tuple(map(int,input().split()))
c=0
for i in range(n-2):
  tmp=sorted(p[i:i+3])
  if tmp[1]==p[i+1]:
    c+=1
print(c)

Solution (Python):


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

Solution (Python):
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)

Solution (Python):
def checkp(a,b,c):
    if max(a,b,c) == b or min(a,b,c) == b:
        return 0
    else:
        return 1

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

count = 0

for i in range(n-2):
    count += checkp(p[i],p[i+1],p[i+2])

print(count)

Solution (Python):
N = int(input())
P = [int(_) for _ in input().split()]
ans = 0
for i in range(N - 2):
    pqr = P[i:i + 3]
    if sorted(pqr)[1] == pqr[1]:
        ans += 1
print(ans)

Solution (Python):
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)

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

Solution (Python):
n=int(input());a=list(map(int,input().split()));print(sum([1 for i in range(n-2) if a[i+1]==sorted(a[i:i+3])[1]]))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
print(sum([1 for i in range(1,n-1) if (a[i-1]<a[i] and a[i]<a[i+1])or(a[i+1]<a[i] and a[i]<a[i-1])]))

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
count=0
for i in range(1,n-1):
	if (p[i]>p[i-1] and p[i]<p[i+1]) or (p[i]<p[i-1] and p[i]>p[i+1]):
		count+=1
print('{}'.format(count))

Solution (Python):
n=int(input())
p=[int(i) for i in input().split()]
ans=0
for i in range(n-2):
    x,y,z=p[i:i+3]
    if x>y>z or x<y<z or x==z>y or x>y==z:
        ans+=1
print(ans)

Solution (Python):
n=int(input())
p=[int(a) for a in input().split()]
cnt=0

for i in range(n-2):
    a=sorted(p[i:i+3])
    if p[i+1]==a[1]:
        cnt+=1
        

print(cnt)

Solution (Python):
def check(lst):
    return lst[0] < lst[1] < lst[2] or lst[2] < lst[1] < lst[0]

n = int(input())
p = list(map(int, input().split()))
ans = map(check, zip(p[:-1], p[1:-1], p[2:]))
print(sum(ans))

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

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

count = 0
for n in range(2, N):
	count += (P[n - 1] == sorted(P[n - 2:n + 1])[1])
print(count)

Solution (Python):
n=input()
l=[int(x) for x in raw_input().split()]
print sum([l[i]<l[i+1]<l[i+2] or l[i]>l[i+1]>l[i+2] for i in range(n-2)])

Solution (Python):
n = int(input())
pp = list(map(int,input().split()))
three = [pp[0],pp[1],pp[2]]
cou = 0
th = 0

for i in range(n-2):
    three[0] = pp[i]
    three[1] = pp[i+1]
    three[2] = pp[i+2]
    th = three[1]
    three.sort()
    if three[1] == th:
        cou += 1
   
print(cou)

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

count = 0

for i in range(1, n-1):
    n3 = [
            p[i-1],
            p[i],
            p[i+1]
        ]
    n3.sort()
   
    if n3[1] == p[i]:
        count += 1
print(count)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))

cnt = 0
for x, y, z in zip(arr, arr[1:], arr[2:]):
    if x > y > z or x < y < z:
        cnt += 1

print(cnt)

Solution (Python):
n=int(input())
plist=[int(s) for s in input().split()]

cnt=0
for i in range(n-2):
    left,mid,right = plist[i],plist[i+1],plist[i+2]
    maxv=max(left,mid,right)
    minv=min(left,mid,right)
    if mid!=maxv and mid!=minv:
        cnt+=1
print(cnt)

Solution (Python):
n = int(input())
p = [int(x) for x in 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)

Solution (Python):
s = int(input())
list = [int(n) for n in input().split()]

sum = 0

for i in range(1, s - 1):
    if (list[i] - list[i - 1]) * (list[i + 1] - list[i]) > 0:
        sum += 1

print(sum)

Solution (Python):
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]-p[i-1])>0:
		ans+=1

print(ans)

Solution (Python):
n = input()
N = input()

N = N.split(" ")
Ni = []
for i in N:
    Ni.append(int(i))

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

Solution (Python):
n = int(input())
p = [int(c) for c in input().split()]
print(len([i 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])]))

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

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

num = 0
for i in range(1,n-1):
  if p[i]>=p[i-1] and p[i+1]>=p[i]:
    num+=1
  elif p[i]>=p[i+1] and p[i-1]>=p[i]:
    num+=1
    
print(int(num))

Solution (Python):
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)

Solution (Python):
n = int(input())
p = [int(i) for i in input().split()]
 
ans = 0
 
for i in range(n-2):
    if p[i] > p[i+1] > p[i+2]:
        ans += 1
    elif p[i] < p[i+1] < p[i+2]:
        ans += 1
 
print(ans)

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

Solution (Python):
n = int(input())
*p, = 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)

Solution (Python):
n = int(input())
p = [int(i) for i in input().split()]

ans = 0

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

print(ans)

Solution (Python):
num_input = int(input())
input_arr = [int(x) for x in input().split()]

count = 0
for i_ in range(len(input_arr)-2):
    arr_list = [input_arr[i] for i in range(i_,i_+3)]
    sorted_arr = sorted(arr_list)
    if sorted_arr[1] == arr_list[1]:
      count = count + 1
    
print(count)

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

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

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

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

Solution (Python):
n = int(input())
p = input().split(' ')
P = list()
cnt = 0

for i in p:
    P.append(int(i))

i = 0
while i <= n-3:
    j = i + 1
    p3 = [P[i], P[i+1], P[i+2]]
    if sorted(p3)[1] == P[j]:
        cnt += 1
    i += 1

print(cnt)

Solution (Python):
n=input()
P=map(int,raw_input().split())
ans=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]:
        ans+=1
print(ans)

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

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

print(count)

Solution (Python):
n=int(input())
a=list(map(int,input().split( )))
count=0
for i in range(1,n-1):
  x,y,z=a[i-1],a[i],a[i+1]
  m=min(x,y,z)
  if m==x:
    if y==min(y,z):
      count+=1
  if m==z:
    if y==min(x,y):
      count+=1
print(count)

Solution (Python):
n =int(input())
p = list(map(int,input().split()))
count=0
for i in range(len(p)-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]:
    count += 1
print(count)

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
L = [int(v) for v in input().split()]

ans = 0
for i in range(1, N - 1):
    p = L[i-1:i+2]
    p.sort()
    
    if p[1] == L[i]:
        ans += 1
    
print(ans)

Solution (Python):
n = int(input())
p = [int(i) for i in input().split()]
count = 0
for i in range(1,n-1):
  if (p[i]-p[i-1]) * (p[i]-p[i+1]) < 0:
    count += 1
print(count)

Solution (Python):
a = int(input())
b = [int(i) for i in input().split()]
c = 0
for i in range(2, a):
    if b[i-2] < b[i-1] < b[i] or b[i-2] > b[i-1] > b[i] :
        c += 1
print(c)

Solution (Python):
def counting(numbers) -> int:
    count = 0
    for i in range(1, len(numbers) - 1):
        pre = numbers[i-1]
        curr = numbers[i]
        next_ = numbers[i+1]
        if pre < curr and curr == next_:
            count += 1
        elif next_ < curr and curr == pre:
            count += 1
        elif pre < curr < next_ or next_ < curr < pre:
            count += 1
    return count
 
_ = input()
numbers_str = input()
result = counting([int(c) for c in numbers_str.split(' ')])
print(result)

Solution (Python):
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)

Solution (Python):
def prob_b():
    n = int(input())
    p_list = [int(a) for a in input().split()]
    ans = 0
    for i in range(n - 2):
        if min(p_list[i], p_list[i+2]) < p_list[i+1] < max(p_list[i], p_list[i+2]):
            ans += 1
    return ans

a = prob_b()
print(str(a))

Solution (Python):
n = int(input())
arr =  list(map(int, input().split() ))

count = 0
for i in range(1, n-1):
	if (arr[i+1]-arr[i]) * (arr[i]-arr[i-1])> 0:
		count += 1
print(count)

Solution (Python):
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] > P[i+1] and P[i+1] > P[i+2]):
		ans += 1

print(ans)

Solution (Python):


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

print(count)

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
p = list(map(int,stdin.readline().split()))

counter=0
for i in range (1, n-1, 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]):
    counter+=1
print(counter)

Solution (Python):
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]:
        c += 1
    elif P[i+1] < P[i] < P[i-1]:
        c += 1
print(c)

Solution (Python):
n = int(input())
p = [int(_) for _ in input().split()]
ans = 0

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

Solution (Python):
n = int(input())
p_array = [int(x) for x in input().split()]

cnt = 0
for i in range(n-2):
    tmp = p_array[i:i+3]
    if tmp[1] == sorted(tmp)[1]:
        cnt += 1
print(cnt)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    r = 0
    for i in range(1,n-1):
        t = sorted(a[i-1:i+2])[1]
        if t == a[i]:
            r += 1

    return r


print(main())

Solution (Python):
n, = list(map(int,input().split()))
p = list(map(int,input().split()))
ret = 0
for i in range(n-2):
  a = p[i:i+3]
  a.sort()
  if a[1]==p[i+1]:
    ret += 1
print(ret)

Solution (Python):
n = int(input())
p = [int(x) for x in input().split()]
ans = 0
for i in range(n-2):
  if p[i]<p[i+1] and p[i+1]<p[i+2]:
    ans += 1
  elif p[i]>p[i+1] and p[i+1]>p[i+2]:
    ans += 1
print(ans)

Solution (Python):
n=int(input())
p=[int(i) for i in input().split()]

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

Solution (Python):
n=int(input())
p=[int(x) for x in input().split()]

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

print(c)

Solution (Python):
n = int(input())
p = [int(_) for _ in input().split()]
ans = 0

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

print(ans)