CodeEff/ECCO huggingface dataset:
# Original solution
import sys


def input():
    return sys.stdin.readline().strip()


def restore(s):
    while len(s) > 1:
        s = s.replace("AA", "B")
        s = s.replace("BB", "A")
        s = s.replace("AB", "")
        s = s.replace("BA", "")
    return s


S = input()
T = input()
q = int(input())
for _ in range(q):
    a, b, c, d = map(int, input().split())
    r_s = restore(S[a - 1 : b])
    r_t = restore(T[c - 1 : d])
    print("YES") if r_s == r_t else print("NO")


# Optimized solution
import sys
from itertools import accumulate


def input():
    return sys.stdin.readline().strip()


def acc(li, n):
    res = [0] * (n + 1)
    for i in range(n):
        if li[i] == "A":
            res[i + 1] = 1
        elif li[i] == "B":
            res[i + 1] = 2
    return list(accumulate(res))


def restore(x, y, li):
    return (li[y] - li[x - 1]) % 3


S = input()
T = input()
N = len(S)
M = len(T)

acc_S = acc(S, N)
acc_T = acc(T, M)

q = int(input())
for _ in range(q):
    a, b, c, d = map(int, input().split())
    v_S = restore(a, b, acc_S)
    v_T = restore(c, d, acc_T)
    print("YES") if v_S == v_T else print("NO")
# Original solution
s = input()
t = input()
n = int(input())
q = []
for i in range(n):
    abcd = list(map(int, input().split()))
    q.append(abcd)

def shorten(s):
    if s[0] != s[1]:
        return s[2:]
    elif s[1] != s[2]:
        return s[0] + s[3:]
    return s[3:]

def check(s):
    sc = [s]
    while len(s) >= 3:
        if s in visited:
            s = visited[s]
            break
        s = shorten(s)
        sc.append(s)

    if len(s) == 2:
        if s == 'AA':
            s = 'B'
        elif s == 'BB':
            s = 'A'
        else:
            s = ''

    for sci in sc:
        visited[sci] = s

    return s

visited = {}
for a,b,c,d in q:
    si = check(s[a-1:b])
    ti = check(t[c-1:d])

    if si == ti:
        print('YES')
    else:
        print('NO')


# Optimized solution
S = input()
T = input()
n = int(input())
q = []
for i in range(n):
    abcd = list(map(int, input().split()))
    q.append(abcd)

toi = lambda c: 1 if c == 'A' else 2
s = [0] * (len(S)+1)
for i in range(len(S)):
    s[i+1] = s[i] + toi(S[i])

t = [0] * (len(T)+1)
for i in range(len(T)):
    t[i+1] = t[i] + toi(T[i])

for a,b,c,d in q:
    si = (s[b] - s[a-1]) % 3
    ti = (t[d] - t[c-1]) % 3
    if si == ti:
        print('YES')
    else:
        print('NO')
# Original solution
x = eval(input())
w = [int(i) for i in input().split()]
d = 0
for i in range(len(w) -2 ):
    if (w[i] > w[i+1] > w[i+2]) or (w[i] < w[i+1] < w[i+2]):
        d += 1

print(d)


# Optimized solution
n=int(eval(input()))
v=[int(i) for i in input().split()]
ans=0
for i in range(1, len(v)-1):
    if (v[i]>v[i-1] and v[i]<v[i+1]) or (v[i]<v[i-1] and v[i]>v[i+1]):
        ans+=1
print(ans)
# Original solution
n = int(eval(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]) or (p[i+1] < p[i] < p[i-1]):
        a += 1
print(a)


# Optimized solution
# 少しひっかけ問題っぽいです。
n = int(eval(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]) or (p[i+1] < p[i] < p[i-1]):
        a += 1
print(a)
# Original solution
N=int(eval(input()))
temp=input().split()
p=[int(temp[i]) for i in range(N)]

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)

# Optimized solution
n=int(eval(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((int(counter)))
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))
print((sum(l[i]<l[i+1]<l[i+2] or l[i]>l[i+1]>l[i+2] for i in range(n-2))))

