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

print(cnt)

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

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

print(answer)

Solution (Python):
n = int(input())
data = list(map(int,input().split()))
point = 0
i = 1
while i <= len(data) - 2:
    if data[i-1] < data[i] and data[i] < data[i+1]:
        point += 1
    if data[i - 1] > data[i] and data[i] > data[i + 1]:
        point += 1
    i += 1

print(point)

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())
S = map(int,input().split())
Number = list(S)
count_number = 0

for i in range(n-2):
    if Number[0] > Number[1] > Number[2] or Number[2] > Number[1] > Number[0]:
        count_number += 1
    del Number[0]

print(count_number)

Solution (Python):

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

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

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

Solution (Python):
input()
P = list(map(int, input().split()))
print(sum(A < B < C or C < B < A for A, B, C in zip(P, P[1:], P[2:])))

Solution (Python):


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

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(s) for s in input().split()]
count = 0
for i in range(len(p)-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(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()))
ans = 0
for i in range(1,n-1):
  pl = [p[i-1],p[i],p[i+1]]
  if p[i] != max(pl) and p[i] != min(pl):
    ans += 1
print(ans)

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

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

Solution (Python):
n = int(input())
l_n = list(map(int, input().split()))
ans_count = 0

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

print(ans_count)

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

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

print(cnt)

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

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_list.append(i)
print(len(ans_list))

Solution (Python):
"""
問題文 { 1 , 2 , . . . , n } の順列 p = { p 1 , p 2 , . . . , p n } があります。
以下の条件を満たすような p i ( 1 < i < n ) がいくつあるかを出力してください。
p i − 1 , p i , p i + 1 の 3 つの数の中で、 p i が 2 番目に小さい。
制約 入力は全て整数である。
3 ≤ n ≤ 20 p は { 1 , 2 , . . . , n } の順列である。
入力 入力は以下の形式で標準入力から与えられる。
n
p 1 p 2 . . . p n
"""

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

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

for i in range(n-2):
    if p[i] < p[i+1] < p[i+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()))
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()))
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,len(P)-1):
    p_ = [P[i-1], P[i], P[i+1]]
    if (P[i] != min(p_)) and (P[i] != max(p_)):
        count+= 1

print(count)

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

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

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

cnt=0
for i in range(1,n-1):
    if (p[i-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()))

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

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

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

print(ans)

Solution (Python):
from typing import Tuple


def answer(n: int, p: Tuple[int]) -> int:
    count = 0
    for i in range(1, n - 1):
        max_ = max(p[i - 1], p[i + 1])
        min_ = min(p[i - 1], p[i + 1])
        if min_ < p[i] < max_:
            count += 1

    return count


def main():
    n = int(input())
    p = tuple(map(int, input().split()))
    print(answer(n, p))


if __name__ == '__main__':
    main()

Solution (Python):

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

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

print(ans)

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

cnt = 0
for i in range(N - 2):
    if max(n[0 + i], n[1 + i], n[2 + i]) \
            > n[1 + i] \
            > min(n[0 + i], n[1 + i], n[2 + i]):
        cnt += 1

print(cnt)

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

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

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

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

Solution (Python):
import sys


def main():
    input = sys.stdin.buffer.readline
    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__":
    main()

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

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

print(ans)

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

ans = 0
for i in range(n):
    if(i == 0):
        pass
    elif (i == n - 1):
        pass
    else:
        a = p[i - 1]
        b = p[i]
        c = p[i + 1]
        lst = [a, b ,c]
        lst.sort()
        if (lst[1] == b):
            ans = ans + 1
print(ans)

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

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

def ans132(n:int, P:str):
    P=list(map(int,P.split()))
    jugde_count=0
    for i in range(1,n-1):
        n_list=sorted([P[i-1],P[i],P[i+1]])
        if n_list[1]==P[i]:
            jugde_count+=1
    return jugde_count

print(ans132(n,P))

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

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

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

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

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

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

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

print(cnt)

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())
L = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
  s = L[i:i+3][1]
  A = sorted(L[i:i+3])
  t = A[1]
  if s == t:
    cnt += 1
print(cnt)

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

pn = list(map(int,input().split()))
count = 0
for x in range(1,n-1):
  if pn[x+1] > pn[x] > pn[x-1] or pn[x-1] > pn[x] > pn[x+1]:
    count += 1
print(count)

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

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

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

print(ans)

Solution (Python):
n = int(input())
p = 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):
  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: ans += 1

print(ans)

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

