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


c = 0
for i in range(n-2):
    alist = []
    alist.append(line[i])
    alist.append(line[i+1])
    alist.append(line[i+1+1])
    if alist[0] == max(alist) and alist[2] == min(alist):
        c += 1
    elif  alist[0] == min(alist) and alist[2] == max(alist):
        c += 1
    else:
        pass
print(c)

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

Solution (Python):
def con(n, lists):
  cnt = 0
  for i in range(1, n-1):
    if lists[i-1] > lists[i] > lists[i+1] or lists[i+1] > lists[i] > lists[i-1]:
      cnt += 1
  return cnt

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

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

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):
import collections

n = int(input())
p = list(map(int, input().split()))
count2 = []
for i in range(1, n-1):
    count = []
    count.append(p[i-1])
    count.append(p[i])
    count.append(p[i+1])
    count.sort()
    if(count[1] == p[i]):
        count2.append(count[1])
ans = collections.Counter(count2)
print(len(ans))

Solution (Python):
import numpy as np

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

cnt = 0
for i in range(1,len(l)-1):
    l_tmp = [l[i-1], l[i], l[i+1]]
    l_tmp.sort()
    arr_tmp = np.array(l_tmp)
    if len(arr_tmp[arr_tmp>l[i]])==1:
        cnt += 1
        
print(cnt)

Solution (Python):
n = int(input())
p = [int(i) for i in input().split()]
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()))
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())
l = [int(i) for i in input().split()]
count = 0
for i in range(len(l) - 2):
    ll = l[i:i + 3]
    ll.sort()
    if ll[1] == l[i+1]:
        count += 1
print(count)

Solution (Python):
n=int(input())
l=[int(i) for i in input().split()]
cnt=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]:
        cnt+=1
print(cnt)

Solution (Python):
N = int(input())
num_list = list(int(i) for i in input().split())
ans = 0
for i in range (N-2):
	if num_list[i+1] > num_list[i]:
		if num_list[i+2] > num_list[i+1]:
			ans +=1
	else:
		if num_list[i+1] > num_list[i+2]:
			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] >= p[i+1] > p[i+2] or p[i] < p[i+1] <= p[i+2]:
    counter += 1
print(counter)

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

ans=0
for ii in range(1,n-1):
    p_order = sorted(list([p[ii-1],p[ii],p[ii+1]]))
    if p_order.index(p[ii]) == 1 and p_order[0] != p_order[1]:
        ans += 1

print(ans)

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

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

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

Solution (Python):
n = int(input())
p = [int(x) for x in input().split()]
print(sum([1 if min(p[i:i+3]) < p[i+1] < max(p[i:i+3]) else 0 for i in range(n-2)]))

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

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

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

count = 0
for i in range(len(P)-2):
    p1 = P[i]
    p2 = P[i+1]
    p3 = P[i+2]
    
    if p1 < p2 < p3 or p3 < p2 < p1:
        count += 1

print(count)

Solution (Python):
N = int(input())
l = list(map(int, input().split()))
c = 0
for j in range(0,N-2):
    if l[j]<l[j+1]<l[j+2] or l[j+2]<l[j+1]<l[j] or (l[j]==l[j+2] and l[j]<l[j+1]) or (l[j]==l[j+2] and l[j]<l[j+1]) or (l[j]==l[j+1] and l[j+2]<l[j+1]) or (l[j+1]==l[j+2] and l[j]<l[j+1]):
        c+=1
print(c)

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

cnt = 0
for idx in range(n - 2):
    if min(p[idx:idx + 3]) != p[idx + 1] and max(p[idx:idx + 3]) != p[idx + 1]:
        cnt += 1
print(cnt)

Solution (Python):
n=int(input())
P=[int(x) for x in input().split()]
count=0
for i in range(n-2):
  p1=P[i]
  p2=P[i+1]
  p3=P[i+2]
  if p2>p1 and p2<p3:
    count+=1
    
  if p2>p3 and p2<p1:
    count+=1
print(count)

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

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

Solution (Python):



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

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

for i in range(n-2):
    aim = p_list[i+1]
    tmp_list = [p_list[i], p_list[i + 1], p_list[i + 2]]
    tmp_list.sort()
    if tmp_list[1] == aim:
        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] > 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):
N = int(input())
a = list(map(int, input().split()))
start = 0
end = 3
counter = 0
for i in range(N-2):
    ls = a[start:end]
    if ls[0] < ls[1] and ls[2] < ls[1]:
        counter = counter
        start = start + 1
        end = end + 1
    elif ls[1] < ls[0] and ls[1] < ls[2]:
        counter = counter
        start = start + 1
        end = end + 1
    else:
        counter = counter + 1
        start = start + 1
        end = end +1
