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):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
li = rl()
cnt = 0
for i in range(1, n-1):
  if li[i-1] < li[i] < li[i+1] or li[i-1] > li[i] > li[i+1]:
    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 sorted([a[i-1], a[i], a[i+1]])[1]==a[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 l[i]>l[i-1] and l[i]<l[i+1]:
    ans+=1
  elif l[i]<l[i-1] and l[i]>l[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):
    l = p[i:i+3]
    l.sort()
    if p[i+1] == l[1]:
        ans+=1
print(ans)

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

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

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    n = I()
    p = LI()
    cnt = 0
    for i in range(n-2):
        if p[i] < p[i+1] < p[i+2]:
            cnt += 1
        if p[i+2] < p[i+1] < p[i]:
            cnt += 1
    print(cnt)
main()

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

def main():
    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)
    
if __name__ == '__main__':
    main()

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

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

print(a)

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
li = []

for i in range(1, n-1):
  mn = min(p[i-1], p[i], p[i+1])
  mx = max(p[i-1], p[i], p[i+1])
  if p[i]!=mn and p[i]!=mx:
    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):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque


from collections import Counter

from itertools import accumulate,combinations,permutations

from heapq import heapify,heappop,heappush


from functools import lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    

    N = int(input())
    
    A = tuple(map(int, input().split())) 
    
    
    count=0
    for i in range(N-2):
        a1,a2,a3=A[i],A[i+1],A[i+2]
        if a1<a2<a3 or a3<a2<a1:
            count+=1
    print(count)
 




if __name__ == "__main__":
    main()

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

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

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

Count = 0
for T in range(0,N-2):
    if P[T+1] == sorted(P[T:T+3])[1]:
        Count += 1
print(Count)

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    P = il()
    ret = 0
    for n in range(1, N - 1):
        if P[n - 1] < P[n] < P[n + 1] or P[n - 1] > P[n] > P[n + 1]:
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):

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

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

for i in range(N-2):
    if arr[i+1]!=max(arr[i:i+3]) and arr[i+1]!=min(arr[i:i+3]):
        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):
    tmp_P = P[i-1:i+2]
    a = tmp_P[1]
    tmp_P.sort()
    if a == tmp_P[1]:
        ans += 1

print(ans)

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


count = 0
for i in range(1,n-1):
    if min(L[i-1],L[i+1]) < L[i] < max(L[i-1], L[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):
    S=p[i:i+3]
    if S[0]<S[1]<S[2] or S[2]<S[1]<S[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):
    kore = p[i-1:i+2]
    if p[i] == sorted(kore)[1]:res += 1
print(res)

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):
import numpy as np

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

def check_condition(l):
  if (l[0] < l[1] < l[2]) or  (l[0] > l[1] > l[2]):
    return 1
  else:
  	return 0

is_satisfied = [check_condition(p[i:i+3]) for i in range(n-2)]
  
print(np.sum(is_satisfied))

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

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

    
if __name__ == "__main__":
    main()

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

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

print(count)

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

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

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

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

Solution (Python):
nb = int(input())
liste = [int(x) for x in input().split()]
compteur = 0
for loop in range(nb-2):
    if (liste[loop+1]>liste[loop] and liste[loop+1]<liste[loop+2]) or (liste[loop+1]<liste[loop] and liste[loop+1]>liste[loop+2]):
        compteur +=1
print(compteur)

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    P = il()

    ret = 0
    for n in range(N - 2):
        trg = P[n:n + 3][1]
        if sorted(P[n:n + 3])[1] == trg: ret += 1
    print(ret)


if __name__ == '__main__':
    main()

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

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

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

print(cnt)

Solution (Python):
num = int(input())
arr = input().split()
count = 0
 
for i in range(1, num-1):
  if int(arr[i-1]) < int(arr[i]) < int(arr[i+1]) or int(arr[i-1]) > int(arr[i]) > int(arr[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())
cnt=0
p=[int(x) for x in input().rstrip().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]:
    cnt+=1
print(cnt)

Solution (Python):
n = int(input())
arr = input().split()
count = 0

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

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

Solution (Python):


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

def sec(a, k, b):
    if (a <= k <= b) or (a >= k >= b):
        global num
        num += 1

for i in range(1, n-1):
    sec(p[i-1], p[i], p[i+1])

print(num)

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

cnt = 0
for i in range(N-2):
    LA = []
    LB = []
    LA = [LP[i],LP[i+1],LP[i+2]]
    LB = sorted(LA)
    if LA[1] == LB[1]:
        cnt += 1
print(cnt)

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

cnt = 0
for i in range(N-2):
    LA = []
    LB = []
    LA.append(LP[i])
    LA.append(LP[i+1])
    LA.append(LP[i+2])
    LB = sorted(LA)
    if LA[1] == LB[1]:
        cnt += 1
print(cnt)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    n, *P = map(int, read().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)
    return


if __name__ == '__main__':
    main()

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

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


if __name__ == '__main__':
    solve()

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

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

print(ans)

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

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

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] < P[i+1]: 
      A += 1
    if P[i-1] > P[i] > P[i+1]: 
      A += 1
