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()]
ans = 0

def second_smallest(numbers):
    m1, m2 = float('inf'), float('inf')
    for x in numbers:
        if x <= m1:
            m1, m2 = x, m1
        elif x < m2:
            m2 = x
    return m2

for i in range(n-1):
  if i != 0:
    a = p[i-1:i+2]
    if a[0] != a[1] and a[1] != a[2] and a[0] != a[2]:
      if p[i] == second_smallest(a):
        ans += 1
print(ans)

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

cnt = 0
for i in range(n):
    tmp = list(map(int, p[i:i+3]))
    if len(tmp) == 3:
        if (tmp[0] < tmp[1] and tmp[1] < tmp[2]) or (tmp[1] < tmp[0] and tmp[2] < tmp[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):
    if p[i-1]<=p[i]<p[i+1] or p[i+1]<=p[i]<p[i-1] :
        ans+=1

    else:
        ans==ans
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])*( p[i] - p[i+1] ) > 0:
        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())
input_list = [int(i) for i in input().split(' ')]

count = 0
past = None
past_diff = None
for i in input_list:
    if past:
        if past_diff is not None and (i - past) * past_diff > 0:
            count += 1
        past_diff = i - past
    past = i

print(count)

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

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

meet_cond = 0
for i in range(0, num_input-3+1):
    x, y, z = arr[i], arr[i+1], arr[i+2]

    if min(x, y, z) == y or max(x, y, z) == y:
        pass
    else:
        meet_cond += 1

print(meet_cond)

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

cnt = 0

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

print(cnt)

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

	if i!=0 and i!=N-1:
		if (P[i+1]<P[i] and P[i+1]<=P[i-1] and P[i]<=P[i-1])or(P[i-1]<P[i] and P[i-1]<=P[i+1] and P[i]<=P[i+1]):
			mes+=1
print(mes)

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

cnt=0
lop=0

while lop<N-2:
  if max(D[lop],D[lop+1],D[lop+2])!=D[lop+1] and min(D[lop],D[lop+1],D[lop+2])!=D[lop+1]:
    cnt=cnt+1
  lop=lop+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):
n = int(input())
ns = input().split(" ")
for i in range(n):
    ns[i] = int(ns[i])

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

print(count)

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

Solution (Python):
coin = 0
def check(Pn,a,coin):
    if Pn[a - 1] < Pn[a] < Pn[a + 1]:
        coin = coin + 1
    elif Pn[a + 1] < Pn[a] < Pn[a - 1]:
        coin = coin + 1
    else:
        coin = coin + 0
    return coin
n = int(input())
Pn = list(map(int,input().split()))
for a in range(1,n-1):
    coin = check(Pn,a,coin)
print(coin)

Solution (Python):


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

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

Solution (Python):
n=input()
s=input()
s=s.replace(" ",",")
s=str(s).split(",")
l=list(s)
a=0
for i in range(2,int(n)):
  if int(l[i-2])<int(l[i-1]) and int(l[i-1])<int(l[i]):
    a=a+1
  if int(l[i-2])>int(l[i-1]) and int(l[i-1])>int(l[i]):
    a=a+1
print(a)

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

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






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

Solution (Python):

n = int(input())
p = input().split()
p = [int(i) for i in p]
count = 0
for i in range(n-2):
    if p[i+1] <max(p[i:i+3]) and p[i+1]>min(p[i:i+3]):
      count +=1
print(count)

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

print(c)

Solution (Python):
import heapq

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

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

print(count)

Solution (Python):
import os, sys, re, math

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

cnt = 0
for i in range(1,N-1):
    temp = s[i-1:i+2]
    temp.sort()
    if temp[1] == s[i]:
        cnt += 1
print(cnt)

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

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

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



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

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

count = 0

i = 1
while i < N - 1:
    if pp[i - 1] < pp[i] < pp[i + 1] or pp[i - 1] > pp[i] > pp[i + 1]:
        count += 1
    i += 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]:
        cnt += 1
    elif p[i]>p[i+1] and p[i+1]>p[i+2]:
        cnt += 1
print(cnt)

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

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

Solution (Python):
import sys
import re
from collections import Counter

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

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

print(ans)

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

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

  	count=count+1
  else:
  	next
    
print(count)

Solution (Python):
n=int(input())
t =list(map(int, input().split()))
s=0
counter=0
for i in t:
    if s==0:
        s+=1
        left=i
        continue
    if s==1:
        s+=1
        mid=i
        continue

    if left>mid:
        if mid>i:
            counter+=1
    if left<mid:
        if mid<i:
            counter+=1
    left=mid
    mid=i

