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

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

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

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

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

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

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

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

Solution (Python):
n = int(input())
P = list(map(int, input().split()))
print(sum(p0 < p1 < p2 or p0 > p1 > p2 for p0, p1, p2 in zip(P, P[1:], P[2:])))

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

ans = 0
for i in range(N - 2):
    a = [L[i], L[i + 1], L[i + 2]]
    a = sorted(a)
    if a[1] == L[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
    else:
        continue

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
    else:
        continue
        
print(ans)

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

res = 0
for i in range(N-2):
	p = P[i:i+3]

	if p[1] == sorted(p)[1]:
		res+=1

print(res)

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

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

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

print(ans)

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

print(count)

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

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

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

ans = 0

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

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

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

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

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

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

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

ans = 0


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

print(ans)

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

ans = 0
for i in range(3, n+1):
    _p = p[i-3:i]
    s = sorted(_p)
    if s[1] == _p[1]:
        ans += 1

print(ans)

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

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

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

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

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

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

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

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

print(count)

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

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

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

print(count)

Solution (Python):


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

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

print(number)

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

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

count = 0
for i in range(len(ps) - 2):
    if (ps[i] < ps[i + 1] < ps[i + 2]) or (ps[i] > ps[i+1] > ps[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=[int(i) for i in input().split()]
ans=0
for i in range(n-2):
    a,b,c=p[i:i+3]
    if a<b<c or a>b>c:
        ans+=1
print(ans)

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

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

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
cnt=0
length=len(l)
for i in range(1,length-1):
  if (l[i]>l[i-1] and l[i]<l[i+1]):
    cnt+=1
  elif(l[i]<l[i-1] and l[i]>l[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 sorted(P[i-1:i+2])[1]==P[i]: 
        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())
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())

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 = 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(raw_input())
P = map(int, raw_input().split())

ans = 0
for i in xrange(1, N-1):
    if P[i] > P[i-1] and P[i] < P[i+1]:
        ans += 1
    elif P[i] < P[i-1] and 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(n-2):
  if a[i]<a[i+1]<a[i+2]:
    cnt+=1
  elif a[i]>a[i+1]>a[i+2]:
    cnt+=1
print(cnt)

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

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

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

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

MOD = 10 ** 9 + 7


def main():
    N = int(input())
    p = list(map(int, input().split()))
    ans = 0

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

    print(ans)


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):

import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 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]:
        count+=1
print(count)

Solution (Python):
n = int(input())
p = [num for num in 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
  if 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()))

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

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

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

print(m)

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

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

print(cnt)

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

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

print(buf)

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

li = list(map(int,input().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())
nums = list(map(int, input().split()))
count = 0
for i in range(1, n-1):
  if max(nums[i-1], nums[i], nums[i+1]) != nums[i] and \
     min(nums[i-1], nums[i], nums[i+1]) != nums[i]:
  	count += 1

print(count)

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

print(ans)

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

count_pn = 0
for i in range(1,N-1):
    if ( Pn[i-1] < Pn[i] < Pn[i+1] ) or ( Pn[i+1] < Pn[i] < Pn[i-1] ):
        count_pn += 1
print(count_pn)

Solution (Python):

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

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

print(the_number)

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):
N = int(input())
P = list(map(int,input().split(" ")))
count = 0
for i in range(1,len(P)-1):
    lst = [P[i-1],P[i],P[i+1]]
    lst.sort()
    if lst[1] == P[i]:
        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):
  if P[i]!=min(P[i-1],P[i],P[i+1]) and P[i]!=max(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):
	ans += (p[i] < p[i + 1] < p[i + 2] or p[i + 2] < p[i + 1] < p[i])
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
def print_ans(n,pr):
    """Test Case
    >>> print_ans(5, [1, 3, 5, 4, 2])
    2
    >>> print_ans(9, [9, 6, 3, 2, 5, 8, 7, 4, 1])
    5
    """
    ans = 0
    for i in range(1, n-1):
        tmp_arr = sorted([pr[i-1],pr[i],pr[i+1]])
        if  tmp_arr[1] == pr[i]:
            ans +=1
    print(ans)

if __name__ == '__main__':
    n = int(input().rstrip())
    pr = list(map(int, input().rstrip().split()))
    print_ans(n,pr)

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

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

print(cnt)

Solution (Python):
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
ans = 0
n = inp()
p = inpl()

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

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

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

print(ans)

Solution (Python):

import sys










def main():
    n, *p = [int(x) for x in sys.stdin.read().split()]

    compare = []
    for i in range(n-1):
        if p[i] < p[i+1]:
            compare.append('<')
        else:
            compare.append('>')

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

    print(count)

if __name__ == "__main__":
    main()

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

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

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

print(count)

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