Solution (Python):
n = int(input())
list_p = [int(i) for i in input().split()]
count = 0
for i in range(1, n - 1):
    if min(list_p[i - 1], list_p[i], list_p[i + 1]) !=list_p[i] and \
            max(list_p[i - 1], list_p[i], list_p[i + 1]) != list_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(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] 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()))
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 sorted([p[i - 1], p[i], p[i + 1]])[1] == p[i]:
        ans += 1
print(ans)

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

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

cnt = 0
for i in range(1,n-1):
    second = p[i]
    scope = sorted([ p[i-1], p[i], p[i+1] ])
    if scope[0] < second and second < scope[2]:
        cnt += 1

print(cnt)

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

Solution (Python):
n = int(input());
arr = list(map(int, input().split()));
count = 0;
for i, num in enumerate(arr):
  if(i == 0 or i == (n - 1)): 
    continue;
  
  target_arr = [arr[i-1], arr[i], arr[i+1]]
  if(sorted(target_arr)[1] == arr[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 sorted([P[i-1],P[i],P[i+1]]).index(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] != min(p[i-1], p[i], p[i+1]) 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(2, n):
  if P[i-2] < P[i-1] < P[i] or P[i-2] > P[i-1] > P[i]:
  	ans += 1
print(ans)

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

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

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
i = 0
ans = 0
while i < len(p) - 3 + 1:
    m = p[i:i+3]
    l = sorted(m)
    if l[1] == m[1]:
        ans += 1
    i += 1
print(ans)

Solution (Python):
import statistics

n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n-2):

    l2=[l[i],l[i+1],l[i+2]]
    if statistics.median(l2)==l[i+1]:
        ans+=1

print(ans)

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

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

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

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

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

count=0
for i in range(1, n-1):
    a=p[i-1]
    b=p[i]
    c=p[i+1]
    p_list=[a,b,c]
    
    p_list.sort()
    
    if p[i]==p_list[1]:
        count+=1
        
        
print(count)

Solution (Python):



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

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

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


print(ct)

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

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

print(cnt)

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

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

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

print(ans)

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

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

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

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,*p=map(int,open(0).read().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()))
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):
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n = int(input())
    a = Input()
    count = 0
    for i in range(1, n-1):
        if a[i] == sorted((a[i-1], a[i], a[i+1]))[1]:
            count += 1

    print(count)

main()

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

def main():
    lines = input()
    n = int(lines[0].strip())
    a = list(map(int, lines[1].split()))

    cnt = 0

    for i in range(2, n):
        b = a[i-2:i+1]
        b = sorted(b)
        if a[i-1] == b[1]:
            cnt += 1

    print(cnt)

main()

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

Solution (Python):
n = int(input())
p = [int(s) for s 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(n - 2):
        if p[i] < p[i + 1] < p[i + 2] or p[i] > p[i + 1] > p[i + 2]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

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

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

ans=0

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

print(ans)

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

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

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

Solution (Python):
def f(a,b,c):
    mx = max(a,b,c)
    mn = min(a,b,c)
    if mx == b or mn == b:
        return False
    else:
        return True

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

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

tmp_list = []
cnt = 0
for i in range(0, n-2, 1):
    tmp = num_list[i:i+3]
    if tmp[0] < tmp[1] and tmp[1] < tmp[2]:
        cnt += 1
    elif tmp[2] < tmp[1] and tmp[1] < tmp[0]:
        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] > p[i+1] > p[i+2]:
        ans += 1
print(ans)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
def check(a, b, c):
  l = [a, b, c]
  l.sort()
  if l[1] == b:
    return True
  else:
    return False
cnt = 0
for i in range(n-2):
  if check(p[i], p[i+1], p[i+2]):
    cnt += 1
print(cnt)

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

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


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

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

print(ans)

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

print(ans)

Solution (Python):
n = int(input())
*P, = 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(n-2):
    ans += P[i] < P[i+1] < P[i+2] or P[i+2] < P[i+1] < P[i]

print(ans)

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

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

Solution (Python):
import sys

N = int(sys.stdin.readline())
P = list(map(int, sys.stdin.readline().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:i+3]
    x = a[1]
    a.sort()
    if a[1] == x:
        ans += 1
print(ans)

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

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

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

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

ans = 0

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ps = list(mapint())
ans = 0

for i in range(1, N-1):
    if Ps[i-1]<=Ps[i]<Ps[i+1] or Ps[i+1]<=Ps[i]<Ps[i-1]:
        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())
s=list(map(int,input().split()))

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

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

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

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

print(ans)

Solution (Python):
n = int(input())
pl = list(map(int, input().split()))
ans = 0
for p1,p2,p3 in zip(pl[:-2],pl[1:-1],pl[2:]):
    if p1 < p2 and p2 < p3 or p1 > p2 and p2 > p3:
        ans += 1

print(ans)

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

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


cnt=0

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

print(cnt)