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

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

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

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

print(cnt)

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

print(output)

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

    if p[i] == temp[1]:
        count += 1

print(count)

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

Solution (Python):
n = int(input())
P = [int(x) for x in input().split()]
c = 0
for i in range(n - 2):
    if P[i] < P[i + 1] < P[i + 2] or P[i] > P[i + 1] > P[i + 2]:
        c += 1

print(c)

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

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

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

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

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

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

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

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

ans= 0

for i in range(1,n-1):
    lis= sorted([li[i],li[i-1],li[i+1]])
    if lis[1]==li[i]:
        ans +=1
print(ans)

Solution (Python):
import sys

indata = sys.stdin.read().strip().splitlines()[1]
numbers = list(map(int, indata.split(" ")))
ans = 0
for i in range(1, len(numbers)):
  p = i - 1
  n = i + 1
  if n >= len(numbers):
    break
  if numbers[p] < numbers[i] < numbers[n] or\
     numbers[n] < numbers[i] < numbers[p]:
    ans += 1
print(ans)

Solution (Python):
import numpy

def solve(string):
    n, *p = map(int, string.split())
    p = numpy.asarray(p)
    asc=(p[:-2] < p[1:-1]) & (p[1:-1] < p[2:])
    desc=(p[:-2] > p[1:-1]) & (p[1:-1] > p[2:])
    return str(sum(asc | desc))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
import numpy

def solve(string):
    n, *p = map(int, string.split())
    p = numpy.asarray(p)
    asc=(p[:-2] < p[1:-1]) & (p[1:-1] < p[2:])
    desc=(p[:-2] > p[1:-1]) & (p[1:-1] > p[2:])
    return str(sum(asc | desc))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
import numpy

def solve(string):
    n, *p = map(int, string.split())
    p = numpy.asarray(p)
    asc=(p[:-2]<p[1:-1]) & (p[1:-1]<p[2:])
    desc=(p[:-2]>p[1:-1]) & (p[1:-1]>p[2:])
    return str(sum(asc | desc))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

print(ans)

Solution (Python):
N = int(input().strip())
P = list(map(int, input().strip().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())
value = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
	if value[i] < value[i+1] < value[i+2] or value[i] > value[i+1] > value[i+2]:
		cnt += 1
print(cnt)

Solution (Python):
count = 0
n = int(input())
p = [int(i) for i in input().split()]
for i in range(1,n-1):
    lower = min(p[i-1],p[i+1])
    upper = max(p[i-1],p[i+1])
    if lower < p[i] and p[i] < upper:
        count += 1

print(count)

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

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

print(counter)

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

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

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

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

print(count)

Solution (Python):
readints=lambda:map(int,input().split(' '))
n=int(input())
a=list(readints())
ans=0
for i in range(1,n-1):
  arr=[a[i-1],a[i],a[i+1]]
  arr.sort()
  if a[i]==arr[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):
def solve(l:list):
    cnt = 0
    for i in range(1, len(l)-1):
        if l[i+1]>l[i]>l[i-1] or l[i+1]<l[i]<l[i-1]:
            cnt += 1
    return cnt

def main():
    input()
    l = list(map(int, input().split(" ")))
    print(solve(l))

if __name__ == "__main__":
    main()

Solution (Python):
def solve(l:list):
    cnt = 0
    for i in range(1, len(l)-1):
        if l[i+1]>l[i]>l[i-1] or l[i+1]<l[i]<l[i-1]:
            cnt += 1
    return cnt

def main():
    input()
    l = list(map(int, input().split(" ")))
    print(solve(l))

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

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

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

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


if __name__ == "__main__":
    test()

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

Solution (Python):

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

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

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

Solution (Python):
def getlist():
	return list(map(int, input().split()))

n = int(input())
p = getlist()

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

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):
def main():
    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 += 1
    return count

if __name__ == '__main__':
    print(main())

Solution (Python):

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

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

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

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

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

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

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

for a in range(n-2):
    if (p[a] < p[a+1] < p[a+2]) or (p[a+2] < p[a+1] < p[a]):
        cnt += 1
print(cnt)

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

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

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

Solution (Python):

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

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

print(count)

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

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

print (cnt)

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

cnt = 0
for n in range(0, N-2, 1):
  p1 = P[n]
  p2 = P[n+1]
  p3 = P[n+2]
  min_p = min(p1,p2,p3)
  max_p = max(p1,p2,p3)
  if (min_p != p2) and (max_p != p2):
    cnt += 1

print(cnt)

Solution (Python):
import sys
n = int(sys.stdin.readline())
plist = [int(a) for a in sys.stdin.readline().split()]
ans = 0
for i in range(1, n-1):
  tmp_plist = sorted(plist[i-1:i+2])
  if tmp_plist[1] == plist[i]:
    ans += 1
print(ans)

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

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

print(cnt)

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

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

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

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

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

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

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

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

print(count)

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

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

print(count)

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

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

array = map(int, raw_input().split())
num = 0

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

print num

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

ans = 0
for i in range(n - 2):
    q = [p[i + j] for j in range(3)]
    if min(q) < q[1] < max(q):
        ans += 1

print(ans)

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

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

Solution (Python):



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

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



n = I()
p = III()

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

print(count)

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

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

for i in range(1,n-1):
    if p_list[i-1] == p_list[i] < p_list[i+1] or p_list[i] == p_list[i+1] < p_list[i-1]:
        cout += 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):

import sys


def solve(n: int, p: "List[int]"):

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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    p = [ int(next(tokens)) for _ in range(n) ]  
    solve(n, p)

