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())
cnt=0
*s,=map(int,input().split())
for i in range(n-2):
	if (s[i]<s[i+1]<=s[i+2])or(s[i+2]<s[i+1]<=s[i]):
		cnt += 1
	else:
		pass
print(cnt)

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

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

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

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

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

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

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

Solution (Python):
n = input()
p = list(map(int, input().split()))
result = 0
i = 1
for index, v in enumerate(p):
    if index != i:
        continue
    else:
        if len(p) >= index+2:
            a = p[index-1]
            b = p[index]
            c = p[index+1]
            if (a > b and b > c) or (b > a and c > b):
                result += 1
    i += 1
print(result)

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

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

print(count)

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

cnt = 0

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

print(cnt)

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

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

print(c)

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

Solution (Python):
import itertools

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

ans = 0
l = p
for i in range(len(l)-2):
  tmp = sorted([l[i], l[i+1], l[i+2]])
  if tmp[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]-p[i-1])*(p[i+1]-p[i])>0:
    ans+=1
print(ans)

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

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

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

print(count)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
l = [p[i] 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]]
print(len(l))

Solution (Python):

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

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

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

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

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

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

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

cnt = 0
for i in range(1,N-1):
    if (list[i-1] < list[i] and list[i] < list[i+1]) or (list[i-1] > list[i] and list[i] > list[i+1]):
        cnt += 1
        
print(cnt)

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

for i in range(1,n-1):
    low=min(p[i-1],p[i],p[i+1])
    heigh=max(p[i-1],p[i],p[i+1])
    if low<p[i]<heigh:
        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 = list(map(int, input().split()))
count = 0
for i in range(1, n-1):
    if (p[i] > p[i-1] and p[i] < p[i+1]) or (p[i] < p[i-1] and p[i] > p[i+1]):
        count += 1
print(count)

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

count = 0

for i in range(0, len(lst)-2):
    target = lst[i:i+3]
    minVal = min(target)
    maxVal = max(target)
    val = lst[i+1]
    if val != minVal and val != maxVal:
        count += 1

print(count)

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

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

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

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(n: int, p: "List[int]"):
    ans = 0
    for i in range(1, n-1):
        if sorted([p[i-1], p[i], p[i+1]])[1] == p[i]:
            ans += 1

    print(ans)
    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())
def LI():
  return [int(s) for s in input().split()]

p = LI()

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

print(count)

Solution (Python):
n = int(input())
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=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])):
        count=count+1
    elif((p[i+2]<p[i+1])and(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(1, n-1):
    min_p = min(p[i-1], p[i+1])
    max_p = max(p[i-1], p[i+1])
    if min_p < p[i] < max_p:
        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
    else:
        pass

print(count)

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

ans = 0

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

print(ans)

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

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

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

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

print(count)

Solution (Python):
def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    count = 0

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

    print(count)

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

result = 0

for i in range(1,n-1):
    buf=[p[i-1],p[i],p[i+1]]
    if sorted(buf).index(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]:
        cnt += 1
    elif p[i-1] > p[i] >= p[i+1]:
        cnt +=1
print(cnt)

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

Solution (Python):
n, *ps = map(int, open(0).read().split())
cou =0
for x, y, z in zip(ps[:-2], ps[1:-1], ps[2:]):
  if (x-y)*(z-y)<0:
    cou += 1
print(cou)

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

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

print(count)

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

    ans = 0

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


if __name__=="__main__":
    main()

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

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

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

Solution (Python):
n=int(input())
p=list(map(int, input().split()))
A=int(0)
for i in range(1,n-1):
    q=[p[i-1],p[i],p[i+1]]
    r=sorted(q)
    if q[1]==r[1]:
        A+=1
    else:
        continue
print(A)

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

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

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

hantei = 0


for i in range(number-2):
  if (list_input[i]-list_input[i+1])*(list_input[i+2]-list_input[i+1])<0:
    hantei = hantei +1

print(hantei)

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

for i in range(1, n - 1):
    larger = max(p[i-1], p[i+1])
    smaller = min(p[i-1], p[i+1])
    if p[i] > smaller and p[i] < larger:
        ans += 1

print(ans)

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

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

print(ans)

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

print(counter)

Solution (Python):

n=int(input())
p=[int(i) for i in 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):
def main():
    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)

if __name__ == '__main__':
    main()

Solution (Python):
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys



read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = map(int, read().split())
print()
ans = 0
for i in range(N - 2):
    S = [P[i], P[i + 1], P[i + 2]]
    SS = sorted(S)
    if S[1] == SS[1]:
        ans += 1
print(ans)

Solution (Python):
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys



read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = map(int, read().split())
print(sum(x<y<z or x>y>z for x,y,z in zip(P,P[1:],P[2:])))

Solution (Python):
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys
import numpy as np
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = map(int, read().split())
print(sum(x<y<z or x>y>z for x,y,z in zip(P,P[1:],P[2:])))

Solution (Python):
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys
import numpy as np
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = map(int, read().split())
print()
ans = 0
for i in range(N - 2):
    S = [P[i], P[i + 1], P[i + 2]]
    SS = sorted(S)
    if S[1] == SS[1]:
        ans += 1
print(ans)

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

count = 0

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

print(count)

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

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

Solution (Python):
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        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)



