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):
input()
ls = list(map(int, input().split()))
p = 0
for i in range(1, len(ls)-1):
	a = sorted(ls[i-1: i+2])
	p += a[1] == ls[i]
print(p)

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

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

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

Solution (Python):
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    c = 0
    for i in range(1, n - 1):
        if sorted(a[i - 1:i + 2])[1] == a[i]:
            c += 1
    return c


if __name__ == "__main__":
    print(solve())

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

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

num = 0
for i in range(n-2):
    list_i = P[i:i+3]
    if list_i[1] == sorted(list_i)[-2]:
        num += 1
    else:
        num += 0

print(num)

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


if __name__ == "__main__":
    main()

Solution (Python):
def main():
  n = int(input())
  ps = list(map(int, input().split(' ')))
  ans = 0
  for i in range(0, n-2):
    t = ps[i+1]
    s = sorted(ps[i:i+3])
    ans += 1 if t == s[1] else 0
  print(ans)


if __name__ == '__main__':
  main()

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

Solution (Python):

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

c=0
for i in range(n-2):
    tmp=p_list[i:i+3]
    if tmp[1]==sorted(tmp)[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,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]):
    count = count + 1
  
print(count)

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

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

print(cnt)

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

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

ans = 0
for i in range(1, n - 1):
    v = P[i]
    row = sorted(P[i-1:i+2])
    if row[1] == v:
        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]) * (p[i] - p[i-1]) > 0:
    cnt += 1

print (cnt)

Solution (Python):
from statistics import median

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

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

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

Solution (Python):


import os
import sys

n = int(input())

p = list(map(lambda x: int(x), 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

	if 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] and p[i] < p[i+1]:
  	c += 1
  elif p[i+1] < p[i] and p[i] < p[i-1]:
    c += 1
  else:
    pass

print(c)

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

Solution (Python):

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

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

print(count)

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

Solution (Python):

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

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

print(count)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n):
    if (i - 1) >= 0 and (i + 1) < n:
        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())
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 = [int(i) for i in input().split()]
c = 0
for i in range(1, n-1):
    if p[i-1] < p[i] < p[i+1] or p[i] < p[i-1] == 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()))
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())
num = list(map(int,input().split()))
c = 0
for i in range(N-2):
    a = [num[i],num[i+1],num[i+2]]
    b =num[i+1]
    a.sort()
    if a[1] == b:
        c += 1
print(c)

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]:
        cnt += 1
    elif 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(n - 2):
    if sorted([p[i], p[i + 1], p[i + 2]])[1] == p[i + 1]:
        cnt += 1
print(cnt)

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

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

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

print(ans)

Solution (Python):
n = int(input())
P = list(map(int, input().split()))
count = 0
for i in range(n-2):

    P_temp = [P[i], P[i+1], P[i+2]]
    P_temp.sort()
    if P_temp[1] == P[i+1]:
        count = count + 1

print(count)

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

count = 0
for i, pi in enumerate(p):
    if i == 0 or i == n-1:
        pass
    else:
        if pi != max(p[i-1:i+2]) and pi != min(p[i-1:i+2]):
            count += 1
print(count)

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

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

print(ans)

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

cnt=0
for i in range(1,len(p)-1):
    small = 1
    if p[i]>p[i-1]:
        small+=1
    if p[i]>p[i+1]:
        small+=1
    if small==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 min(p[i-1:i+2]) < p[i] < max(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(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):


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

if __name__ == '__main__':
    n = int(input())
    p = list(map(int, input().split()))
    print(main(n, p))

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())
P = list(map(int, input().split()))
count = 0
for i in range(1,N-1):
    a = P[i-1]
    b = P[i]
    c = P[i+1]
    if a<b<c or a>b>c:
        count += 1
print(count)

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

Solution (Python):
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
n = int(ss[0])
p = list(map(lambda x: int(x), ss[1].split()))
result = []
for i in range(1, n-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
        result.append(1)
print(len(result))

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

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

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

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
b=l[0]
c=l[1]
ans=0
for i in range(2,n):
  a=b
  b=c
  c=l[i]
  ab=b>a
  bc=c>b
  if (ab==True and bc==True) or (ab==False and bc==False):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] < p[i+1] or p[i+1] < p[i] < p[i-1]:
        count += 1
print(count)

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

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

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

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

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

counter=0
for i in range(1, N-1):
  if (p[i]-p[i-1])*(p[i]-p[i+1])<0:
    counter+=1
    
print(counter)

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

def count(ps):
    if len(ps) <= 2:
        return 0
    qs = sorted(ps[0:3])
    res = 1 if qs[1] == ps[1] else 0
    return res + count(ps[1:])

print(count(ps))

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

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

print(count)

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

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

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

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

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

print(temp)

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

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

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

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