print(counter)

Solution (Python):


N = int(input())
P = list(map(int,input().split()))
sm = 0
for i in range(len(P)-2):
    sm += int(sorted(P[i:i+3])[1]==P[i+1])
print (sm)

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

Solution (Python):




from sys import stdin

N = int(stdin.readline())
P = [int(x) for x in stdin.readline().rstrip().split()]

cnt = 0

for i in range(N-2):
    tmp_list = P[i:i+3]
    tmp_list_unique = list(set(tmp_list))
    tmp_list_unique.sort()
    if tmp_list_unique[1] == tmp_list[1]:
        cnt += 1


print(cnt)

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

print(count)

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

a = []
for i in range (N-1):
    a.append(P[i+1] - P[i])

ans = 0
for i in range (N-2):
    if a[i+1]/a[i] > 0:
        ans = ans + 1
print(ans)

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 += 1
print(a)

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
  else:
    pass
  
print(count)

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

Solution (Python):
n=int(input())
str=input()
p_str=str.split(" ")
p=[int(tmp) for tmp in p_str]
count=0

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

print(count)

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

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

print(l)

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

    print(len([i for i in range(1, n - 1) if sorted([p[i - 1], p[i], p[i + 1]]).index(p[i]) == 1]))

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 i in range(1, n -1):
    if (p[i - 1] < p[i] and p[i] < p[i + 1]) or (p[i - 1] > p[i] and p[i] > p[i + 1]):
        count += 1
print(count)

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

d = []
for i in range(n):
    d.append(int(d_a[i]))

ans = 0
for i in range(1,n-1):
    a = []
    a.append(d[i-1])
    a.append(d[i])
    a.append(d[i+1])
    
    asd = sorted(a)
    if asd[1] == d[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] and p[i+1] > p[i+2]) or (p[i] < p[i+1] and p[i+1] < p[i+2]) or (p[i] == p[i+2] and p[i+1] > p[i]):
        cnt += 1
print(cnt)

Solution (Python):
from sys import stdin

n = int(stdin.readline())
p = [int(x) for x in stdin.readline().rstrip().split()]
count = 0

for i, pi in enumerate(p):
    if i == 0:
        continue
    elif i == n-1:
        break
    tmplist = sorted([pi, p[i-1], p[i+1]])
    if pi == tmplist[1]:
        count = count + 1

print(count)

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

count=0
for i in range(0,N-2):
  tmp = [P[i],P[i+1],P[i+2]]
  tmp.sort()
  if P[i+1]==tmp[1]:
    count+=1
  elif tmp[0]==tmp[1] or tmp[0]==tmp[2]:
    count+=1

print(count)

Solution (Python):
n = int(input())
c = list(map(int, input().split()))
count=0
for i in range(1, n-1):
  temp = []
  temp.append(c[i-1])
  temp.append(c[i])
  temp.append(c[i+1])
  temp.sort()
  if c[i] == temp[1]:
    count += 1
    
print(count)

Solution (Python):
import sys
from collections import Counter
from operator import itemgetter, attrgetter
n=0
 
n = input()
d_list= list(map(int, input().split()))
cnt=0
for i in range(1,len(d_list)-1):
    b=d_list[i-1]
    m=d_list[i]
    a=d_list[i+1]
    if (b< m <a) or (a< m< b):
        cnt+=1
        
    
print(cnt)

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

result = 0

number_list = []

for i in numbers:
	number_list.append(i)
	if len(number_list) < 3:
		continue
	elif len(number_list) > 3:
		number_list.pop(0)

	sorted_list = sorted(number_list)
	
	if sorted_list[1] == number_list[1]:
		result += 1

print(result)

Solution (Python):
n = int(input())
P = [int(i) for i 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())
pa = list(map(int, input().split()))

c = 0
for i in range(1, len(pa) - 1):
    ll = pa[i-1:i+2]
    ls = sorted(ll)
    if ll[1] == ls[1]:
        c += 1
print(c)

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

cnt = 0
l_ext = []

for i in range(n-2):
  l_ext.clear()
  l_ext.append(l[i])
  l_ext.append(l[i+1])
  l_ext.append(l[i+2])
  if sorted(l_ext)[-2] == l_ext[1]:
    cnt += 1
  i += 1

print(cnt)

Solution (Python):
from sys import stdin
from heapq import nsmallest

n = int(stdin.readline())
p = [int(x) for x in stdin.readline().rstrip().split()]



cnt = 0

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

print(cnt)

