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 = 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(x) for x in input().split()]
counter = 0
for i in range(1, n-1):
    if (p[i]-p[i-1])*(p[i+1]-p[i]) > 0:
        counter += 1

print(counter)

Solution (Python):
import sys
import numpy as np
sys.setrecursionlimit(1000000)
 
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+2] > p[i+1]:
        ans += 1
    elif p[i] > p[i+1] and p[i+2] < p[i+1]:
        ans += 1
        
print(ans)

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

count = 0
for i in range(n-2):
  a = p[i]
  b = p[i+1]
  c = p[i+2]
  if b > a and b < c:
    count+=1
  elif b > c and b < a:
    count+=1
print(count)

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

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

res = 0
for i in range(N - 2):
    if (P[i + 1] < P[i] and P[i + 1] > P[i + 2]) or (P[i + 1] > P[i] and P[i + 1] < P[i + 2]):
        res += 1
print(res)

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

cnt = 0
for i in range(n-2):
    i += 1
    L = [P[i-1], P[i], P[i+1]]
    L = sorted(L)
    if L[1] == P[i]:
        cnt += 1


print(cnt)

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

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

c = 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]:
        c += 1

print(c)

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

Solution (Python):

import sys
import collections

def main():
	
	n = int(input())
	p = list(input().split(" "))
	
	ans = 0
	for i, val in enumerate(p):
		if i == 0:
			continue
		if i+1 > n-1:
			continue
		fst = int(p[i-1])
		snd = int(p[i])
		srd = int(p[i+1])
		if snd != max(fst,snd,srd) and snd != min(fst,snd,srd):
			ans += 1
	
	
	print(ans)	
	
	
if __name__ == "__main__":
	main()

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

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

print(cnt)

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


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

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

print(result)

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

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

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

counter = 0

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

  else:
    if p[i+1] >= p[i]:
      counter += 1

print(counter)

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] < p[i + 2] or p[i] > p[i + 1] > p[i + 2]:
        cnt += 1
print(cnt)

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

cnt = 0

for i in range(1, N - 1) :
    
    if p[i] != max(p[i-1:i+2]) and p[i] != min(p[i-1:i+2]) :
        cnt += 1


print(cnt)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-2):
    p1, p2, p3 = p[i], p[i+1], p[i+2]
    aaa = [p1,p2,p3]
    aaa.sort()
    if aaa[1] == p2:
        ans += 1
print(ans)

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

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

num = 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]:
        num += 1

print(num)

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

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

left = [False] * n
right = [False] * n

for i in range(1, n):
    if p[i-1] < p[i]:
        left[i] = True

for i in range(n-1, 1, -1):
    if p[i] < p[i-1]:
        right[i-1] = True

count = 0
for i in range(1,n-1):
    if not(left[i] and right[i]):
        if left[i] or right[i]:
            count += 1

print(count)

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

for i in range(1, n-1):
    s = sorted(p[i-1:i+2])
    if(s[1] == p[i]):
        result += 1

print(result)

Solution (Python):
num = int(input())
numbers = str(input())

numbers = numbers.split(' ')
numbers = [int(n) for n in numbers]

cnt = 0
for i in range(1, num - 1):
    li = sorted([numbers[i - 1], numbers[i], numbers[i + 1]])
    if 1 == li.index(numbers[i]):
        cnt += 1

print(cnt)

Solution (Python):



n = int(input())
li = list(map(int,input().split()))
cntr = 0

for i in range(n - 2):
    li_tmp = li[i : (i + 3)]
    if li_tmp[1] != max(li_tmp) and li_tmp[1] != min(li_tmp):
        cntr += 1
print(cntr)

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()))

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

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

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

Solution (Python):

import time
import re
import math
import fractions

def main():
    global N,A,B,C,D,memo,mx,mn,temp
    N=int(input())
    P=list(map(int,input().split()))
    count=0
    for a in range(1,N-1):
        lst=[P[a-1],P[a],P[a+1]]
        lst.sort()
        if lst[2]==lst[1]:
            if lst[0]==P[a]:
                count+=1
        elif lst[0]==lst[1]:
            if not lst[2]==P[a]:
                count+=1
        else:
            if lst[1]==P[a]:
                count+=1
    print(count)