print(A)

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

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

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

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

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

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

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

for i in range(n-2):
    if p[i+1]!=min(p[i:3+i]) and p[i+1]!=max(p[i:3+i]):
        c+=1
    elif p[i+1]==max(p[i:3+i]) and p[i:3+i].count(p[i+1])==2:
        c+=1
print(c)

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

for i in range(1, n - 1):
    per = [p[i - 1], p[i], p[i + 1]]
    per.sort()
    
    if per[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):
    Pps = sorted(P[i:i + 3])
    if Pps[1] == P[i + 1]:
        ans += 1
print(ans)

Solution (Python):

def main():
    n = int(input())
    P = list(map(int, input().split()))

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

    print(ans)


main()

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

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

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

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

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

for i in range(1,n-1):
  l=p[i-1]
  m=p[i]
  r=p[i+1]
  if l<m<r or r<m<l:
    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())
l = list(map(int,input().split()))

count = 0
for i in range(n-2):

    if(l[i] < l[i+1] and l[i+1] < l[i+2]):
        count += 1
        continue
    if(l[i+2] < l[i+1] and l[i+1] < l[i]):
        count += 1
        continue

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]
    if a<=b<=c or c<=b<=a:count+=1
print(count)

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

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

if __name__ == '__main__':
    main()

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

Solution (Python):
def is_no2(X):
    if X[1] == min(X) or X[1] == max(X):
        return 0
    else:
        return 1

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

ans = 0
for i in range(N-2):
    X = [P[i], P[i+1], P[i+2]]
    ans += is_no2(X)

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

input = lambda: sys.stdin.readline().rstrip()


def solve():
    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)


if __name__ == '__main__':
    solve()

Solution (Python):
def main():
    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)
    
if __name__ == "__main__":
    main()

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

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

    if p[i-1] > p[i] and p[i] > p[i+1]:
        c = c + 1

print(c)

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

ans = 0
for i in range(0,len(P)-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()))

start = 2 - 1
end = len(p) - 1

count = 0
for i in range(start, end):
    
    a = p[i - 1]
    b = p[i]
    c = p[i + 1]
    
    
    
    new_list = sorted([a, b, c])
    
    if b == new_list[1]:
        
        count += 1
        
print(count)

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

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

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

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

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

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

print(cnt)

Solution (Python):
def main():
    _ = input()
    A = list(map(int, input().split()))
    cnt = 0
    for i in range(len(A)-2):
        A_sub = sorted(A[i:i+3])
        a = A[i+1]
        if a == A_sub[1]:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):
def actual(n, P):
    count = 0

    for i in range(1, n - 1):
        a, b, c = P[i - 1], P[i], P[i + 1]

        if (a < b < c) or (a > b > c):
            count += 1

    return count

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

print(actual(n, P))

Solution (Python):
N=int(input())
S=list(map(int,input().split()))
count=0
for i in range(N-2):
    if max(S[i],S[i+1],S[i+2])==S[i+1] or min (S[i],S[i+1],S[i+2])==S[i+1]:
        count+=0
    else:
        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()))
res=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]:
        res+=1
print(res)

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

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

Solution (Python):
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
p=lmp()
ans=0
for i in range(n-2):
    if sorted(list((p[i],p[i+1],p[i+2])))[1]==p[i+1]:
        ans+=1
print(ans)

Solution (Python):
import math
def ip():return int(input())
def inp():return map(int,input().split())
def linp():return list(map(int,input().split()))

n=ip()
p=linp()
ans=0
for i in range(1,n-1):
    l=[p[i-1],p[i],p[i+1]]
    if p[i]>min(l) and p[i]<max(l):ans+=1
print(ans)

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

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

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

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

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    p = list(map(int, input().split()))
    ans = 0
    for i in range(n - 2):
        tmp = p[i: i + 3]
        tmp.sort()
        if tmp[1] == p[i + 1]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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

Solution (Python):

import sys
input = sys.stdin.readline
n = int(input())
p = list(map(int, input().split()))


count =[]
for i in range(1,n-1):
    p3 =p[i-1:i+2]
    p3.sort()
    if p3[1] ==p[i]:
        count.append(i)
print(len(count))

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