ans = 0
for i in range(n):
    if i - 1 >= 0 and i + 1 < n:
        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())
lst = list(map(int,input().split()))
ans = 0
for i in range(N-2):
  hako = []
  hako.extend([lst[i],lst[i+1],lst[i+2]])
  hako.sort()
  if hako[1] == lst[i+1]:
      ans += 1
print(ans)

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

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

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

Solution (Python):
kosuu = int(input())
hairetu = list(map(int, input().split()))
count = 0
step = kosuu - 2
for a in range(step):
    if hairetu[a] < hairetu[a + 1] < hairetu[a + 2]:
        count += 1
    if hairetu[a + 2] < hairetu[a+1] < hairetu[a]:
        count += 1
print(count)

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

Solution (Python):
def q35(n, p):
    count = 0
    for i in range(n-2):
        a = p[i:i+3]
        if min(a) != p[i+1] and max(a) != p[i+1]:
            count += 1
    return count

N = int(input())
p = [int(i) for i in input().split()]
print(q35(N, p))

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

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):
def bSort(a):
    for i in range(len(a)):
        for j in range(len(a)-1, i, -1):
            if a[j] > a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]

    return a



n = int(input())

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

d = [0]*3
c = [0]*3
count = 0

for i in range(n-2):
    for j in range(3):
        d[j] = p[i+j]
        c = d[:]
    d = bSort(d)
    
    if c[1] == d[1]:
        count += 1
print(count)

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

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

print(count)

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

Solution (Python):
import  numpy   as      np

I_N             =       int(input())
S               =       input().split()
I_S             =       np.array(S).astype(type(I_N))
I_Counter       =       0

for i in range(1,I_N-1):

        if(I_S[i-1] < I_S[i] and I_S[i] < I_S[i+1]):
                I_Counter       +=      1
        elif(I_S[i-1] > I_S[i] and I_S[i] > I_S[i+1]):
                I_Counter       +=      1

print(I_Counter)

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

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

main()

Solution (Python):

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
    b = [a[i - 1], a[i], a[i + 1]]
    b.sort()
    if a[i] == b[1]: 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])or\
        (p[i-1]>=p[i] and p[i]>=p[i+1]):
        cnt += 1
    else:
        pass
    
print(cnt)

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

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

def main():
	n = int(input().strip())
	v = list(map(int, input().strip().split()))
	ans = 0
	for i in range(n-2):
		l = v[i:i+3]
		
		t = l[1]
		if t == sorted(l)[1]:
			ans += 1
	print(ans)

if __name__ == '__main__':
	main()

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

cnt=0
for i in range(1,N-1):
  temp_list = num_list[i-1:i+2]
  sort_list = sorted(temp_list)
  if temp_list[1] == sort_list[1]:
    cnt+=1
print(cnt)

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




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

print(ans)

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

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()))
count=0
for i in range(n-2):
  if p[i+1]==sorted(p[i:i+3])[1]:
    count+=1
print(count)

Solution (Python):





from sys import stdin









temp = stdin.readline().split()
N = int(temp[0])

data = []
write = stdin.readline().split()
for i in range(N):
    data.append(int(write[i]))

count = 0
for i in range(N-2):
    array = sorted(data[i:i+3])
    if data[i+1]==array[1]:
        count += 1
        
print(count)

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

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


i=1
l=[]
while i<n-1:
  if p[i-1]<p[i]<p[i+1] or p[i-1]>p[i]>p[i+1]:
    l.append(i)
  else:
    pass
  i+=1
print(len(l))

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

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

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

ans = 0

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

Solution (Python):
n = int(input())
seq_str = input().split(" ")
seq = [int(s) for s in seq_str]
counter = 0

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

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
  if 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(1, n-1):
  s = sorted(p[i-1:i+2], reverse=True)
  if s[0] != p[i] and s[1] == p[i]:
    ans += 1
print(ans)

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

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

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

print(count)

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

print(an)

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

Solution (Python):
n = int(input())
A = [int(a) for a in input().split()]
ans=0
for i in range (1,n-1):
  mid =A[i]
  top =A[i-1]
  bot =A[i+1]
  B =[top,mid,bot]
  ma =(max(B))
  mi =(min(B))
  if mi != mid and ma != mid:
    ans +=1
print(ans)

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

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

Solution (Python):
def main():
    n = int(input())
    l = list(map(int,input().split(' ')))
    ans = 0
    for i in range(n-2):
        if l[i]<l[i+1]<l[i+2] or l[i+2]<l[i+1]<l[i]:
            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(1,n-1):
    if max(p[i-1:i+2]) != p[i] and min(p[i-1:i+2]) != p[i]:
        count += 1
print(count)

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

a=0
for i in range(X-2):
	if sorted(N[i:i+3])[1] == N[i:i+3][1]:
		a += 1