start=time.time()
main()

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

Solution (Python):
n = int(input())
ps = [int(p) for p in input().split(" ")]
ans = 0
for i in range(n-2):
  if ps[i] < ps[i+1] < ps[i+2]:
     ans += 1
  elif ps[i+2] < ps[i+1] < ps[i]:
     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-1] > P[i] and P[i] > P[i+1]:
    count += 1
  if P[i-1] < P[i] and P[i] < P[i+1]:
    count += 1
print(count)

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    p_list = list(map(int, input().split()))

    answer = 0
    for i in range(1,len(p_list)-1):
        p1 = p_list[i-1]
        p2 = p_list[i]
        p3 = p_list[i+1]

        tmp_p_list = [p1, p2, p3]
        tmp_p_list = sorted(tmp_p_list)

        if tmp_p_list[1] == p2:
            answer += 1
    print(answer)

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

ans = 0

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

    s.sort()

    if s[1] == p[i] :
        ans += 1

print(ans)

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

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

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

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

count = 0

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

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

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

Solution (Python):
def read():
    n = int(input().strip())
    p = list(map(int, input().strip().split()))
    return n, p


def solve(n, p):
    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
    return count


if __name__ == '__main__':
    inputs = read()
    print('%d' % solve(*inputs))

Solution (Python):
import sys

def solve(n, p):
    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

    return count


if __name__ == '__main__':

    n = sys.stdin.readline().strip()
    p = map(int, sys.stdin.readline().strip().split(" "))
    print solve(int(n), p)

Solution (Python):
import sys

cin = sys.stdin
N = int(cin.readline())
p = list(map(int, cin.readline().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 = list(map(int,input().split()))
lists = []
for i in range(1,len(p)-1):
    if p[i-1] < p[i] < p[i+1]:
        lists.append(p[i])
    elif p[i-1] > p[i] > p[i+1]:
        lists.append(p[i])
print(len(lists))

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



counter = 0
for i in range(1, n - 1):
    
    d = {"i-1": nums[i - 1], "i": nums[i], "i+1": nums[i + 1]}
    sorted_d = sorted(d.items(), key=lambda x: x[1], reverse=True)
    if sorted_d[1][0] == "i":
        counter += 1
print(counter)

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

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

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] < p[i+2]) or (p[i+2] < p[i+1] < p[i]):
        ans += 1

print(ans)

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] < p[i + 2] or p[i] > p[i + 1] > p[i + 2]:
        cnt += 1

print(cnt)

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

anscnt = 0
for i in range(1, len(plst) - 1):
    if plst[i - 1] < plst[i] and plst[i] < plst[i + 1]:
        anscnt += 1
    elif plst[i + 1] < plst[i] and plst[i] < plst[i - 1]:
        anscnt += 1

print(anscnt)

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

Solution (Python):
def input_from_console():
    n = int(input())
    p_list= list(map(int, input().strip().split()))
    return n, p_list


def solve(n, p_list):
    result = 0
    if n <= 2:
        return result
    for i in range(n - 2):
        if min(p_list[i], p_list[i+2]) < p_list[i+1] and max(p_list[i], p_list[i+2]) > p_list[i+1]:
            result += 1
    return result


def main():
    n, p_list = input_from_console()
    print(solve(n, p_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  
        check_cases()
    else:
        main()

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

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

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

ans = 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]):
        ans += 1
print(ans)

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

count = 0

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

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

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

def f(a, b, c):
    if a < b and b < c:
        return True
    if c < b and b < a:
        return True
    return False


ans = 0
for i in range(len(p) - 2):
    if f(p[i], p[i+1], p[i+2]):
        ans += 1

print(ans)

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

for i in range(1,N-1):
    if arr[i] > arr[i-1] and arr[i] > arr[i+1]:
        continue
    if arr[i] < arr[i-1] and arr[i] < arr[i+1]:
        continue
    count += 1

print(count)

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

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):
N = int(input())
p = [int(i) for i in input().split()]
Nres=0
for i in range(1,N-1):
    if p[i-1]<p[i] and p[i+1]>=p[i]:
        Nres+=1
    elif p[i+1]<p[i] and p[i-1]>=p[i]:
        Nres+=1