Solution (Python):
N = int(input())
S = [int(x) for x in input().split()]
count=0
for i in range(1,N-1):
  l=[S[i-1],S[i],S[i+1]]
  l.sort()
  if l[1]==S[i]:
    count+=1
    
print(count)

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

print(cnt)

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

Solution (Python):

n = input()
a = [int(i)for i in input().split(" ")]
ans = 0
for i in range(int(n)-2):
	if a[i+1] != max(a[i:i+3]) and a[i+1] != min(a[i:i+3]):
		ans += 1
print(ans)

Solution (Python):
a = [input().split() for i in range(2)]
li = a[-1]
lis = [int(i) for i in li]
lis
n = int(a[0][0])
cnt = 0
for i in range(0,n-2):
    l = [lis[i],lis[i+1],lis[i+2]]
    l_sort = sorted(l)
    if(l[1] == l_sort[1]):
        cnt += 1

print(cnt)

Solution (Python):
import numpy as np
n = int(input())
p = list(map(int, input().split()))
count = 0

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

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

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

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

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

print(count)

Solution (Python):

def logic():
  n = int(input())
  b = list(map(int, input().split()))
  count = 0
  i = 1
  while i < n - 1:
    if b[i] < b[i - 1]:
      if b[i] > b[i + 1]:
        count += 1
    elif b[i] < b[i + 1]:
      if b[i] > b[i - 1]:
        count += 1
    i += 1
  print(count)



if __name__ == '__main__':
    logic()

Solution (Python):
k = 0
a = input()

lista = input().split()

for c in range(1, len(lista)-1):

    if int(lista[c-1]) > int(lista[c]) > int(lista[c+1]) or int(lista[c-1]) < int(lista[c]) < int(lista[c+1]):
        k += 1

print(k)

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

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

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

print(a)

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

Solution (Python):
k = 0
a = input()

lista = input().split()

for c in range(1, len(lista)-1):

    if int(lista[c-1]) > int(lista[c]) > int(lista[c + 1]) or int(lista[c - 1]) < int(lista[c]) < int(lista[c + 1]):
        k += 1

print(k)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
oc = 0
c = 0

for i in l[1:n-1]:
    nl = sorted(l[oc:oc+3])
    if i == nl[1]:
        c += 1
    oc += 1

print(c)

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

Solution (Python):
def min_count(nums):
    c = 0
    for i in range(len(nums)-2):
        if nums[i]<nums[i+1]<nums[i+2]:
            c = c + 1
        elif nums[i+2]<nums[i+1]<nums[i]:
            c = c + 1
    return c
a = input()
b = map(int,input().split())
c =[]
for x in b:
	c.append(x)
print(min_count(c))

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

Solution (Python):
n = int(input())
ppp = list(map(int,input().split()))
cnt = 0
mini = 0
maxx = 0
p = [0]*3

for i in range(n-2):
    p[0] = ppp[i]
    p[1] = ppp[i+1]
    p[2] = ppp[i+2]
    
    mini = min(p)
    maxx = max(p)
    
    if mini != p[1]:
        if maxx != p[1]:
            cnt += 1
        
print(cnt)

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

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

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

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

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

c = 0
for i in range(1, n):
    i0 = i -1
    i1 = i + 1
    if (p[i] > p[i0]) & (p[i] < p[i1]):
        c += 1
    elif (p[i] < p[i0]) & (p[i] > p[i1]):
        c += 1
    else:
        c += 0    
print(c)

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

for  j  in range(a-2):
    d = []
    d.append(c[j])
    d.append(c[j+1])
    d.append(c[j+2])
    d.sort()
    if d[1]==c[j+1]:
          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] > p[i] or p[i+1] > p[i+2]) and (p[i+1] < p[i] or p[i+1] < p[i+2]):
    cnt += 1

print(cnt)

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

counter = 0

for i in range(n-2):
  min_list = []
  min_list.append(Data[i])
  min_list.append(Data[i+1])
  min_list.append(Data[i+2])
  if min_list[1] != min(min_list) and min_list[1] != max(min_list):
    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] < p[i+2]:
        s += 1
    elif p[i] > p[i+1] > p[i+2]:
        s += 1
print(s)

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

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

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
i = 2
m = 0
while(i<n):
    x = p[i-2]
    y = p[i-1]
    z = p[i]
    if(x<y<z or x>y>z):
        m += 1
    i += 1
print(m)

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+1] > P[i] or P[i-1] > P[i] and P[i] > P[i+1]:
        count += 1

print(count)

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],max(p[i],p[i+1])) and p[i]!=min(p[i-1],min(p[i],p[i+1])):
        cnt+=1
