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

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

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

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

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

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

	t.sort()
	
	if t[1] == 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):
    a=p[i-1:i+2]
    if min(a[0],a[2])<a[1]<=max(a[0],a[2]):
        ans+=1
print(ans)

Solution (Python):

n = int(input())
p= [int(j) for j in input().split()]
ans =0
for i in range(0,n-3+1):
    if p[i:i+3][1] ==sorted(p[i:i+3])[1]:
        ans+=1
        
print(ans)

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

Solution (Python):
import sys
import math
from collections import Counter
import itertools



def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

def LI(): return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'


p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")



n = int(input())
p=LI()

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


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


main()

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

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

Solution (Python):

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

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

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

ans = 0

for i in range(n - 2):
    if(max(p[i : i+3]) > p[i+1] and min(p[i : i+3]) < 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] and p[i+1]<p[i+2]:
		res+=1
	elif p[i]>p[i+1] and p[i+1]>p[i+2]:
		res+=1
print(res)

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:i + 2]) and p[i] != max(p[i - 1: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):
    l = [p[i - 1], p[i], p[i + 1]]
    l.sort()
    if l[1] == p[i]:
        c += 1
print(c)

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

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

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

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())
a = list(map(int,input().split()))
ans = 0
s = 1
while s < n-1:
  if a[s-1] < a[s] < a[s+1] or a[s-1] > a[s] > a[s+1]:
    ans += 1  
  s += 1
print(ans)

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

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

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

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

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

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

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd 
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) 







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

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

counter = 0

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

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

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

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(n-2):
  if (a[i] > a[i+1] and a[i+1] > a[i+2]) or (a[i] < a[i+1] and a[i+1] < a[i+2]):
    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
    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()))
ans = 0
for i in range(n-2):
    T = P[i:i + 3]
    if T == sorted(T) or T == sorted(T,reverse=True):
        ans += 1
print(ans)

Solution (Python):


n = int(input())
p = list(int(x) for x 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()))
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()))
count=0
for i in range(1,n-1):
  if(p[i]>p[i-1] and p[i]<p[i+1]):
    count+=1
     
  if(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()))
cnt=0

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

print(ans)

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

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

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

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

ans = 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]:
    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]) or (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()]

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

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

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

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

Solution (Python):
def ll():
    return list(map(int,input().split()))
def l():
    return int(input())
n = l()
s = ll()
count=0
for i in range(len(s)-2):
    b = [s[i],s[i+1],s[i+2]]
    c = sorted(b)
    if b[1]==c[1]:
        count+=1
print(count)

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

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

print(count)

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

for i in range(0,len(A)-2):
    B=[A[i],A[i+1],A[i+2]]
    C=sorted(B)
    if B[1]==C[1]:
        count+=1

print(count)

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

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

cnt=0

for i in range(1,n-1):
  f=p[i-1]
  s=p[i]
  t=p[i+1]

  if f<s and s<t:
    cnt+=1
  elif t<s and s<f:
    cnt+=1

print(cnt)

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

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

Solution (Python):

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

def middle(a,b,c,cnt):
    lst =[a,b,c]
    lst.sort()
    if lst[1] == b:
        cnt += 1
        
    return cnt
cnt = 0
for i in range(n-2):
    cnt = middle(p[i],p[i+1],p[i+2],cnt)
    
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 = [int(i) for i in 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()))
num = 0

for i in range(n-2):
    a,b,c = p[i],p[i+1],p[i+2]
    if a <= b<=c or a >= b >= c:
        num += 1
print(num)

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

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

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

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

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

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):
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):
    p=P[i-1:i+2]
    p_s=sorted(p)
    if p[1]==p_s[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 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):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


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

print(counter)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()

N, A, B = map(int, input().split())