if __name__ == '__main__':
    AtCoder().main()

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


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

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

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

def ju(a,b,c):
    return b==(a+b+c)-min(a,b,c)-max(a,b,c)
    

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

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

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


if __name__ == '__main__':
    main()

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

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

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

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

for i in range(n-2):
    l=[p[i],p[i+1],p[i+2]]
    l.sort()
    if l[1]==p[i+1]:
        cnt+=1
        l=[]
    else:
        l=[]
print(cnt)

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

for p1, p2, p3 in zip(p, p[1:], p[2:]):
    if (p1 < p2 and p2 < p3) or (p1 > p2 and p2 > p3):
        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())
ps = [int(i) for i in input().split()]

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

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

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]:
        ans += 1
    if a[i] > a[i + 1] > a[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 sorted([p[i-1],p[i],p[i+1]])[1]==p[i]:ans+=1
print(ans)

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

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

for i in range(1,n-1):
    if min(l[i-1],l[i+1]) <= l[i] and l[i] <= max(l[i-1],l[i+1]):
        pair += 1 

print(pair)

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

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

print(count)

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

pi = []
cnt = 0

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

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
tmp = []
count = 0
for i in range(n):
  tmp.append(p[i])
  if len(tmp)==3:
    if sorted(tmp)[1]==p[i-1]:
      count+=1
    tmp.pop(0)
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 += 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]>min(p[i-1],p[i+1]) and p[i]<max(p[i-1],p[i+1]):
        ans+=1
print(ans)

Solution (Python):



import numpy as np


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


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


print(res)

Solution (Python):
N, *P = map(int, open(0).read().split())
c = 0
for i in range(N-2):
    p1 = P[i]
    p2 = P[i+1]
    p3 = P[i+2]
    if p1 < p2 < p3 or p3 < p2 < p1:
        c += 1

print(c)

Solution (Python):
def main():
    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]>p[i]):
            ans += 1
        elif (p[i-1]>p[i]) & (p[i+1]<p[i]):
            ans += 1
    return ans

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

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

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

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

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

def main():
    n = int(input())
    *p, = 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)

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

print(ans)

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

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

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

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

print(cnt)

Solution (Python):
n = int(input())
p=list(map(int, input().split()))
count=0
for i in range(n-2):
    box = p[i:i+3]
    boxed = sorted(box)
    if box[1]==boxed[1]:
        count+=1
    else:
        pass
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())
ps = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
    if ps[i] < ps[i+1] and ps[i+1] <= ps[i+2]:
        cnt+=1
    elif ps[i+2] < ps[i+1] and ps[i+1] <= ps[i]:
        cnt+=1
    else:
        continue
print(cnt)

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

cnt=0
for i in range(1,n-1):
  a=P[i-1]
  b=P[i]
  c=P[i+1]
  if max([a,b,c])!=b and min([a,b,c])!=b:
    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]:
		count += 1
	elif A[i-1]<A[i] and A[i]<A[i+1]:
		count += 1
print(count)

Solution (Python):
N, *L,  = [list(map(int, s.split())) for s in open(0)]
A = L[0]

cnt = 0
for i in range(len(A) - 2):
    ma = max(A[i], A[i+1], A[i+2])
    mi = min(A[i], A[i+1], A[i+2])
    if A[i+1] not in [ma, mi]:
        cnt += 1
print(cnt)

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

ans = 0
data = []
for p in P:
   if len(data) == 2:
      data.append(p)
      if data[0] < data[1] and data[1] < data[2]:
          ans += 1
      elif data[2] < data[1] and data[1] < data[0]:
          ans += 1
      data.pop(0)
   else:
      data.append(p)

print(ans)

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

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

ans = 0
for i in range(1, len(p)-1): ans += sorted([p[i-1], p[i], p[i+1]])[1] == p[i]
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]>p[i+1]>p[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):
    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)

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

count=0

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

print(count)

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

new_numbers = []

cnt = 0
for i in range(1, len(numbers)-1):
    numberset = [numbers[i-1], numbers[i], numbers[i+1]]
    numberset.sort()
    if numberset.index(numbers[i]) == 1:
        cnt += 1
        
print(cnt)

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

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