print(Nres)

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

c=0

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

print(c)

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

Solution (Python):

N = int(input())
p = list(map(int,input().split()))
idx = 3
cnt = 0
while idx<=N:   
    tmp = p[idx-3:idx]
    tmps = sorted(tmp)
    if tmp[1] == tmps[1]:
        cnt += 1
    idx += 1
print(cnt)

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

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

print(count)

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

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

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

s = p[:3]
ans = 0
for i in range(n-2):

    if s[1]>min(s) and s[1]<max(s):
        ans += 1
    if i == n-3:
        break
    s = s[1:]+[p[i+3]]
print(ans)

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

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

print(num)

Solution (Python):

def acinput():
    return list(map(int,input().split(" ")))


n=int(input())
p=acinput()

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):
n = int(input())
P = list(map(int, input().split()))
c = 0
for i in range(n-2):
    p = P[i:i+3]
    q = sorted(P[i:i+3])
    if p[1] == q[1]:
        c += 1
print(c)

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

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):
n = int(input())
p = list(map(int, input().split()))

count = 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]:
        count += 1

print(count)

Solution (Python):
from sys import stdin

N=int(stdin.readline().rstrip())
num_list=[int(x) for x in stdin.readline().rstrip().split()]
output=0
for n in range(N-2):
    if (num_list[n]-num_list[n+1])*(num_list[n+2]-num_list[n+1])<0:
        output+=1

print(output)

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

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())
A=list(map(int,input().split()))
count=0
for i in range(len(A)-2):
    if A[i]> A[i+1] and A[i+1]>A[i+2]:
        count+=1
    elif A[i]< A[i+1] and A[i+1]<A[i+2]:
        count+=1
print(count)

Solution (Python):


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

ans = 0
for i in range(len(p)-2):
    p1 = p[i]
    p2 = p[i+1]
    p3 = p[i+2]
    if p1 < p2 and p2 < p3:
        ans += 1
    elif p3 < p2 and p2 < p1:
        ans += 1

print(ans)

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

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

print(counter)

Solution (Python):
n = int(input())
ppp = list(map(int, input().split()))
ans = 0
for p, q, r in zip(ppp, ppp[1:], ppp[2:]):
    if sorted([p, q, r])[1] == q:
        ans += 1
print(ans)

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

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(1,n-1):
    if p[i]>p[i-1] and p[i]-1<p[i+1]:
        ans +=1
    elif p[i] > p[i + 1] and p[i] - 1 < 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-2):
    t = [p[i], p[i+1], p[i+2]]
    a = sorted(t)
    
    if t[1] == a[1]: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-1] > p[i] and p[i] > p[i+1]:
        count += 1
        continue
    if p[i-1] < p[i] and p[i] < p[i+1]:
        count += 1
print(count)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    p_lis=LIST()
    ct=0
    for i in range(1,n-1):
        if p_lis[i]>p_lis[i-1] and p_lis[i]<p_lis[i+1]:
            ct+=1
        elif p_lis[i]<p_lis[i-1] and p_lis[i]>p_lis[i+1]:
            ct+=1

    print(ct)



if  __name__=='__main__':
    main()

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

Solution (Python):
import numpy as np

n = int(input())
P = input()
P = P.split(' ')

count = 0
for i in range(1, n-1):
    p_1 = int(P[i-1])
    p_2 = int(P[i])
    p_3 = int(P[i+1])
    
    p_list = np.argsort([p_1, p_2, p_3])
    if p_list[1] == 1:
        count += 1
print(count)

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())
lista = [int(i) for i in input().split()]

ans = 0
for i in range(1,n-1):
    if lista[i-1]>lista[i]>lista[i+1]:
        ans+=1
    elif lista[i-1]<lista[i]<lista[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 sorted([p[i-1], p[i], p[i+1]])[1] == p[i]:
        ans += 1
print(ans)

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

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]:
        if p[i]<p[i+1]:
            cnt += 1
    if p[i-1]>p[i]:
        if p[i]>p[i+1]:
            cnt += 1

print(cnt)

Solution (Python):

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