A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""
N = int(input())
P = list(map(int, input().split()))
counter = 0
for i in range(1, len(P) - 1):
    if (P[i - 1] < P[i] and P[i] < P[i + 1]) or (P[i - 1] > P[i] and P[i] > P[i + 1]):
        counter += 1

print(counter)

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

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

print(count)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    s = S()
    b = list(set(s))
    a = len(list(set(s)))
    if a == 2 and s.count(b[0]) == s.count(b[1]) == 2:
        print("Yes")
    else:
        print("No")
    return


def B():
    n = II()
    p = LI()
    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)
    return


def C():
    n = II()
    d = LI()
    d.sort()
    ans = 0
    for i in range(10**5+1):
        if n // 2 == bisect_left(d, i):
            ans += 1
    print(ans)
    return


def combination_mod(n, k, mod):
    
    

    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = factorial(n) % mod
    b = factorial(k) % mod
    c = factorial(n - k) % mod
    return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod
    
def power_func(a, b, mod):
    
    

    if b == 0: return 1
    if b % 2 == 0:
        d = power_func(a, b // 2, mod)
        return d * d % mod
    if b % 2 == 1:
        return (a * power_func(a, b - 1, mod)) % mod


def D():
    n, k = LI()
    ans = 0
    for i in range(1,k+1):
        a = combination_mod(n - k + 1, i, mod)
        b = combination_mod(k - 1, i - 1, mod)
        print((a*b)%mod)
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    B()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
p = LIST()
cnt = 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]):
		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()))

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-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):
icase=0
if icase==0:
    n=int(input())
    p=list(map(int,input().split()))
    icnt=0
    pi=[0]*3
    for i in range(1,n-1):
        pi=[p[i+1],p[i],p[i-1]]
        if p[i]==sum(pi)-min(pi)-max(pi):
            icnt+=1
    print(icnt)

Solution (Python):
import sys
n = int(input())
p = list(map(int, sys.stdin.readline().rstrip().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(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):
    s = [p[i-1], p[i], p[i+1]]
    s = sorted(s)
    if s[1] == p[i]:
        count += 1

print(count)

Solution (Python):
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(readline())
  P = list(map(int, readline().split()))
  ans = 0
  for i in range(N-2):
    p1 = P[i]
    p2 = P[i+1]
    p3 = P[i+2]
    if (p1<p2<p3) or (p1>p2>p3):
      ans += 1
  
  print(ans)
  
  
  
  
      
if __name__ == '__main__':
  main()

Solution (Python):
def main():
    n = int(input())
    p = [int(a) for a in input().split()]
    count = 0
    for i in range(1, len(p) - 1):
        p_ = p[i - 1 : i + 2]
        p_.sort()
        if p[i] == p_[1]:
            count += 1
    print(count)
main()

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

Solution (Python):



def MI():return map(int,input().split())
def LI():return list(MI())

n,*p=map(int,open(0).read().split())

cnt=0
for a,b,c in zip(p[0:],p[1:],p[2:]):
    if a>b>c or a<b<c:
        cnt+=1
    
print(cnt)

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

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

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

print(ans)

Solution (Python):
n=int(input())
*p,=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()]
count = 0
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 mn!=p[i] and  mx != 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]) 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()))
count = 0
for i in range(len(p)-1):
    if i == 0:
        continue
    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())
P = list(map(int,input().split()))
ans = 0
for i in range(1, n - 1):
    now = P[i]
    tmp = [P[i - 1], P[i], P[i + 1]]
    tmp.sort()
    if now == tmp[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 + 2] <= p[i + 1] < p[i]:
        ans += 1
    else:
        continue

print(ans)

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

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

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

if __name__ == "__main__":
  resolve()

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    P = [int(p) for p 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)

    return 0

if __name__ == "__main__":
    solve()

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):
    k = p[i-1:i+2]
    l = k.copy()
    l.sort()
    if l[1] == k[1]:
        ans += 1
print(ans)

Solution (Python):
def solve():
    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__':
    solve()

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

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