print(counter)

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

S = 0

for i in range(N-2):
	if P[i] <= P[i+1]:
		if P[i+1] < P[i+2]:
			S += 1
			continue
	if P[i+2] <= P[i+1]:
		if P[i+1] < P[i]:
			S += 1
			continue
	if (P[i+2] == P[i]) & (P[i+1] > P[i]):
		S += 1
print(S)

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

Solution (Python):
import numpy

N = int(input())
p = numpy.asarray(list(map(int,input().split())))

p_diff = numpy.diff(p)


p_diff = numpy.where(p_diff > 0, 1, -1)

p_diff2 = numpy.diff(p_diff)

print(len(p_diff2[p_diff2 == 0]))

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n-2):
  lst=[p[i],p[i+1],p[i+2]]
  m=min(lst)
  P=p[i+1]
  del lst[lst.index(m)]
  if min(lst)==P:
    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] 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()))
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()))
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())
list = list(map(int, input().split()))

count = 0

for i in range(1, len(list)-1):
    num = list[i]
    if (num > list[i-1] and num < list[i+1]) or (num < list[i-1] and num > list[i+1]):
        count += 1

print(count)

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):
if __name__ == '__main__':
    input()
    a = list(map(int, input().split()))
    count = 0
    for i in range(0, len(a) - 2):
        old = a[i:i + 3]
        new = sorted(old)
        if old[1] == new[1]:
            count += 1
    print(count)

Solution (Python):
N = input()
P = list(input().split())
count = 0

for i in range(len(P)-2) :
	judge_list = list() 
	midle = int(P[i+1])
	judge_list.extend([int(P[i]),int(P[i+1]),int(P[i+2])])
	judge_list.sort()

	if midle == judge_list[1]:
		count+=1
print(count)

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

cnt = 0

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

print(counter)

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

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

count=0
for i in range(n-2):
  ext=[]
  for k in range(3):
    ext.append(li[i+k])
    
  ext.sort()
  if ext[1]==li[i+1]:
    count+=1
    
print(count)

Solution (Python):



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

l = n - 2

r = 0

for i in range(l):
    l2 = p[i:3+i]
    if l2[0] < l2[1]:
        if l2[1] < l2[2]:
            r += 1
    else:
        if l2[1] > l2[2]:
            r += 1

print(r)

Solution (Python):
N = int(input())
lst = list(map(int, input().split()))
score = 0
for i in range(N-2):
	if (lst[i]-lst[i+1])*(lst[i+2]-lst[i+1]) < 0:
		score += 1
	else:
		pass
print(score)

Solution (Python):
import numpy as np

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

cnt=0
for i in range(1, n-1):
    tmp = np.array([p[i-1], p[i], p[i+1]])
    if np.argsort(tmp)[1] == 1:
        cnt+=1

print(cnt)

Solution (Python):
def ordinary_number(N: int, p: list)->int:
    return sum(
        (p[i-1] < p[i] and p[i] < p[i+1]) or (p[i-1] > p[i] and p[i] > p[i+1])
        for i in range(1, N-1))


if __name__ == "__main__":
    N = int(input())
    P = [int(s) for s in input().split()]

    ans = ordinary_number(N, P)
    print(ans)

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

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

print(count)

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

print(count)

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
ans=0
for c in range(1,n-1):
    a=[arr[c-1],arr[c],arr[c+1]]
    a.sort()
    if a[1]==arr[c]:
        ans+=1
print(ans)

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

answer=0
for i in range(len(lists)-2):
    tmp = lists[i:i+3]
    if(max(tmp)==tmp[1] or min(tmp)==tmp[1]):
        continue
    answer+=1

print(answer)

Solution (Python):

if __name__=='__main__':
    n = int(input())
    p = [int(x) for x in input().split()]
    q = [1 if p[i]<p[i+1] else -1 for i in range(n-1)]
    r = [q[i]*q[i+1] for i in range(n-2)]
    print(r.count(1))

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

Solution (Python):






import sys
import math
import array


class mymath:
    
    pi = 3.14159265358979323846264338

    
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()


class output:
    
    def list(self, l):
        l = list(l)
        
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()



















def main():
    
    N = int(input())
    P = None
    A = []
    P = [int(w) for w in input().split()]

    for i in range(N-2):
        if P[i] < P[i+1] < P[i+2]:
            A.append(P[i+1])
        elif P[i] > P[i+1] > P[i+2]:
            A.append(P[i+1])

    print(len(A))

if __name__ == '__main__':
    main()

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