print(cnt)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
count=0
for i in range(n):
    if i >=1 and i < 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]):
            count = count + 1

print(count)

Solution (Python):
b = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
count=0
list=[]
for i in range(1,len(a)-1):
    list.append(a[i-1])
    list.append(a[i])
    list.append(a[i+1])
    if not max(list) == a[i] and not min(list)==a[i]:
        count+=1
    list=[]
print(count)

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

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

ans = 0

for i in range(1,len(li) - 1):
    if li[i - 1] < li[i] < li[i + 1]:
        ans += 1
    if li[i + 1] < li[i] < li[i - 1]:
        ans += 1

print(ans)

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

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

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

Solution (Python):
import collections
def hit(t):
    sort_t = sorted(t)
    return sort_t[1] == t[1]

n = int(input())
ps = [int(x) for x in input().split()]
window_ps=[]
for i in range(len(ps)-2):
    window_ps.append((ps[i],ps[i+1],ps[i+2]))

res = [hit(t) for t in window_ps]
print(collections.Counter(res)[True])

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

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

    elif nums[i-1]>nums[i] and nums[i]>nums[i+1]:
        cnt+=1
print(cnt)

Solution (Python):
s=input()
t=list(map(int,input().split()))
i=0
j=0
l=int(s)
for i in range(l-2):
  list=[t[i],t[i+1],t[i+2]]
  if t[i+1]!=max(list) and t[i+1]!=min(list):
    j=j+1
print(j)

Solution (Python):
import numpy as np
n = input()
n = int(n)
data = input().split()
count = 0

for i in np.arange(1, n-1):
  a = int(data[i-1])
  b = int(data[i])
  c = int(data[i+1])
  arr = np.array([a, b, c])
  arr = np.sort(arr)
  if arr[1] == b:
    count += 1

print(count)

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

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

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

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

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

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


print(ans)

Solution (Python):
N=int(input())
a=list(input().split())
for i in range(N):
    a[i]=int(a[i])
ans=0
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]):
        ans+=1
print(ans)

Solution (Python):
n = int(input())
n_list = list(map(int,input().split()))
a = 0
for i in range(n - 2):
    num = n_list[i:(i + 3)]
    n1 = num[0]
    n2 = num[1]
    n3 = num[2]
    if ((n2 < n1 or n2 < n3) and (n2 > n1 or n2 > n3)):
        a += 1
print(a)

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

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

res_sum = 0

for i in range(n-2):
    res = True
    p, q, r = p_list[i], p_list[i+1], p_list[i+2]
    if q == min(p, q, r):
        res = False
    elif p == min(p, q, r) and r == min(p, q, r):
        res = False
    elif p == min(p, q, r):
        if q > r:
            res = False
    else:
        if q > p:
            res = False
    if res:
        res_sum += 1

print(res_sum)

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

Solution (Python):
N = int(input())
huga = input().split()
p = []
for i in range(N):
  p.append(int(huga[i]))
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):

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

count = 0

for i in range(n-2):
    num_id = i+1
    temp = [num_list[num_id-1], num_list[num_id], num_list[num_id+1]]
    list_sorted = sorted(temp, reverse=True)
    if list_sorted[1] == num_list[num_id]:
        count += 1


print(count)

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

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

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

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

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

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

cnt = 0

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

print(cnt)

Solution (Python):
n = input()
p = list(map(int,input().split()))
res = 0
for i, num in enumerate(p):
	if(1 <= i and i <= (len(p) - 2)):
		li = [p[i-1],p[i],p[i + 1]]
		li.sort()
		if((p[i-1] != p[i + 1]) and (p[i-1] != p[i]) and (p[i] != p[i + 1]) and (li[1] == p[i])):
			res = res + 1
print(res)

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

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

Solution (Python):

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

ans = 0
for i in range(1,n-1):
	tmp = list[i-1:i+2]
	tmp.sort()
	
	if tmp[0] != list[i] and  tmp[1] == list[i]:
		ans = ans + 1
print(ans)

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

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

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

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

  if temp[1] == sorted(temp)[1]:
    counter+=1
    
print(counter)

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

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

print(ans)

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


def main():
	n = int(input())
	p = list(map(int,input().split()))
	count = 0
	for i in range(1, n-1):
		if check(p, i):
			count += 1
	print(count)

def check(p, i):
	if ((p[i -1] < p[i]) and (p[i] < p[i + 1])) or ((p[i -1] > p[i]) and (p[i] > p[i + 1])):
		return True
	else:
		return False

main()

Solution (Python):

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