if __name__ == '__main__':
    main()

Solution (Python):
N=int( input() )
S=input().split(" ")

for i in range ( N ) :
    S[i] = int(S[i])

A = []
num = 0
for i in range ( N - 2 ) :
    A.append ( ( S[i+2]-S[i+1] ) * ( S[i+1]-S[i] ) )
    if A[i] > 0:
        num = num + 1

print ( num )

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

	cnt = 0
	for i in range(N - 2):
		if P[i] < P[i+1] < P[i+2] or P[i] > P[i+1] > P[i+2] :
			cnt += 1
		else:
			pass
	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] <= p[i+1] and p[i-1] <= p[i]:
        ans += 1
    elif p[i+1] <= p[i] and p[i] <= p[i-1]:
        ans += 1

print(ans)

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

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

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

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

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

Solution (Python):
import math





inputa = input().split()
inputb = input().split()

a = int(inputa[0])






listb = []
listb = [int(n) for n in inputb]

cnt = 0
for i in range(1,a-1):
    if listb[i-1] < listb[i] and listb[i] < listb[i+1]:
        cnt += 1
    elif listb[i-1] > listb[i] and listb[i] > listb[i+1]:
        cnt+=1

print(cnt)

Solution (Python):
n,*p=map(int,open(0).read().split())
cnt=0
for i in range(1,n-1):
  if sorted([p[i-1], p[i], p[i+1]])[1] == p[i]:
    cnt+=1
print(cnt)

Solution (Python):
n,*p=map(int,open(0).read().split())
cnt=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]):
    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 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):
n=int(input())
p = list(map(int, input().split()))
count=0
for i in range (n-2):
  if p[i]>p[i+1]>p[i+2] or p[i+2]>p[i+1]>p[i]:
        count = 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 + 2] < p[i + 1] < p[i]:
		ans += 1
print(ans)

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

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

print(c)

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

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

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

ans=0
for i in range(n-2):
  a=l[i]
  b=l[i+1]
  c=l[i+2]
  if (a<b<c) or (c<b<a):
    ans+=1

print(ans)

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

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

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

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

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

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

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

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

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

sum=0
for i in range(1,N-1):
    if(min(H[i-1],H[i],H[i+1])!=H[i]):
        if(max(H[i-1],H[i],H[i+1])!=H[i]):
            sum+=1
print(sum)

Solution (Python):
N = int(input())
Plist = list(map(int,input().split()))
count = 0
for i in range(N-2):
    a1 = Plist[i]
    a2 = Plist[i+1]
    a3 = Plist[i+2]
    b1 =  (a1 < a2 and a2 < a3) 
    b2 =  (a3 < a2 and a2 < a1) 
    if b1 or b2:
        count += 1
print( count )

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

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

Solution (Python):

n = int(input())
I = input()
P = []

for i in range(n):
    P.append(int(I.split()[i]))
    

count = 0

for w in range(n-2):
    A = P[w]-P[w+1]
    B = P[w+1]-P[w+2]
    
    if A*B>0:
        count+=1
    
print(count)

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

    print(score)


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]-p[i-1])>0):
    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-1]< A[i]< A[i+1] or A[i+1] < A[i] < A[i-1]:
        count = count + 1
    else:
        pass

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

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

Solution (Python):

import sys


def solve(n: int, p: "List[int]"):
    count = 0
    for i in range(1, n-1):
        if p[i-1] <= p[i] and p[i] <= p[i+1]:
            count += 1
        elif p[i+1] <=p[i] and p[i] <= p[i-1]:
            count += 1
    print(count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    p = [ int(next(tokens)) for _ in range(n) ]  
    solve(n, p)

if __name__ == '__main__':
    main()

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

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

cnt = 0

for i in range(1, n-1):
    if(arr[i-1] < arr[i] and arr[i] < arr[i+1]):
        cnt += 1
    elif(arr[i-1] > arr[i] and arr[i] > arr[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] :
        ans += 1
    elif p[i] > p[i+1] > p[i+2] :
        ans += 1
    else:
        continue
else:
    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())
p=input().split()
count=0
for i in range(0,n-2):
    if int(p[i])<int(p[i+1]):
        if int(p[i+1])<int(p[i+2]):
            count+=1
    elif int(p[i])>int(p[i+1]):
        if int(p[i+1])>int(p[i+2]):
            count+=1
print(count)

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

Solution (Python):
n = int(input())
p = 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()))
cnt = 0
for i in range(2, n):
    p_n = p[i-2:i+1]
    p_n_sort = sorted(p_n)
    if p_n_sort[1] == p_n[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]<p[i+1] and p[i-1]<p[i]) or (p[i]>p[i+1] and p[i-1]>p[i]):
        ans=ans+1
print(ans)

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

print(count)

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

cnt=0

for i in range(1, n-1):
    p_list = [p[i-1], p[i], p[i+1]]
    if not min(p_list) ==  p_list[1] and not max(p_list) == p_list[1]:
        cnt+=1

print (cnt)

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

count = 0
for i in range(1, N-1):
    m = sorted(Ps[(i-1):(i+2)])[1]
    if m == Ps[i]:
        count += 1
print(count)

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

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

Solution (Python):
n=int(input())
p=[int(x) for x in input().split()]
count=0
b=2
while b<n:
    x=min(p[b],p[b-1],p[b-2])
    y=max(p[b],p[b-1],p[b-2])
    if p[b-1]!=x and p[b-1]!=y:
        count+=1
    b+=1
print(count)

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