Solution (Python):
s = int(input())
n = list(map(int,input().split()))
S = []
count=0
for i in range(1,len(n)-1):
    S = []
    S.extend(n[i-1:i+2])
    S.sort()
    if S[1]==n[i]:
        count+=1
    del S    
print(count)

Solution (Python):
import re
import numpy as np


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

flag=0
for i in range(N-2):
  p0=ps[i]
  p1=ps[i+1]
  p2=ps[i+2]
  
  if np.sort(np.array([p0,p1,p2]))[1]==p1:
    flag+=1
print(flag)

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

Solution (Python):
import sys
inputs = sys.stdin.readlines()
n = int(inputs[0])
p = [int(x) for x in inputs[1].split(' ')]

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

print(counter)

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

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

print(ans)

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

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

print(ans)

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

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

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

Solution (Python):
str = input()
n = int(str.split()[0])

p = []
pS = input()
for i in range(n) :
	p.append(int(pS.split()[i]))
	
a = 0
for i in range(len(p) - 2) :
	if (p[i] < p[i+1]) :
		if (p[i + 1] < p[i + 2]) :
			a+=1
	elif(p[i] > p[i + 1]) :
		if (p[i + 1] > p[i + 2]) :
			a+=1

print(a)

Solution (Python):
from collections import deque
n=int(input())
p=list(map(int, input().split()))

Q=deque(maxlen=3)
Q.append(p[0])
Q.append(p[1])

count = 0
for i in range(2,n):
    Q.append(p[i])
    
    if Q[0] <= Q[1] <= Q[2] or Q[2] <= Q[1] <= Q[0]:
        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] - p[i-1]) * (p[i] - p[i+1]) < 0:
        ans += 1
print(ans)

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

print(count)

Solution (Python):










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

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

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

print(sum)

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

def niban(i,list):
    if list[i]<list[i+1]<list[i+2] or list[i+2]<list[i+1]<list[i]:
      
       return 1
    else:
       
       return 0



for i in range(n-2):
    if niban(i,plist):
        count += 1

print(count)

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

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

print(cnt)

Solution (Python):
import numpy as np

N = int(input())

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

count = 0

for i in range(N-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()))
cnt=0
for i in range(n-2):
    a=[]
    for j in range(3):
        a.append(p[i+j])
    a.sort()
    if a[1]==p[i+1]:
        cnt+=1
print(cnt)

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

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

Solution (Python):
def secc(a,b,c):
    k =[]
    k.append(a)
    k.append(b)
    k.append(c)
    k.sort()
    if(k[1]==b):
        return True
    else:
        return False
n = int(input())
a = list(map(int,input().split()))
c =0 
for i in range(1,n-1):
    if(secc(a[i-1],a[i],a[i+1])):
        c+=1 
print(c)

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

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
X = []
for i in range(1,n-1):
  A = [p[i-1],p[i],p[i+1]]
  A.sort()
  if p[i]==A[1]:
    X.append(p[i])
print(len(X))

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

result = 0

for count in range(N-2):
    sliced_list = numbers[:3]
    if min(sliced_list) != sliced_list[1] and max(sliced_list) != sliced_list[1]:
        result = result + 1
    numbers.pop(0)
print(result)

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

ans = 0
for i in range(1, n - 1):
    P_list = [P_n[i - 1], P_n[i], P_n[i + 1]]
    P_list.sort()

    if P_n[i] == P_list[1]:
        ans += 1

print(ans)

Solution (Python):
num = int(input())
numbers = [ int(i) for i in input().split()]
count = 0
for i in range(len(numbers)):
    if i == 0:
        continue
    elif i == num-1:
        continue
    else:
        if numbers[i] < numbers[i-1] and numbers[i] > numbers[i+1]:
            count +=1
        elif numbers[i] > numbers[i-1] and numbers[i] < numbers[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):
    p1,p2,p3 = p[i:i+3]
    if p1 < p2 < p3 or p1 > p2 > p3:
        count += 1
print(count)

Solution (Python):
num = int(input())
seq = input().split()

sequence = [int(i) for i in seq]
count = 0

for i in range(len(sequence)-2):
  subseq = sorted(sequence[i:i+3])
  if sequence[i+1]==subseq[1]: count += 1
  
print(count)

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

cnt = 0

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

print(cnt)

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

Solution (Python):
N = int(input())
nump = input().split()
nump = [int(i) for i in nump]

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

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 and c > b ):
     count = count + 1 
  elif(c < b and a > b ):
     count = count + 1 

print(count)

Solution (Python):
import sys 
def ordinary():
    n=int(input())
    p=list(map(int, input().split()))
    countour=0
    for i in range(1,n-1):
        if ((p[i-1] <p[i] ) & (p[i] < p[i+1])) or ((p[i-1] > p[i] )& (p[i] > p[i+1])):
            countour+=1
    
    print(countour)