# Optimized solution
n=int(eval(input()))
l=list(map(int,input().split()))
a=0
for i in range(n-2):
  p,q,r=l[i:i+3]
  if p<q<r or r<q<p: a+=1
print(a)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
    if a[i - 1] < a[i] < a[i + 1] or a[i - 1] > a[i] > a[i + 1]:
        ans += 1
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n - 2):
    if a[i] < a[i + 1] < a[i + 2]:
        ans += 1
    if a[i] > a[i + 1] > a[i + 2]:
        ans += 1
print(ans)
# Original solution
n=int(eval(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)

# Optimized solution
n=int(eval(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)
# Original solution
N = int(eval(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)


# Optimized solution
N = int(eval(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)
# Original solution
n = int(eval(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)


# Optimized solution
n = int(eval(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)
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
    if max(l[i], l[i+1], l[i+2]) != l[i+1] and min(l[i], l[i+1], l[i+2]) != l[i+1]:
        cnt += 1
print(cnt)

# Optimized solution
n = int(eval(input()))
l = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
    if l[i]<l[i+1]<l[i+2] or l[i]>l[i+1]>l[i+2]:
        cnt += 1
print(cnt)
# Original solution
#B
n = int(eval(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)

# Optimized solution
n = int(eval(input()))
p = list(map(int, input().split()))
count = 0
for i in range(1, n-1):
    if p[i-1] < p[i] and p[i] < p[i+1]:
        count += 1
    elif p[i-1] > p[i] and p[i] > p[i+1]:
        count += 1
    else:
        pass

print(count)
# Original solution
n = int(eval(input()))
p = [int(x) for x in input().split()]

cnt = 0

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

# Optimized solution
n = int(eval(input()))
p = [int(_) for _ in input().split()]
cnt =0
for i in range(2,n):
  if p[i-2] < p[i-1] < p[i] or p[i]<p[i-1]<p[i-2]:
    cnt +=1
print(cnt)
# Original solution

n = int(eval(input()))
ps = list(map(int, input().split()))

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

print(count)

# Optimized solution

n = int(eval(input()))
ps = list(map(int, input().split()))

count = 0
for i in range(n-2):
    a = [ps[i], ps[i+1], ps[i+2]]
    b = ps[i+1]
    a.sort()
    if a[1] == b:
        count += 1

print(count)
# Original solution
N = int(eval(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)

# Optimized solution
N = int(eval(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)
# Original solution
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(eval(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)



# def main():

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


# Optimized solution
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(eval(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)
# Original solution
n = int(eval(input()))
p = list(map(int, input().split()))

ans = sum(p[i] == (p[i + 1] + p[i] + p[i - 1] - max(p[i + 1], p[i], p[i - 1]) - min(p[i + 1], p[i], p[i - 1])) for i in range(1, n - 1))

print(ans)


# Optimized solution
n = int(eval(input()))
p = list(map(int, input().split()))


ans = sum(
    p[i - 1] < p[i] < p[i + 1] or p[i - 1] > p[i] > p[i + 1]
    for i in range(1, n - 1)
)

print(ans)
# Original solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    d = defaultdict(int)
    for i in s:
        d[i] += 1
    for i in list(d.keys()):
        if d[i] != 2:
            print("No")
            quit()
    print("Yes")
    return

#B
def B():
    n = I()
    p = LI()
    ans = 0
    for i in range(1,n-1):
        k = p[i-1:i+2]
        k.sort()
        if k[1] == p[i]:
            ans += 1
    print(ans)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return


#Solve
if __name__ == "__main__":
    B()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    p = LI()
    a = [0]*(n+1)
    a[p[0]] += 1
    a[p[1]] += 1
    a[p[2]] += 1
    ans = 0
    if sum(a[:p[1]]) == 1:
        ans += 1
    for i in range(2,n-1):
        a[p[i-2]] -= 1
        a[p[i+1]] += 1
        if sum(a[:p[i]]) == 1:
            ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()
# Original solution
n = int(eval(input()))

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

Answer = int(0)
for i in range(n-2):
     if L[i]<L[i+1] and L[i+1]<L[i+2]:
             Answer = Answer + 1
             continue
     if L[i+2]<L[i+1] and L[i+1]<L[i]:
             Answer = Answer + 1
             continue
print(Answer)


# Optimized solution
n = int(eval(input()))

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

Answer = int(0)
for i in range(n-2):
     if L[i]<L[i+1] and L[i+1]<L[i+2]:
             Answer = Answer + 1
     if L[i+2]<L[i+1] and L[i+1]<L[i]:
             Answer = Answer + 1
print(Answer)
# Original solution
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

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)
# lcm = lambda x, y: (x * y) // fractions.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()


# Optimized solution
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
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()
# Original solution
n = int(eval(input()))
p = list(map(int, input().split()))

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

print(count)

# Optimized solution
n = int(eval(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]:
        count = count +1
    elif p[i+1] < p[i] < p[i-1]:
        count = count +1
    else:
        pass

print(count)
# Original solution
cnt = 0
n = int(eval(input()))
lst = [int(i) for i in input().split()]
for i in range(n-2):
    a,b,c = lst[i],lst[i+1],lst[i+2]
    if (a<b and b<c) or (c<b and b<a):
        cnt += 1
print(cnt)

# Optimized solution
n = int(eval(input()))
lst = list(map(int,input().split()))
cnt = 0
for i in range(1,n-1):
    x,y,z = lst[i-1],lst[i],lst[i+1]
    if x<=y<=z or z<=y<=x:
        cnt += 1
print(cnt)
# Original solution
n = int(eval(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)

# Optimized solution
def solve():
    n = int(eval(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()
# Original solution
n = int(eval(input()))

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

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

print(ans)


# Optimized solution
N = int(eval(input()))

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

ans = 0
for i in range(1, N-1):
    if (PPP[i] >= PPP[i-1] and PPP[i+1] > PPP[i]) or (PPP[i] >= PPP[i+1] and PPP[i-1] > PPP[i]):
        ans += 1

print(ans)
# Original solution
n = int(eval(input()))
p = list(map(int, input().split()))
cnt = 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]:
        cnt += 1
print(cnt)


# Optimized solution
n = int(eval(input()))
p = list(map(int, input().split()))
cnt = 0
for i in range(2, n):
    a = [p[i], p[i-1], p[i-2]]
    a.sort()
    if p[i-1] == a[1]:
        cnt += 1
print(cnt)
# Original solution
n = int(eval(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)

# Optimized solution
n = int(eval(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)
# Original solution
n = int(eval(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)


# Optimized solution
n = int(eval(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)
# Original solution
N = int(eval(input()))
P = list(map(int, input().split()))
ans = 0
for i in range(N-2):
    ans += P[i] < P[i+1] < P[i+2]
    ans += P[i] > P[i+1] > P[i+2]
print(ans)


# Optimized solution
n = int(eval(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)
# Original solution
n=int(eval(input()))
p=list(input().split())
p=[int(i) for i in p]
cnt=0
for i in range(1,n-1):
    if p[i]!=max(p[i-1],max(p[i],p[i+1])) and p[i]!=min(p[i-1],min(p[i],p[i+1])):
        cnt+=1
print(cnt)


# Optimized solution
n=int(eval(input()))
p=list(input().split())
p=[int(i) for i in p]
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)
# Original solution
n = int(eval(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)

# Optimized solution
n = int(eval(input()))
p = list(map(int,input().split()))
ans = 0
for i in range(1,n-1):
    t = p[i-1:i+2]
    if max(t)>t[1]>min(t):
        ans+=1
print(ans)
# Original solution
n = int(eval(input()))
p = list(map(int , input().split()))

meet_condition = 0

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

# Optimized solution
n = int(eval(input()))
p = list(map(int , input().split()))

meet_condition = 0

for i in range(1 , n-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
        meet_condition += 1
        
print(meet_condition)
# Original solution
n = int(eval(input()))
pn = list(map(int,input().split()))

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

# Optimized solution
count = 0
n = int(eval(input()))
p = list(map(int,input().split()))

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)
# Original solution
N = int(eval(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)

# Optimized solution
n=int(eval(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)
# Original solution
def solve(string):
    n, c = string.split()
    n, c = int(n), list(c)
    wi, ri = 0, n - 1
    while wi < n and c[wi] == "R":
        wi += 1
    while ri >= 0 and c[ri] == "W":
        ri -= 1
    ans = 0
    while wi < n and ri >= 0 and wi < ri:
        c[wi], c[ri], ans = c[ri], c[wi], ans + 1
        wi, ri = wi + 1, ri - 1
        while wi < n and c[wi] == "R":
            wi += 1
        while ri >= 0 and c[ri] == "W":
            ri -= 1
    return str(ans)


if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))


# Optimized solution
def solve(string):
    _, c = string.split()
    r = c.count("R")
    return str(c[:r].count("W"))


if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))
# Original solution
# 初期入力
from bisect import bisect_left
import sys
#input = sys.stdin.readline  #文字列では使わない
N = int(eval(input()))
c =input().strip()
ans =0
w =[i for i, x in enumerate(c) if x == 'W']
r =[i for i, x in enumerate(c) if x == 'R']
w_num =len(w) #全体でWの数
r_num =len(r) #全体でRの数

ans =bisect_left(r,r_num)
print((r_num -ans))

# Optimized solution

# 初期入力
from bisect import bisect_left
import sys
#input = sys.stdin.readline  #文字列では使わない
N = int(eval(input()))
c =input().strip()
ans =0
r =[i for i, x in enumerate(c) if x == 'R'] #全体の中でRのIndex
r_num =len(r) #全体でRの数

ans =bisect_left(r,r_num) #呪われないためのRとWの境界
print((r_num -ans)) #境界より右側のRの数
# Original solution
import sys
input = sys.stdin.readline

n=int(eval(input()))
s=list(input().strip())
count = 0
for i in range(n):
    if s[i]=='W':
        for j in range(n-1,i,-1):
            if s[j]=='R':
                s[i],s[j]=s[j],s[i]
                count+=1
                break
        else:
            break
        
print(count)



# Optimized solution
import sys
input = sys.stdin.readline

n=int(eval(input()))
s=list(input().strip())
count = 0
cw = s.count('W')
cr = n-cw

for i in range(cr):
    if s[i]=='W':
        count+=1

print(count)
# Original solution
# -*- coding: utf-8 -*-
import sys


def main():
    N = int( sys.stdin.readline() )
    c_list = list(sys.stdin.readline().rstrip())
    

    cnt = 0
    L = 0
    R = len(c_list) - 1

    while L < R:
        if (c_list[L] == "W") and (c_list[R] == "R"):
            c_list[L], c_list[R] = c_list[R], c_list[L]
            cnt += 1
            L += 1
            R -= 1
        elif c_list[L] == "R":
            L += 1
        elif c_list[R] == "W":
            R -= 1
    
    
    print(cnt)


if __name__ == "__main__":
    main()


# Optimized solution
# -*- coding: utf-8 -*-
import sys


def main():
    N = int( sys.stdin.readline() )
    c_list = list(sys.stdin.readline().rstrip())
    

    num_R = c_list.count("R")
    cnt = 0

    for i in range(num_R):
        if c_list[i] == "W":
            cnt += 1
    
    print(cnt)


if __name__ == "__main__":
    main()
# Original solution
import re

N = int(input().strip())
# C = [c for c in input().strip()]
C = input().strip()

G = re.compile(r"^R*W*$")
cnt = 0


def rep(i, c, r, w):
    if i == r:
        return "W"
    elif i == w:
        return "R"
    else:
        return c

while not G.match(C):
    cnt += 1
    r = C.rfind("R")
    w = C.find("W")
    C = "".join([
        rep(i, c, r, w)
        for i, c in enumerate(C)
    ])
    # break

print(cnt)

# Optimized solution
N = int(input().strip())
C = [c for c in input().strip()]

if "W" not in C or "R" not in C:
    print((0))
    import sys; sys.exit(0)

cnt = 0

i = 0
j = len(C) - 1
while i < j:
    while C[i] == "R":
        i += 1
    while C[j] == "W":
        j -= 1
    if i > j:
        break
    cnt += 1
    C[i] = "R"
    C[j] = "W"
    i += 1
    j -= 1

print(cnt)