cnt = 0
for i in range(1, n, 1):
    pi = ps[i]
    if pi != max(ps[i-1:i+2]) and pi != min(ps[i-1:i+2]):
        cnt += 1

print(cnt)

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+2]<p[i+1]<p[i]:
        count+=1
print(count)

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

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_s = [int(v) for v in input().split()]

ans = 0
for i in range(1, n - 1):
  if p_s[i - 1] < p_s[i] < p_s[i + 1] or p_s[i + 1] < p_s[i] < p_s[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 max(p[i-1],p[i],p[i+1]) == p[i]:
        ans += 0
    elif min(p[i-1],p[i],p[i+1]) == p[i]:
        ans += 0
    else:
        ans += 1
print(ans)

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]:
        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 = list(map(int, input().split()))
cnt = 0
for i in range(n - 2):
    a = list()
    a.append(p[i])
    a.append(p[i + 1])
    a.append(p[i + 2])
    check = p[i + 1]
    a.sort()
    if check == a[1]:
        cnt += 1
print(cnt)

Solution (Python):
n = int(input())
p = list(map(int, input().strip().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):

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



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

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
    j = max(0, i - 1)
    k = min(n - 1, i + 1)
    b = a[j:k+1]
    b.sort()
    ans += b[1] == a[i]

print(ans)

Solution (Python):
n = int(input())
l = [int(num) for num in input().split()]

count = 0

for i in range(len(l)-2) :
    part = l[i:i+3]
    part.sort(reverse=False)
    if (part.index(l[i+1]) == 1) :
        count += 1

print(count)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
cnt = 0
for i in range(1, n-1):
  p1 = A[i-1]
  p2 = A[i]
  p3 = A[i+1]
  if (p1 > p2 and p2 > p3) or (p3 > p2 and p2 > p1):
    cnt += 1
    
print(cnt)

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

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

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)

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+2] < p[i+1] and p[i+1] <= p[i])):
        ans += 1

print(ans)

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


count = 0

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

print(count)

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
input = stdin.readline().split()
mem = 0
cnt = 0
for i in range(N):
    if i == 0:
        continue
    if i == N-1:
        continue
    if int(input[i]) > int(input[i-1]) and int(input[i+1]) > int(input[i]):
        
        cnt += 1
    if int(input[i]) < int(input[i-1]) and int(input[i+1]) < int(input[i]):
        
        cnt += 1
print(cnt)

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]<p[i+2]:
        ans += 1
    elif p[i+2]<p[i+1]<p[i]:
        ans += 1

print(ans)

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

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

print(ans)

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

c = 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]):
    c += 1
print(c)

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

cnt =0
l=[]

for i in range(1,n-1):
    l.append(p[i-1])
    l.append(p[i])
    l.append(p[i+1])
    l.sort()
    
    if l[1]==p[i]:
        cnt+=1
    l = []

print(cnt)

Solution (Python):


N = int(input().rstrip())
p_s = input().split()
p = [int(s) for s in p_s]

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)

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

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

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

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

Solution (Python):
n = int(input())
L = list(map(int,input().split()))
def f(t):
    return t[0] > t[1] and t[1] > t[2] or t[0] < t[1] and t[1] < t[2]
count = 0
for i in range(n - 2):
    if (f(L[i:])):
        count += 1
print(count)

Solution (Python):


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

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

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for idx,val in enumerate(p):
    if idx == 0:
        continue
    elif idx == n - 1:
        break
    if val < max(p[idx - 1], p[idx + 1]) and val > min(p[idx - 1], p[idx + 1]):
        cnt += 1

print(cnt)

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

ans = 0
A = [0,0,0]
for i in range(1, n-1):
    A = [P[i-1],P[i],P[i+1]]
    A.sort()
    if A[1] == P[i]:
        ans += 1

print(ans)

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

for i in range(1,n-1):
    x = [ p[i-1], p[i], p[i+1] ]
    x.sort()
    if x[1] == p[i]:
        cnt +=1

print(cnt)

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

count=0
for i in range(0,n-2):
    if line[i]<line[i+1]<=line[i+2]:
        count+=1
    elif line[i+2]<line[i+1]<=line[i]:
        count+=1

print(count)

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

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