def is_mid(v):
  return int(min(v)<v[1] and v[1]<max(v))
res=0
for i in range(1,N-1):
  res+=is_mid(P[(i-1):(i+2)])
print(res)

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

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

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

meet_condition = 0

for i in range(n-2):
    X =[]
    for j in range(3):
        X.append(p[i+j])
    if p[i+1] != max(X) and  p[i+1] != min(X):
        meet_condition += 1
        
print(meet_condition)

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())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  maxi = max(p[i-1],p[i],p[i+1])
  mini = min(p[i-1],p[i],p[i+1])
  if p[i] != maxi and p[i] != mini:
    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().strip())
p = list(map(int, input().split()))
ans = 0

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

print(ans)

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

Solution (Python):

import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    l = [int(x) for x in input().split()]

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

    print(cnt)
    

if __name__ == '__main__':
    main()

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

Solution (Python):
def c(x,s):
    return [x[i:i+s]for i in range(len(x)-s+1)]
input()
print([sorted(i)[1]==i[1]for i in c(list(map(int,input().split())),3)].count(True))

Solution (Python):
def c(x,s):
    return [x[i:i+s]for i in range(len(x)-s+1)]
input()
print([sorted(i)[1]==i[1]for i in c(list(map(int,input().split())),3)].count(True))

Solution (Python):




def each_cons(x, size):
    return [x[i:i+size] for i in range(len(x)-size+1)]
input();a=0
print([sorted(i)[1]==i[1]for i in each_cons(list(map(int,input().split())),3)].count(True))

Solution (Python):
def solve():
    n, *p_l = map(int, open(0).read().split())
    ans = 0
    
    for i in range(1, n-1):
        if p_l[i-1] < p_l[i] < p_l[i+1] or p_l[i+1] < p_l[i] < p_l[i-1]:
            ans += 1
    print(ans)


if __name__ == '__main__':
    solve()

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

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

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

cnt = 0

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

Solution (Python):
n = int(input())
p = list(map(int,(input().split())))
l= [[0]*3 for i in range(n-2)]
count = 0
j = 0

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

for i in range(1,n-1):
    if p[i]==l[j][1]:
        count += 1
    j += 1
print(count)

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

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

print(cnt)

Solution (Python):
import numpy as np
N = int(input())
P = np.array([int(x) for x in input().split()])
count = 0
for n in range(N-2):
    if P[n] < P[n+1] and P[n+1] < P[n+2]:
        count += 1
    if P[n+2] < P[n+1] and P[n+1] < P[n]:
        count += 1
print(count)

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

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

ans = 0

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    ans=0
    for i in range(1,n-1):
        ans+=(A[i-1]<A[i]<A[i+1]) or (A[i-1]>A[i]>A[i+1])
    print(ans)
resolve()

Solution (Python):



n = int(input())

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

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

Solution (Python):
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([1, 3, 5, 4, 2]), 2)

    def test_2(self):
        self.assertEqual(think([9, 6, 3, 2, 5, 8, 7, 4, 1]), 5)


def solve():
    p = read()
    result = think(p)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(data):
    n = len(data)
    count = 0
    for i in range(n):
        if i + 2 >= n:
            break
        if data[i] < data[i + 1] < data[i + 2] or data[i] > data[i + 1] > data[i + 2]:
            count += 1
    return count


def write(result):
    print(result)


if __name__ == '__main__':
    
    solve()

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

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

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

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

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

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

ans = 0
for i in range(1, n-1):
  if li[i-1] > li[i] and li[i+1] < li[i]:
    ans += 1
  if li[i-1] < li[i] and li[i+1] > li[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):
    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()))

ans = 0

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

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

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

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

print(cnt)

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

for i in range(n-2):
    a, b, c = ls[i], ls[i+1], ls[i+2]
    if c > b > a or a > b > c:
        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] 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=input()
l=list(map(int,input().strip().split()))
ans=0
for i in range(1,len(l)-1):
  gc=0;
  lc=0;
  if(l[i] >l[i-1] or l[i]>l[i+1]):
    gc=1
  if(l[i] <l[i-1] or l[i]<l[i+1]):
    lc=1
  ans+=(gc & lc)
  
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())
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, p):
    res = 0

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

    print(res)


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

    main(n, p)

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

Solution (Python):
N=int(input())
s=list(map(int,input().split(" ")))
co=0
i=0
while i<=N-3:
    if s[i]<s[i+1]<s[i+2] or s[i]>s[i+1]>s[i+2]:
        co+=1
    i+=1
print(co)

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

count = 0

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

print(count)

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

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

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

for i in range(1, n-1):
    As = [Ps[i-1], Ps[i], Ps[i+1]]    
    if Ps[i] == sum(As) - max(As) - min(As):
        ans += 1


print(ans)