print(a)

Solution (Python):

cnt = 0

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

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

print(cnt)

Solution (Python):
n = int(input())
p = [int(line) for line in 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())
P = list(map(int,input().split(' ')))
num = 0
for i in range(1,N-1):
  if min(P[i-1],P[i+1]) < P[i]  and P[i] <max(P[i-1],P[i+1]):
    num += 1
print(num)

Solution (Python):
N = int(input())
Pn=list(map(int,input().split()[:N]))

def judge(x,y,z):
    if x < y < z or z< y< x:
        return 1
    else:
        return 0

ret=0
for i in range(1,N-1):
    ret+=judge(Pn[i-1],Pn[i],Pn[i+1])
print(ret)

Solution (Python):
N = int(input())
P = list(map(int,input().split(' ')))
num = 0
for i in range(1,N-1):
  if min(P[i-1],P[i+1]) < P[i]  and P[i] <max(P[i-1],P[i+1]):
    num += 1
print(num)

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

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

c = 0

for i in range(1, n-1):
    t = [arr[i-1], arr[i], arr[i+1]]
    t.sort()
    if arr[i] == t[1]:
        c+=1

print(c)

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

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

print(ans)

Solution (Python):
import copy
import numpy as np

S = input()

N = int(S)

S = input()

P = list(map(int, S.split()))

check = []

count = 0

for i in range(0, N-2, 1):

    check = P[i:i+3]
    check = np.array(check)
    check = check.argsort()
    if check[1] == 1:
        count = 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] or p[i-1] > p[i] > p[i+1]:
    ans += 1
    
print(ans)

Solution (Python):
def OrdinaryNumber(n,p,flag=None):
    
    
    if n < 3:
        return 0
    
    
    if flag == "LessThan":
        if p[1] < p[2]:
            count = OrdinaryNumber(n-1, p[1:], "LessThan")+1
        else:
            count = OrdinaryNumber(n-1, p[1:], "GreaterThan")
            
    
    elif flag == "GreaterThan":
        if p[1] < p[2]:
            count = OrdinaryNumber(n-1, p[1:], "LessThan")
        else:
            count = OrdinaryNumber(n-1, p[1:], "GreaterThan")+1
    
    
    else:
        if p[1] < p[2]:
            count = OrdinaryNumber(n-1, p[1:], "LessThan")
            if p[0] < p[1]:
                count +=1
        else:
            count = OrdinaryNumber(n-1, p[1:], "GreaterThan")
            if p[0] > p[1]:
                count +=1
                
    return count

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

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

cnt = 0
for i in range(n - 2):
    permutation = [p[i], p[i + 1], p[i + 2]]
    permutation.pop(permutation.index(max(permutation)))
    if max(permutation) == 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):
    X = [P[i], P[i + 1], P[i + 2]]
    X.sort()
    if X[1] == P[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 sorted(p[i:i + 3])[1] == p[i:i + 3][1]:
    
        count = count + 1
        
print("{}".format(count))

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

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

 else:
    a=a

print(a)

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

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

print(count)

Solution (Python):

N = int(input())

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

c = 0

for i in range(1,N-1):
    
    M = max(P[i-1],P[i],P[i+1])
    m = min(P[i-1],P[i],P[i+1])
    if P[i] != M and P[i] != m: 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-1] < P[i] < P[i+1] or P[i+1] < P[i] < P[i-1]:
        ans += 1

print(ans)

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

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

print(count)

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

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

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

Solution (Python):
num = int(input())
kazu = list(map(int, input().split()))
answer = 0
for n in range(1, num - 1):
  a, b, c = kazu[n - 1], kazu[n], kazu[n + 1]
  if (a < b and b < c) or (a > b and b > c):
    answer += 1
print(answer)

Solution (Python):
n=int(input())
l=[];cnt=0;a1=0;a2=0;a3=0
l= list(map(int,input().strip().split()))[:n]
for i in range(n-2):
    mid=0
    a1=l[i]
    a2=l[i+1]
    a3=l[i+2]
    if a2 is not max(a1,a2,a3) and a2 is not min(a1,a2,a3):
        cnt+=1
print(cnt)

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

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

print(answer)

Solution (Python):
n = int(input())
P = list(map(int,input().split()))
count = 0
for i in range(1,n-1):
  if P[i] == sorted([P[i-1],P[i],P[i+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):
    p_num = p[i-1:i+2]
    p_num = sorted(p_num)
    if p[i] == p_num[1]:
        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 max(p[i-1:i+2]) != p[i] and min(p[i-1:i+2]) != p[i]:
        cnt += 1

print(cnt)

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

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

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

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

print(len([a for a,b,c in zip(nums, nums[1:], nums[2:]) if sorted([a,b,c])[1]==b]))