ordinary()

Solution (Python):
import sys


def main():
    n = sys.stdin.readline().strip()
    p_s = sys.stdin.readline().strip()
    p = [int(s) for s in p_s.split()]
    ans = 0
    for i in range(len(p)-2):
        sorted_three = sorted(p[i:i+3])
        if sorted_three[1] == p[i+1] and sorted_three[0] < p[i+1]:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

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

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

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

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

cnt=0
for i in range(num-2):
    if list_A[i] < list_A[i+1] and list_A[i+1] < list_A[i+2]:
        cnt += 1
    elif list_A[i] > list_A[i+1] and list_A[i+1] > list_A[i+2]:
        cnt += 1

    else:
        pass

print(cnt)

Solution (Python):


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

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

print(cnt)

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

Solution (Python):
n = int(input())
p = tuple(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())
count = 0
a = input()
list1 = list(map(int,a.split()))

for i in range(1,N-1):
    if list1[i-1] < list1[i] < list1[i+1]:
        count +=1
    elif list1[i+1] < list1[i] < list1[i-1]:
        count +=1

print(count)

Solution (Python):
a = input()
b = list(map(int,input().split()))

total = 0
for i in range(len(b) - 2):
  templist = [b[i], b[i+1], b[i+2]]
  if b[i+1] != max(templist) and b[i+1] != min(templist):
    total += 1

print(total)

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

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

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

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

print(s)

Solution (Python):



n = int(input())
array_p = [int(i) for i in input().split(' ')]

def is_second(input_list):
    sort = sorted(input_list)
    if input_list[1] == sort[1]:
        return True
    else:
        return False

count = 0
for i in range(1, n - 1):
    if is_second(array_p[i - 1 : i + 2]):
        count += 1

print(count)

Solution (Python):


def main():
    
    
    
    
    
    
    
    
    n = int(input())
    p_list = list(map(int, input().split()))
    cnt = 0
    for i in range(1, n-1):
        if min(p_list[i-1],p_list[i+1])<p_list[i] and p_list[i]<=max(p_list[i-1],p_list[i+1]):
            cnt += 1
        else:
            pass
    print(cnt)



if __name__=='__main__':
    main()

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

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

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

answer = 0

prev_bigger = P[0] < P[1]
for i in range(2, N):
    current_bigger = P[i-1] < P[i]
    if prev_bigger and current_bigger:
        answer += 1
    elif not prev_bigger and not current_bigger:
        answer += 1
    prev_bigger = current_bigger

print(answer)

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

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= map(int, input().split())
W = list(map(int, input().split()))
ans_max=0
ans_min=0
for i in range(1,len(W)-1,1):
    if(W[i]==max(W[i-1],W[i],W[i+1])):
        ans_max = ans_max+1
    if(W[i]==min(W[i-1],W[i],W[i+1])):
        ans_min = ans_min+1


print(len(W)-2-(ans_max+ans_min))

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

print(A)

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

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

Solution (Python):
def code_for_B(test=None):

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

    pre = list_p[0]
    count = 0

    for i in range(1,n-1):
        cur = list_p[i]
        nxt = list_p[i+1]

        if pre >= cur > nxt:
            count += 1
        elif pre < cur < nxt:
            count += 1

        pre, cur = cur, nxt

    print(count)

code_for_B()

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

answer = 0

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

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

ans = 0

for i in range(n - 2):
    li = [p_list[i], p_list[i + 1], p_list[i + 2]]
    li.sort()
    if li[1] == p_list[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=count+1
print(count)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
cnt=0
for i in range(1,N-1):
   b=[A[i-1],A[i],A[i+1]]
   b.sort()
   if b[1]==A[i]:
      cnt+=1
print(cnt)

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

count=0

for i in range(n-1):
    if i == 0:
        count=0
    elif v[i-1] < v[i] < v[i+1] or v[i-1] > v[i] > v[i+1]:
        count=count+1

print(count)

Solution (Python):

n = int(input())

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

ans = 0

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

print(ans)

Solution (Python):

n = int(input())
arr = [int(i) for i in input().split(" ")]
l = len(arr)
count = 0
for i in range(0, l-2):
    m = arr[i+1]
    tmp = [arr[i], arr[i+1], arr[i+2]]
    tmp.sort()
    if m == tmp[1]:
        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] > 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()))
count = 0
for i in range(n-2):
  if (p[i]-p[i+1])*(p[i+2]-p[i+1]) < 0:
    count+=1
print(count)

Solution (Python):

import sys

n = int(input())
s = [int(c) for c in input().split(' ')]

count = 0

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

print(count)