You are given an array a. Some element of this array a_{i} is a local minimum iff it is strictly less than both of its neighbours (that is, a_{i} < a_{i} - 1 and a_{i} < a_{i} + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, a_{i} > a_{i} - 1 and a_{i} > a_{i} + 1). Since a_1 and a_{n} have only one neighbour each, they are neither local minima nor local maxima.

An element is called a local extremum iff it is either local maximum or local minimum. Your task is to calculate the number of local extrema in the given array.


-----Input-----

The first line contains one integer n (1 ≤ n ≤ 1000) — the number of elements in array a.

The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 1000) — the elements of array a.


-----Output-----

Print the number of local extrema in the given array.


-----Examples-----
Input
3
1 2 3

Output
0

Input
4
1 5 2 5

Output
2

Difficulty: EASY

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

def main():
	i = 0
	ans = 0
	while i < len(arr):
		first = 0
		last = len(arr) - 1
		if i != first and i != last:
			if arr[i] < arr[i - 1] and arr[i] < arr[i + 1] or (arr[i] > arr[i - 1] and arr[i] > arr[i + 1]):
				ans += 1
		i += 1
	print(ans)
main()


n = int(input())
A = input().split()
A = [int(i) for i in A]
count = 0
if n == 1:
	print(0)
else:
	for i in range(1, n - 1):
		if (A[i] - A[i - 1]) * (A[i] - A[i + 1]) > 0:
			count += 1
	print(count)


a = (*map(int, [*open(0)][1].split()),)
print(sum(((y - x) * (y - z) > 0 for (x, y, z) in zip(a, a[1:], a[2:]))))


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


n = int(input())
m = list(map(int, input().split(' ')))
if len(m) > 1:
	b = m[0]
	c = m[1]
k = 0
for i in range(2, n):
	a = b
	b = c
	c = m[i]
	if a > b < c or c < b > a:
		k += 1
print(k)


n = int(input())
arr = [int(i) for i in input().split()]
c = 0
for i in range(1, n - 1):
	if arr[i] > arr[i - 1] and arr[i] > arr[i + 1] or (arr[i] < arr[i - 1] and arr[i] < arr[i + 1]):
		c += 1
print(c)


r = int(input())
n = input().split()
for i in range(len(n)):
	n[i] = int(n[i])

def main(ns):
	es = 0
	for i in range(1, len(ns) - 1):
		if ns[i] < ns[i - 1] and ns[i] < ns[i + 1] or (ns[i] > ns[i - 1] and ns[i] > ns[i + 1]):
			es = es + 1
	print(es)
main(n)


n = input()
a = [int(s) for s in input().split(' ')]
ans = 0
for i in range(1, len(a) - 1):
	if a[i] > a[i - 1] and a[i] > a[i + 1] or (a[i] < a[i - 1] and a[i] < a[i + 1]):
		ans += 1
print(ans)


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


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


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


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


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


from sys import stdin, stdout
N = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
count = 0
for i in range(1, len(arr) - 1):
	if arr[i - 1] > arr[i] and arr[i] < arr[i + 1]:
		count += 1
	elif arr[i - 1] < arr[i] and arr[i] > arr[i + 1]:
		count += 1
stdout.write(str(count) + '\n')


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


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


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


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


n = int(input().strip())
arr = [int(e) for e in input().strip().split()]
number_extrema = 0
for i in range(1, len(arr) - 1):
	if arr[i] > arr[i - 1] and arr[i] > arr[i + 1] or (arr[i] < arr[i + 1] and arr[i] < arr[i - 1]):
		number_extrema += 1
print(number_extrema)


n = int(input())
data = [int(i) for i in input().split()]
extr = 0
for i in range(1, n - 1):
	if data[i] > data[i + 1] and data[i] > data[i - 1] or (data[i] < data[i - 1] and data[i] < data[i + 1]):
		extr += 1
print(extr)


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


n = int(input())
l = [int(i) for i in input().split()]
print(sum((l[i] > l[i - 1] and l[i] > l[i + 1] or (l[i] < l[i - 1] and l[i] < l[i + 1]) for i in range(1, n - 1))))


n = int(input())
a = [int(e) for e in input().split()]

def is_extremum(i, arr):
	return i > 0 and i < len(arr) - 1 and (arr[i - 1] < arr[i] and arr[i] > arr[i + 1] or (arr[i - 1] > arr[i] and arr[i] < arr[i + 1]))
print(sum([1 for (i, _) in enumerate(a) if is_extremum(i, a)]))


import math
from sys import stdin
number = int(stdin.readline())
string = stdin.readline().strip().split()
output = 0
for i in range(1, number - 1):
	if int(string[i]) < int(string[i - 1]) and int(string[i]) < int(string[i + 1]):
		output += 1
	if int(string[i]) > int(string[i - 1]) and int(string[i]) > int(string[i + 1]):
		output += 1
print(output)


n = int(input())
list1 = [int(i) for i in input().split()]
if n == 1 or n == 2:
	print(0)
else:
	total = 0
	for i in range(1, n - 1):
		if list1[i] > list1[i + 1] and list1[i] > list1[i - 1] or (list1[i] < list1[i + 1] and list1[i] < list1[i - 1]):
			total += 1
	print(total)


def extrema(arr):
	count = 0
	for i in range(1, len(arr) - 1):
		if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
			count += 1
		elif arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
			count += 1
	return count
t = int(input())
print(extrema(list(map(int, input().strip().split()))))


n = int(input())
a = [int(i) for i in input().split(' ')]
r = 0
if n <= 2:
	print(0)
	exit(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]:
		r += 1
print(r)


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


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


n = int(input())
L = [int(x) for x in input().split()]
c = 0
for i in range(1, n - 1):
	if L[i] < L[i - 1] and L[i] < L[i + 1] or (L[i] > L[i - 1] and L[i] > L[i + 1]):
		c += 1
print(c)


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)


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


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


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


n = int(input())
a = [int(x) for x in input().split()]

def is_extrema(a, b, c):
	if a < b and b > c or (a > b and b < c):
		return True
	else:
		return False
ans = 0
for i in range(1, n - 1):
	if is_extrema(a[i - 1], a[i], a[i + 1]):
		ans += 1
print(ans)


input()
mylist = list(map(int, input().split()))
counter = 0
i = 0
while i < len(mylist):
	if i == 0 or i == len(mylist) - 1:
		i += 1
	else:
		if mylist[i] > mylist[i + 1] and mylist[i] > mylist[i - 1]:
			counter += 1
		elif mylist[i] < mylist[i + 1] and mylist[i] < mylist[i - 1]:
			counter += 1
		i += 1
print(counter)


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


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


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
n = int(input())
ans = 0
a = list(map(int, input().split()))
for i in range(1, n - 1):
	if a[i] > a[i - 1]:
		if a[i] > a[i + 1]:
			ans += 1
	if a[i] < a[i - 1]:
		if a[i] < a[i + 1]:
			ans += 1
print(ans)


def find_extrema(n, lst):
	maxima = list()
	minima = list()
	if n >= 3:
		for i in range(1, n - 1):
			if lst[i] > lst[i - 1] and lst[i] > lst[i + 1]:
				maxima.append(lst[i])
			elif lst[i] < lst[i - 1] and lst[i] < lst[i + 1]:
				minima.append(lst[i])
		return len(minima) + len(maxima)
	return 0
m = int(input())
a = [int(j) for j in input().split()]
print(find_extrema(m, a))


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


n = int(input())
sin = str(input()).split()
z = 0
for i in range(1, n - 1):
	if int(sin[i]) > int(sin[i - 1]) and int(sin[i]) > int(sin[i + 1]) or (int(sin[i]) < int(sin[i + 1]) and int(sin[i]) < int(sin[i - 1])):
		z += 1
print(z)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

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

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
n = int(input())
a = list(mapi())
res = 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]:
		res += 1
print(res)


n = int(input())
l = [int(x) for x in input().split()]
count = 0
if n == 1 or n == 2:
	print(0)
else:
	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]:
			count += 1
	print(count)


n = int(input())
data = [int(tmp) for tmp in input().split()]
answer = 0
for i in range(1, n - 1):
	if data[i - 1] < data[i] and data[i + 1] < data[i]:
		answer += 1
	elif data[i - 1] > data[i] and data[i + 1] > data[i]:
		answer += 1
	else:
		pass
print(answer)


useless = input()
numbers = input().split()

def local_extremums(array):
	numbers = list(map(int, array))
	i = 1
	result = 0
	while i < len(numbers) - 1:
		if numbers[i] < numbers[i - 1] and numbers[i] < numbers[i + 1] or (numbers[i] > numbers[i - 1] and numbers[i] > numbers[i + 1]):
			result += 1
		i += 1
	return result
print(local_extremums(numbers))


input()
a = b = s = 0
for c in map(int, input().split()):
	if a and (a > b < c or a < b > c):
		s += 1
	(a, b) = (b, c)
print(s)


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


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


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


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


import sys
a0 = [int(x) for x in sys.stdin.readline().split()]
a = [int(x) for x in sys.stdin.readline().split()]
n = 0
for (i, x) in enumerate(a[1:-1]):
	if x > a[i] and x > a[i + 2]:
		n += 1
	elif x < a[i] and x < a[i + 2]:
		n += 1
print(n)


n = int(input())
a = [int(x) for x in input().split()]
if n <= 2:
	print(0)
	exit(0)
else:
	ans = 0
	for i in range(1, n - 1):
		if a[i] > a[i + 1] and a[i] > a[i - 1] or (a[i] < a[i + 1] and a[i] < a[i - 1]):
			ans += 1
print(ans)


n = int(input()) - 1
a = list(map(int, input().split()))
i = 1
kek = 0
while i <= n - 1:
	if a[i - 1] > a[i] and a[i + 1] > a[i] or (a[i - 1] < a[i] and a[i + 1] < a[i]):
		kek += 1
	i += 1
print(kek)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
ct = 0
for i in range(1, n - 1):
	if a[i] > a[i - 1] and a[i] > a[i + 1] or (a[i] < a[i - 1] and a[i] < a[i + 1]):
		ct += 1
print(ct)


n = int(input())
a = [int(i) for i in input().split()]
c = 0
for i in range(1, n - 1):
	if a[i] > max(a[i - 1], a[i + 1]) or a[i] < min(a[i - 1], a[i + 1]):
		c += 1
print(c)


def main():
	input()
	nums = list(map(int, input().split()))
	lastn = nums.pop(0)
	mc = 0
	while len(nums) > 1:
		buff = nums.pop(0)
		if lastn < buff and buff > nums[0] or (lastn > buff and buff < nums[0]):
			mc += 1
		lastn = buff
	return mc
print(main())


input()
num = [int(x) for x in input().split()]
c = 0
for i in range(1, len(num) - 1):
	if num[i] > num[i + 1] and num[i] > num[i - 1] or (num[i] < num[i + 1] and num[i] < num[i - 1]):
		c += 1
print(c)


n = int(input())
a = [int(s) for s in input().split(' ')]
e = 0
for i in range(1, n - 1):
	if a[i] > max(a[i - 1], a[i + 1]) or a[i] < min(a[i - 1], a[i + 1]):
		e += 1
print(e)


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


n = int(input())
nums = [eval(x) for x in input().split()]
c = 0
for i in range(1, n - 1):
	if nums[i - 1] < nums[i] and nums[i + 1] < nums[i] or (nums[i - 1] > nums[i] and nums[i + 1] > nums[i]):
		c += 1
print(c)


n = int(input())
a = list(map(int, input().split()))
c = 0
if len(a) == 1 or len(a) == 2:
	pass
else:
	for i in range(1, n - 1):
		if a[i - 1] < a[i] and a[i + 1] < a[i] or (a[i - 1] > a[i] and a[i + 1] > a[i]):
			c += 1
print(c)


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


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


def main():
	n = int(input())
	A = [int(y) for y in input().split()]
	solver(n, A)

def solver(n, A):
	count = 0
	for i in range(1, n - 1):
		if isExtremum(A, i):
			count += 1
	print(count)

def isExtremum(A, i):
	return A[i - 1] < A[i] and A[i] > A[i + 1] or (A[i - 1] > A[i] and A[i] < A[i + 1])
main()


n = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
	if L[i] > L[i - 1]:
		if L[i] > L[i + 1]:
			ans += 1
	elif L[i] < L[i - 1]:
		if L[i] < L[i + 1]:
			ans += 1
print(ans)


n = int(input())
sum = 0
str_in = input()
m = [int(i) for i in str_in.split()]
for i in range(n):
	if i == 0:
		continue
	elif i == n - 1:
		break
	elif m[i - 1] < m[i] > m[i + 1] or m[i - 1] > m[i] < m[i + 1]:
		sum += 1
print(sum)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
N = int(input())
A = [int(x) for x in 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)


a = int(input())
b = list(map(int, input().split()))
s = 0
for i in range(1, len(b) - 1):
	if b[i - 1] < b[i] > b[i + 1] or b[i - 1] > b[i] < b[i + 1]:
		s += 1
print(s)


import itertools
n = int(input())
l = [int(i) for i in input().split(' ')]
ret = 0
for i in range(1, len(l) - 1):
	if (l[i] - l[i - 1]) * (l[i] - l[i + 1]) > 0:
		ret += 1
print(ret)


n = int(input())
a = [int(x) for x in input().split()]
ct = 0
for i in range(1, n - 1):
	if a[i] < a[i - 1] and a[i] < a[i + 1]:
		ct += 1
	if a[i] > a[i - 1] and a[i] > a[i + 1]:
		ct += 1
print(ct)


n = int(input())
ls = input()
ls = ls.split(' ')
i = 1
num = 0
l = n - 1
while i < l:
	if int(ls[i]) > int(ls[i - 1]) and int(ls[i]) > int(ls[i + 1]) or (int(ls[i]) < int(ls[i - 1]) and int(ls[i]) < int(ls[i + 1])):
		num += 1
	i += 1
print(str(num))


N = int(input())
X = list(map(int, input().split()))
print(sum([1 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]]))


from sys import stdin
from sys import stdout
sprint = stdout.write
sinput = stdin.readline

def func():
	sprint('F')
t = int(sinput())
t = 0
arr = [int(x) for x in input().split()]
for i in range(1, len(arr) - 1):
	if arr[i] < arr[i - 1] and arr[i] < arr[i + 1] or (arr[i] > arr[i - 1] and arr[i] > arr[i + 1]):
		t += 1
print(t)


import sys
line = sys.stdin.readline()
n = int(line)
line = sys.stdin.readline()
parts = line.split(' ')
a = []
for i in range(n):
	a.append(int(parts[i]))
ans = 0
for i in range(1, n - 1):
	if (a[i] - a[i - 1]) * (a[i] - a[i + 1]) > 0:
		ans += 1
print(ans)


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


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


n = int(input())
data = list(map(int, input().split()))
print(sum((curr > prev and curr > nxt or (curr < prev and curr < nxt) for (curr, (prev, nxt)) in zip(data[1:], zip(data, data[2:])))))


x = int(input())
z = list(map(int, input().split()))
c = 0
for i in range(1, x - 1):
	if z[i] > z[i + 1] and z[i] > z[i - 1] or (z[i] < z[i + 1] and z[i] < z[i - 1]):
		c += 1
print(c)


n = int(input())
arr = [int(num) for num in input().split()]
count = 0
for i in range(1, len(arr) - 1):
	if arr[i - 1] < arr[i] and arr[i + 1] < arr[i] or (arr[i - 1] > arr[i] and arr[i + 1] > arr[i]):
		count += 1
print(count)


n = int(input())
a = list(map(int, input().split()))
if n < 3:
	exit(print(0))
ans = n - 2
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)


x = input()
x = x.split()
x = int(x[0])
y = input()
y = y.split()
z = []
for i in y:
	z.append(int(i))
i = 1
flag = 0
while i < x - 1:
	if z[i] > z[i - 1] and z[i] > z[i + 1]:
		flag += 1
		i += 1
	elif z[i] < z[i - 1] and z[i] < z[i + 1]:
		flag += 1
		i += 1
	else:
		i += 1
print(flag)


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


n = int(input())
A = [int(i) for i in input().split(' ')]
cnt = 0
for i in range(1, n - 1):
	if A[i] > A[i - 1] and A[i] > A[i + 1] or (A[i] < A[i - 1] and A[i] < A[i + 1]):
		cnt += 1
print(cnt)


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


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


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


n = int(input())
a = [int(i) for i in input().split()]
e = 0
if n >= 3:
	for i in range(1, len(a) - 1):
		if a[i] < a[i - 1] and a[i] < a[i + 1] or (a[i] > a[i + 1] and a[i] > a[i - 1]):
			e = e + 1
	print(e)
else:
	print(0)


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


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	ans = 0
	l = LI()
	for i in range(1, n - 1):
		a = l[i - 1]
		b = l[i]
		c = l[i + 1]
		if a < b > c or a > b < c:
			ans += 1
	return ans
print(main())


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


N = int(input())
Str_in = input().split()
Array = []
for i in Str_in:
	Array.append(int(i))
count = 0
for i in range(1, N - 1):
	if Array[i] > Array[i - 1] and Array[i] > Array[i + 1]:
		count = count + 1
	if Array[i] < Array[i - 1] and Array[i] < Array[i + 1]:
		count = count + 1
print(count, '\n')


n = int(input())
a = list(map(int, input().split(' ')))
ma = 0
mi = 0
for i in range(1, len(a) - 1):
	if a[i] < a[i - 1] and a[i] < a[i + 1]:
		ma += 1
	if a[i] > a[i - 1] and a[i] > a[i + 1]:
		mi += 1
print(ma + mi)


n = int(input())
arr = [int(x) for x in input().split()]
count = 0
for i in range(1, n - 1, 1):
	if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
		count += 1
	elif arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
		count += 1
print(count)


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


a = int(input())
a = [int(x) for x in input().split()]
ans = 0
for i in range(1, len(a) - 1):
	if a[i + 1] > a[i] < a[i - 1]:
		ans += 1
	if a[i + 1] < a[i] > a[i - 1]:
		ans += 1
print(ans)


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


input()
i = [*map(int, input().split())]
print(sum((1 for (x, y, z) in zip(i, i[1:], i[2:]) if x > y and z > y or (x < y and z < y))))


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
ara = inara()
ans = 0
for i in range(1, n - 1):
	if ara[i] > ara[i - 1] and ara[i] > ara[i + 1]:
		ans += 1
	elif ara[i] < ara[i - 1] and ara[i] < ara[i + 1]:
		ans += 1
print(ans)


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


n = int(input())
numbers = list(map(int, input().split()))
result = 0
for index in range(n):
	if index > 0 and index < n - 1:
		if numbers[index] < numbers[index - 1] and numbers[index] < numbers[index + 1] or (numbers[index] > numbers[index + 1] and numbers[index] > numbers[index - 1]):
			result += 1
print(result)


n = int(input())
s = input().split()
a = []
for i in s:
	a.append(int(i))
cnt = 0
for i in range(1, n - 1):
	if a[i] > a[i - 1] and a[i] > a[i + 1]:
		cnt += 1
	elif a[i] < a[i - 1] and a[i] < a[i + 1]:
		cnt += 1
print(cnt)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
l = inlt()
c = 0
for i in range(1, n - 1):
	if l[i] > l[i - 1] and l[i] > l[i + 1] or (l[i] < l[i - 1] and l[i] < l[i + 1]):
		c = c + 1
print(c)


b = int(input())
a = [int(i) for i in input().split()]
x = 0
for i in range(1, len(a) - 1):
	if a[i] > a[i - 1] and a[i] > a[i + 1]:
		x += 1
	if a[i] < a[i - 1] and a[i] < a[i + 1]:
		x += 1
print(x)


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


n = int(input())
p = [int(x) for x in input().split()]
if n == 1 or n == 2:
	print(0)
else:
	s = 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]):
			s += 1
	print(s)


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


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


n = int(input())
m = [int(x) for x in input().strip().split()]
count = 0
for i in range(1, n - 1):
	if m[i] < m[i - 1] and m[i] < m[i + 1]:
		count += 1
	elif m[i] > m[i - 1] and m[i] > m[i + 1]:
		count += 1
print(count)


n = int(input())
k = 0
l = list(map(int, input().split()))
for i in range(1, n - 1):
	if l[i - 1] < l[i] > l[i + 1]:
		k = k + 1
	elif l[i - 1] > l[i] < l[i + 1]:
		k = k + 1
print(k)


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


import sys, os.path
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
	sys.stdout = open('out.txt', 'w')
n = int(input())
li = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
	if li[i] < li[i + 1] and li[i] < li[i - 1] or (li[i] > li[i + 1] and li[i] > li[i - 1]):
		ans += 1
print(ans)


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


i = int(input())
A = [int(x) for x in input().split()]
e = 0
for i in range(1, len(A) - 1):
	if A[i] > A[i - 1] and A[i] > A[i + 1]:
		e += 1
	elif A[i] < A[i - 1] and A[i] < A[i + 1]:
		e += 1
print(e)


a = int(input())
x = a - 1
b = input().split()
i = 1
k = 0
while i < x:
	if int(b[i]) > int(b[i + 1]) and int(b[i]) > int(b[i - 1]):
		k = k + 1
	elif int(b[i]) < int(b[i + 1]) and int(b[i]) < int(b[i - 1]):
		k = k + 1
	i = i + 1
print(k)


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


from sys import stdin, stdout
n = int(stdin.readline())
ans = 0
a = [int(i) for i in stdin.readline().split()]
for i in range(1, n - 1):
	if a[i - 1] < a[i] and a[i + 1] < a[i] or (a[i - 1] > a[i] and a[i + 1] > a[i]):
		ans += 1
stdout.write(str(ans))


n = int(input())
li = [int(k) for k in input().split()]
if n == 1 or n == 2:
	print(0)
else:
	cnt = 0
	for i in range(1, len(li) - 1):
		if li[i] > li[i - 1] and li[i] > li[i + 1]:
			cnt += 1
		elif li[i] < li[i - 1] and li[i] < li[i + 1]:
			cnt += 1
	print(cnt)


n = int(input())
a = input().split()
k = 0
for i in range(0, a.__len__()):
	a[i] = int(a[i])
for i in range(1, a.__len__() - 1):
	if a[i] < a[i + 1] and a[i] < a[i - 1] or (a[i] > a[i + 1] and a[i] > a[i - 1]):
		k += 1
print(k)


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


IL = lambda : list(map(int, input().split()))
I = lambda : int(input())
n = I()
a = IL()
print(sum([a[i] < min(a[i - 1], a[i + 1]) or a[i] > max(a[i - 1], a[i + 1]) for i in range(1, n - 1)]))


T_ON = 0
DEBUG_ON = 1
MOD = 998244353

def solve():
	n = read_int()
	A = read_ints()
	count = 0
	for i in range(1, n - 1):
		if A[i] < A[i - 1] and A[i] < A[i + 1]:
			count += 1
		elif A[i] > A[i - 1] and A[i] > A[i + 1]:
			count += 1
	print(count)

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def read_int():
	return int(input())

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

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def First():
	print('First')

def Second():
	print('Second')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def fib_to_n(n):
	f = []
	(a, b) = (0, 1)
	while a <= n:
		f.append(a)
		(a, b) = (b, a + b)
	return f

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def lcm(a, b):
	d = gcd(a, b)
	return a * b // d

def is_even(x):
	return x % 2 == 0

def is_odd(x):
	return x % 2 == 1

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P

def is_lucky(n):
	return set(list(str(n))).issubset({'4', '7'})
main()


x = int(input())
y = input().split()
z = []
k = 0
for i in range(x):
	y[i] = int(y[i])
	z.append(y[i])
for i in range(1, x - 1):
	if z[i - 1] > z[i] and z[i] < z[i + 1]:
		k = k + 1
	elif z[i - 1] < z[i] and z[i] > z[i + 1]:
		k = k + 1
print(k)


n = int(input())
ans = 0
inp = list(map(int, input().split()))
for (num, _) in enumerate(inp):
	if num == 0 or num == n - 1:
		continue
	elif inp[num] < inp[num - 1] and inp[num] < inp[num + 1] or (inp[num] > inp[num - 1] and inp[num] > inp[num + 1]):
		ans += 1
print(ans)


n = int(input())
A = [int(i) for i in input().split(' ')]
res = 0
for i in range(1, n - 1):
	res += A[i] > A[i - 1] and A[i] > A[i + 1] or (A[i] < A[i + 1] and A[i] < A[i - 1])
print(res)


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


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


n = int(input())
a = [int(a) for a in input().split()]
sum = 0
for i in range(1, len(a) - 1):
	if a[i] > a[i - 1] and a[i] > a[i + 1]:
		sum += 1
	elif a[i] < a[i - 1] and a[i] < a[i + 1]:
		sum += 1
print(sum)


amount = int(input())
array = [int(x) for x in input().split()]
counter = 0
for i in range(1, amount - 1):
	if array[i] < array[i - 1] and array[i] < array[i + 1] or (array[i] > array[i - 1] and array[i] > array[i + 1]):
		counter += 1
print(counter)


def le(v, n):
	t = 0
	for c in range(1, n - 1):
		if v[c - 1] < v[c] > v[c + 1] or v[c - 1] > v[c] < v[c + 1]:
			t += 1
	return t
n = int(input())
v = [int(c) for c in input().split()]
print(le(v, n))


x = int(input())
array = list(map(int, input().split()))
output = 0
for i in range(1, len(array) - 1):
	if array[i] < array[i + 1] and array[i] < array[i - 1] or (array[i] > array[i + 1] and array[i] > array[i - 1]):
		output += 1
print(output)


n = int(input())
a = list(map(int, input().split()))
count = sum([1 for i in range(1, n - 1) if a[i - 1] < a[i] > a[i + 1] or a[i - 1] > a[i] < a[i + 1]])
print(count)


l = int(input(''))
c = input('')
v = c.split(' ')
cont = 0
for x in range(1, l - 1):
	a = int(v[x - 1])
	s = int(v[x])
	d = int(v[x + 1])
	if a < s > d or a > s < d:
		cont += 1
print(cont)


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


n = int(input())
arr = [int(i) for i in input().split()]
ans = 0
for i in range(1, n - 1):
	ans += int(arr[i] > arr[i + 1] and arr[i] > arr[i - 1] or (arr[i] < arr[i + 1] and arr[i] < arr[i - 1]))
print(ans)


def local_extrema(arr):
	count = 0
	for i in range(1, len(arr) - 1):
		if arr[i] > arr[i - 1] and arr[i] > arr[i + 1] or (arr[i] < arr[i - 1] and arr[i] < arr[i + 1]):
			count += 1
	return count
n = int(input())
arr = list(map(int, input().split()))
print(local_extrema(arr))


n = int(input())
arr = list(map(int, input().split(' ')))
extremacount = 0

def isextrema(arr, i):
	if len(arr) == 1:
		return False
	if i == 0:
		return False
	if i == len(arr) - 1:
		return False
	(a, b, c) = arr[i - 1:i + 2]
	return b < a and b < c or (b > a and b > c)
extremacount = sum([isextrema(arr, j) for j in range(n)])
print(extremacount)


n = int(input())
it = [int(x) for x in input().split()]
c = 0
for i in range(1, n - 1):
	if it[i - 1] < it[i] and it[i + 1] < it[i]:
		c += 1
	elif it[i - 1] > it[i] and it[i + 1] > it[i]:
		c += 1
print(c)


n = int(input())
a = tuple(map(int, input().split()))
m = 0
for i in range(1, len(a) - 1):
	if a[i - 1] > a[i] < a[i + 1] or a[i - 1] < a[i] > a[i + 1]:
		m += 1
print(m)


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


n = int(input())
num = input()
num = num.split()
i = 0
while i <= n - 1:
	num[i] = int(num[i])
	i += 1
i = 1
hasel = 0
while i <= n - 2:
	if num[i] > num[i + 1] and num[i] > num[i - 1] or (num[i] < num[i + 1] and num[i] < num[i - 1]):
		hasel += 1
	i += 1
print(hasel)


n = int(input())
inputs = input().split()
numbers = []
for a in inputs:
	numbers.append(int(a))
total = 0
for i in range(1, n - 1):
	if numbers[i] < numbers[i - 1] and numbers[i] < numbers[i + 1] or (numbers[i] > numbers[i - 1] and numbers[i] > numbers[i + 1]):
		total += 1
print(total)


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


(n, a) = (int(input()), list(map(int, input().split())))
print(sum((a[i] > a[i - 1] and a[i] > a[i + 1] or (a[i] < a[i - 1] and a[i] < a[i + 1]) for i in range(1, n - 1))))


def f(l, s):
	if l[s - 1] > l[s] and l[s + 1] > l[s] or (l[s] > l[s - 1] and l[s] > l[s + 1]):
		return True
n = input()
a = input().split()
a = list(map(int, a))
s = 0
for e in range(1, len(a) - 1):
	if f(a, e):
		s = s + 1
print(s)


n = input()
nn = int(n)
array = []
array = list(map(int, input().split()))
result = 0
for j in range(1, nn - 1):
	if array[j] > array[j + 1] and array[j] > array[j - 1]:
		result += 1
	elif array[j] < array[j + 1] and array[j] < array[j - 1]:
		result += 1
print(result)


n = int(input())
nums = [int(i) for i in input().split()]
extremums = 0
for i in range(1, n - 1):
	if nums[i - 1] < nums[i] > nums[i + 1] or nums[i - 1] > nums[i] < nums[i + 1]:
		extremums += 1
print(extremums)


n = int(input())
a = [int(i) for i in input().split(' ')]
c = 0
for i in range(1, len(a) - 1):
	lma = False
	lmi = False
	if a[i] < a[i - 1] and a[i] < a[i + 1]:
		lma = True
	if a[i] > a[i - 1] and a[i] > a[i + 1]:
		lmi = True
	if (lma or lmi) and (not (lma and lmi)):
		c += 1
print(c)


a = int(input())
s = [int(c) for c in input().split()]
res = 0
for i in range(1, a - 1):
	if s[i] > s[i - 1] and s[i] > s[i + 1] or (s[i] < s[i - 1] and s[i] < s[i + 1]):
		res += 1
print(res)


c = input()
a = input()
print(sum([1 for i in range(1, int(c) - 1) if int(a.split()[i]) > max(int(a.split()[i - 1]), int(a.split()[i + 1])) or int(a.split()[i]) < min(int(a.split()[i - 1]), int(a.split()[i + 1]))]))


x = input()
x = int(x)
y = input()
y = y.split()
min1 = 0
max1 = 0
for i in range(1, x - 1):
	if int(y[i]) < int(y[i - 1]) and int(y[i]) < int(y[i + 1]):
		min1 = min1 + 1
	if int(y[i]) > int(y[i + 1]) and int(y[i]) > int(y[i - 1]):
		max1 = max1 + 1
res = min1 + max1
if x == 2 or x == 1:
	print(0)
else:
	print(res)


import sys
n = int(sys.stdin.readline())
a = sys.stdin.readline().split()
a = [int(x) for x in a]
ans = 0
for i in range(1, n - 1):
	if a[i] < a[i - 1] and a[i] < a[i + 1] or (a[i] > a[i - 1] and a[i] > a[i + 1]):
		ans += 1
print(ans)


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


import sys
n = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
	if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
		ans += 1
	elif arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
		ans += 1
print(ans)


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


def main():
	(n, res) = (int(input()), 0)
	l = list(map(int, input().split()))
	a = b = l[0]
	for c in l:
		if a > b < c or a < b > c:
			res += 1
		(a, b) = (b, c)
	print(res)
main()


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

def minmax(n, a):
	c = 0
	for i in range(1, n - 1):
		if a[i] < a[i - 1] and a[i] < a[i + 1] or (a[i] > a[i - 1] and a[i] > a[i + 1]):
			c += 1
	return c
assert minmax(3, [1, 2, 3]) == 0
assert minmax(4, [1, 5, 2, 5]) == 2
print(minmax(n, a))


n = int(input())
l = list(input().split(' '))
c = 0
for i in range(1, n - 1):
	if (int(l[i]) - int(l[i - 1])) * (int(l[i]) - int(l[i + 1])) > 0:
		c = c + 1
print(c)


x = int(input())
s = [int(n) for n in input().split()]
if x == 1:
	print(0)
else:
	l = 0
	for n in range(1, x - 1):
		if s[n - 1] < s[n] and s[n] > s[n + 1]:
			l += 1
		elif s[n - 1] > s[n] and s[n] < s[n + 1]:
			l += 1
	print(l)


input()
a = [int(i) for i in input().split(' ')]
extremas = 0
for j in range(len(a) - 2):
	if a[j + 1] > a[j] and a[j + 1] > a[j + 2] or (a[j + 1] < a[j] and a[j + 1] < a[j + 2]):
		extremas += 1
print(extremas)


n = int(input())
extr = 0
ar = [int(i) for i in input().split()]
for i in range(1, n - 1):
	if ar[i] > ar[i - 1] and ar[i] > ar[i + 1]:
		extr += 1
	elif ar[i] < ar[i - 1] and ar[i] < ar[i + 1]:
		extr += 1
print(extr)


n = int(input())
arr = input().split(' ')
arr = [int(i) for i in arr]
extr = 0
for i in range(1, n - 1):
	if arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
		extr += 1
	if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
		extr += 1
print(extr)


import sys
import math
import operator as op
from functools import reduce
from sys import maxsize

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom

def nc2(n):
	return n * (n - 1) // 2
t = 1
for i in range(t):
	n = read_int()
	a = read_int_line()
	ans = 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]):
			ans += 1
	print(ans)


from collections import Counter, defaultdict, deque
import heapq as hq
import math
import sys
input = sys.stdin.readline
n = int(input())
arr = [int(x) for x in input().split()]
total = 0
for i in range(1, n - 1):
	if arr[i - 1] < arr[i] > arr[i + 1] or arr[i - 1] > arr[i] < arr[i + 1]:
		total += 1
print(total)


n = int(input())
lst = []
for x in input().split():
	lst.append(int(x))
if n == 1:
	print(0)
elif n == 2:
	print(0)
else:
	k = 0
	for x in range(1, n - 1):
		if lst[x] > lst[x - 1] and lst[x] > lst[x + 1]:
			k += 1
		elif lst[x] < lst[x - 1] and lst[x] < lst[x + 1]:
			k += 1
	print(k)


n = int(input())
c = 0
x = [int(y) for y in input().split(' ')]
for j in range(1, n - 1):
	if x[j] < x[j - 1] and x[j] < x[j + 1] or (x[j] > x[j - 1] and x[j] > x[j + 1]):
		c = c + 1
print(c)


treasure = int(input())
s = input()
if treasure <= 2:
	print(0)
else:
	pos1 = '0'
	access = treasure - 1
	i = 0
	j = 0
	pos33 = 0
	while pos33 != -1:
		pos1 = s.find(' ')
		number1 = s[0:pos1]
		number11 = int(number1)
		s = s.replace(number1, '', 1)
		s = s.replace(' ', '', 1)
		pos2 = s.find(' ')
		number2 = s[0:pos2]
		number22 = int(number2)
		pos5 = pos2 + 1
		s2 = s[pos5:]
		pos3 = s2.find(' ')
		pos33 = int(pos3)
		if pos33 == -1:
			number3 = int(s2)
		elif pos33 != -1:
			number3 = s2[0:pos3]
		number33 = int(number3)
		if number22 < number11 and number22 < number33:
			i = i + 1
		if number22 > number11 and number22 > number33:
			i = i + 1
		if pos33 == -1:
			break
		j = j + 1
	print(i)


n = int(input())
a = [int(x) for x in input().split()]
num = 0
for i in range(1, n - 1):
	if a[i] > a[i - 1] and a[i] > a[i + 1]:
		num += 1
	elif a[i] < a[i - 1] and a[i] < a[i + 1]:
		num += 1
print(num)


n = int(input())
x = 0
s = tuple(map(int, input().split()))
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]:
		x += 1
print(x)


x = int(input())
a = [int(x) for x in input().split()]
h = 0
for i in range(1, x - 1):
	if a[i] > a[i + 1] and a[i - 1] < a[i]:
		h = h + 1
	if a[i] < a[i + 1] and a[i - 1] > a[i]:
		h = h + 1
print(h)


from sys import stdin, stdout
n = int(input())
a = [int(x) for x in input().split()]
cnt = 0
for i in range(1, n - 1, 1):
	if a[i] > a[i - 1] and a[i] > a[i + 1]:
		cnt += 1
	elif a[i] < a[i - 1] and a[i] < a[i + 1]:
		cnt += 1
print(cnt)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import Decimal
from decimal import *
from collections import defaultdict, deque
import heapq
from decimal import Decimal
getcontext().prec = 25
abcd = 'abcdefghijklmnopqrstuvwxyz'
ABCD = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
MOD = 1000000007
BUFSIZE = 8192
from bisect import bisect_left, bisect_right

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
l = list(map(int, input().split(' ')))
ans = 0
for i in range(1, n - 1):
	(a, b) = sorted((l[i - 1], l[i + 1]))
	if l[i] not in range(a, b + 1):
		ans += 1
print(ans)


input()
data = [int(x) for x in input().split()]
al = 0
for x in range(len(data)):
	if x == 0 or x == len(data) - 1:
		continue
	if data[x] < data[x + 1] and data[x] < data[x - 1] or (data[x] > data[x + 1] and data[x] > data[x - 1]):
		al += 1
print(al)


(n, xs, c) = (int(input()), [int(x) for x in input().split()], 0)
for i in range(1, len(xs) - 1):
	if xs[i] > xs[i - 1] and xs[i] > xs[i + 1]:
		c += 1
	elif xs[i] < xs[i - 1] and xs[i] < xs[i + 1]:
		c += 1
print(c)


n = int(input())
s = input()
s = s.split()
a = 1
number = 0
while a < n - 1:
	if int(s[a]) < int(s[a - 1]) and int(s[a]) < int(s[a + 1]):
		number += 1
	elif int(s[a]) > int(s[a - 1]) and int(s[a]) > int(s[a + 1]):
		number += 1
	a += 1
print(number)


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


n = int(input())
l = list(map(int, input().split()))
count = 0
i = 1
while i < len(l) - 1:
	if l[i] < l[i + 1] and l[i] < l[i - 1]:
		count = count + 1
	elif l[i] > l[i + 1] and l[i] > l[i - 1]:
		count = count + 1
	i = i + 1
print(count)


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


n = int(input())
l = list(map(int, input().split()))
ans = 0
if n < 3:
	print(ans)
else:
	for i in range(1, n - 1):
		if l[i - 1] > l[i] < l[i + 1]:
			ans += 1
	for j in range(1, n - 1):
		if l[j - 1] < l[j] > l[j + 1]:
			ans += 1
	print(ans)


var = int(input())
mango = list(map(int, input().split()))
count = 0
for i in range(1, var - 1):
	if mango[i] > mango[i + 1] and mango[i] > mango[i - 1]:
		count = count + 1
	elif mango[i] < mango[i + 1] and mango[i] < mango[i - 1]:
		count = count + 1
print(count)


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


n = int(input())
a = list(map(int, input().split()))
result = 0
if n <= 2:
	print(0)
else:
	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]:
			result += 1
	print(result)


n = int(input())
a = [int(elem) for elem in input().split()]
s = 0
for i in range(1, n - 1):
	if a[i] > a[i + 1] and a[i] > a[i - 1] or (a[i] < a[i + 1] and a[i] < a[i - 1]):
		s += 1
print(s)


z = int(input())
x = list(map(int, input().split()))
k = 0
if z == 1 or z == 2:
	print(k)
else:
	for i in range(1, z - 1):
		if x[i - 1] < x[i] and x[i + 1] < x[i] or (x[i - 1] > x[i] and x[i + 1] > x[i]):
			k += 1
	print(k)


import sys

def main():
	n = sys.stdin.readline()[:-1].split()
	args = sys.stdin.readline()[:-1].split()
	array = list(map(int, args))
	count = 0
	for i in range(1, len(array) - 1):
		if array[i] > array[i - 1] and array[i] > array[i + 1] or (array[i] < array[i - 1] and array[i] < array[i + 1]):
			count += 1
	print(count)
main()


n = int(input())
b = 0
a = list(map(int, input().split()))
for i in range(1, len(a) - 1):
	if n < 3:
		break
	elif a[i] < a[i - 1] and a[i] < a[i + 1] or (a[i] > a[i - 1] and a[i] > a[i + 1]):
		b = b + 1
print(b)


n = int(input())
a = [int(z) for z in input().split()]
cnt = 0
for i in range(1, n - 1):
	if a[i - 1] < a[i] and a[i + 1] < a[i]:
		cnt += 1
	if a[i - 1] > a[i] and a[i + 1] > a[i]:
		cnt += 1
print(cnt)


n = int(input())
arr = list(map(int, input().split()))
if n > 2:
	count = 0
	i = 1
	while i < n - 1:
		if arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
			count += 1
		elif arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
			count += 1
		i += 1
	print(count)
else:
	print(0)


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


input()
n = [int(x) for x in input().split()]
total = 0
for (a, b, c) in zip(n, n[1:], n[2:]):
	total += a > b < c or a < b > c
print(total)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
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
	if l[i] < l[i - 1] and l[i] < l[i + 1]:
		ans += 1
print(ans)


def list_output(s):
	print(' '.join(map(str, s)))

def list_input():
	return list(map(int, input().split()))
n = int(input())
a = list_input()
res = 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]):
		res += 1
print(res)


result = 0
n = int(input())
tab = [int(x) for x in input().split()]
for i in range(1, n - 1):
	result += 1 if tab[i] > tab[i - 1] and tab[i] > tab[i + 1] or (tab[i] < tab[i - 1] and tab[i] < tab[i + 1]) else 0
print(result)


p = input()
li = [int(x) for x in input().split()]
cnt = 0
for i in range(1, len(li) - 1):
	if li[i + 1] > li[i] and li[i - 1] > li[i]:
		cnt += 1
	elif li[i + 1] < li[i] and li[i - 1] < li[i]:
		cnt += 1
print(cnt)


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


n = int(input().strip())
arr = [int(__) for __ in input().strip().split()]
if n <= 2:
	print(0)
else:
	ans = 0
	for i in range(1, n - 1):
		if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
			ans += 1
		elif arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
			ans += 1
	print(ans)


n = int(input())
a = [int(x) for x in input().split()]
print(sum([1 if a[i] > a[i + 1] and a[i] > a[i - 1] or (a[i] < a[i + 1] and a[i] < a[i - 1]) else 0 for i in range(1, n - 1)]))


n = int(input())
kolvo = 0
A = [int(x) for x in input().split()]
for i in range(1, n - 1):
	if A[i] < A[i - 1] and A[i] < A[i + 1] or (A[i] > A[i - 1] and A[i] > A[i + 1]):
		kolvo += 1
print(kolvo)


def solution(l1):
	if len(l1) < 3:
		return 0
	i = 1
	ans = 0
	while i < len(l1) - 1:
		if l1[i - 1] < l1[i] and l1[i] > l1[i + 1] or (l1[i - 1] > l1[i] and l1[i + 1] > l1[i]):
			ans += 1
		i += 1
	return ans

def answer():
	n = int(input())
	l1 = [int(x) for x in input().split()]
	print(solution(l1))
answer()


n = int(input().strip())
ta = input().strip().split(' ')
a = list()
for num in ta:
	a.append(int(num))
ext = 0
for i in range(1, n - 1):
	if a[i] > a[i - 1] and a[i] > a[i + 1]:
		ext += 1
	elif a[i] < a[i - 1] and a[i] < a[i + 1]:
		ext += 1
print(ext)


def extreme(n, a):
	n = int(n)
	ex = 0
	aa = []
	a = a + ' '
	for i in range(0, n):
		if a.find(' ') > 0:
			aa.append(int(a[:a.find(' ')]))
			a = a[a.find(' ') + 1:]
	for i in range(1, n - 1):
		if aa[i] > aa[i - 1] and aa[i] > aa[i + 1] or (aa[i] < aa[i - 1] and aa[i] < aa[i + 1]):
			ex = ex + 1
	print(ex)
extreme(input(), input())


n = int(input())
a = [i for i in map(int, input().split())]
(i, ans) = (1, 0)
while i < n - 1:
	if (a[i] - a[i - 1]) * (a[i] - a[i + 1]) > 0:
		ans += 1
	i += 1
print(ans)


n = int(input())
a = input().split(' ')
f = 0
c = 0
i = 1
while i < n - 1:
	if int(a[i - 1]) > int(a[i]) < int(a[i + 1]):
		c += 1
	if int(a[i - 1]) < int(a[i]) > int(a[i + 1]):
		c += 1
	i += 1
print(c)


n = int(input())
l = [int(x) for x in input().split()]
cnt = 0
for i in range(1, n - 1):
	if l[i] > l[i - 1] and l[i] > l[i + 1] or (l[i] < l[i - 1] and l[i] < l[i + 1]):
		cnt += 1
print(cnt)


from sys import stdin
n = int(input())
nums = list(map(int, input().split()))
count = 0
for i in range(1, n - 1):
	if nums[i] > nums[i - 1] and nums[i] > nums[i + 1]:
		count += 1
	elif nums[i] < nums[i - 1] and nums[i] < nums[i + 1]:
		count += 1
print(count)


n = int(input())
line = list(input().split(' '))
line = [int(i) for i in line]
s = 0
for i in range(1, n - 1):
	if line[i - 1] < line[i] > line[i + 1]:
		s += 1
	elif line[i - 1] > line[i] < line[i + 1]:
		s += 1
print(s)


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


n = int(input())
a = list(map(int, input().split()))
if n < 3:
	print(0)
else:
	cnt = 0
	i = 1
	while i < n - 1:
		if a[i] > a[i - 1] and a[i] > a[i + 1] or (a[i] < a[i - 1] and a[i] < a[i + 1]):
			cnt += 1
		i += 1
	print(cnt)


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


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


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


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


n = int(input())
a = [int(x) for x in input().split(' ')]
c = 0
for i in range(n - 2):
	if a[i] > a[i + 1] and a[i + 2] > a[i + 1] or (a[i] < a[i + 1] and a[i + 2] < a[i + 1]):
		c += 1
print(c)


from sys import stdin, stdout
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
	if a[i] > a[i - 1] and a[i] > a[i + 1]:
		ans += 1
	elif a[i] < a[i - 1] and a[i] < a[i + 1]:
		ans += 1
print(ans)


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


n = input()
a = input().split()
i = 1
result = 0
while i < int(n) - 1:
	if int(a[i - 1]) > int(a[i]) and int(a[i]) < int(a[i + 1]):
		result += 1
	elif int(a[i - 1]) < int(a[i]) and int(a[i + 1]) < int(a[i]):
		result += 1
	i += 1
print(result)


n = int(input())
a = [int(x) for x in input().split()]
res = 0
for i in range(1, len(a) - 1):
	if a[i - 1] < a[i] > a[i + 1] or a[i - 1] > a[i] < a[i + 1]:
		res += 1
print(res)


a = int(input())
l = [int(i) for i in input().split()]
ans = 0
for i in range(1, a - 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)


n = int(input())
a = list(map(int, input().split()))
count = 0
i = 1
while i <= n - 2:
	if a[i] < a[i - 1] and a[i] < a[i + 1] or (a[i] > a[i - 1] and a[i] > a[i + 1]):
		count += 1
	i += 1
print(count)


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


n = int(input())
ai = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
	ans += not (ai[i - 1] > ai[i]) ^ (ai[i + 1] > ai[i]) and ai[i - 1] != ai[i] and (ai[i + 1] != ai[i])
print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

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 pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		r = 0
		for (b, c, d) in zip(a, a[1:], a[2:]):
			if b < c and c > d or (b > c and c < d):
				r += 1
		rr.append(r)
	return JA(rr, '\n')
print(main())


a = int(input())
Message = input()
b = []
b = Message.split(' ')
s = 0
for i in range(a):
	b[i] = int(b[i])
for i in range(1, len(b) - 1):
	if b[i] < b[i - 1] and b[i] < b[i + 1]:
		s += 1
	elif b[i] > b[i - 1] and b[i] > b[i + 1]:
		s += 1
print(s)


n = int(input())
a = list(map(int, input().split()))
f = lambda i: 0 < (a[i] - a[i - 1]) * (a[i] - a[i + 1])
print(len(list(filter(f, range(1, n - 1)))))


n = int(input())
a = [int(i) for i in input().split()]
ex = []
for i in range(1, n - 1):
	if a[i] > a[i - 1] and a[i] > a[i + 1]:
		ex += [a[i]]
	elif a[i] < a[i - 1] and a[i] < a[i + 1]:
		ex += [a[i]]
print(len(ex))


n = int(input())
l = []
i = 0
s = input().split()
while i < n:
	l.append(int(s[i]))
	i += 1
i = 1
out = 0
while i < n - 1:
	if l[i] > l[i - 1] and l[i] > l[i + 1]:
		out += 1
	if l[i] < l[i - 1] and l[i] < l[i + 1]:
		out += 1
	i += 1
print(out)


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


import sys
input = sys.stdin.readline
from math import *

def inp():
	return int(input().strip())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
li = inlt()
cnt = 0
for i in range(1, n - 1):
	if li[i] < li[i - 1] and li[i] < li[i + 1]:
		cnt += 1
	elif li[i] > li[i - 1] and li[i] > li[i + 1]:
		cnt += 1
print(cnt)


def is_extrema(a, i):
	return a[i - 1] < a[i] > a[i + 1] or a[i - 1] > a[i] < a[i + 1]
_ = input()
arr = [int(x) for x in input().split(' ')]
num_extrema = 0
for i in range(1, len(arr) - 1):
	if is_extrema(arr, i):
		num_extrema += 1
print(num_extrema)


n = int(input())
f = [int(i) for i in input().split()]
gh = 0
b = 0
t = 0
for i in range(1, n - 1):
	b = f[i + 1]
	gh = f[i - 1]
	if gh > f[i] < b or gh < f[i] > b:
		t = t + 1
print(t)


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


n = input()
arr = list(map(int, input().split(' ')))
count = 0
for x in range(1, len(arr) - 1):
	if arr[x] > arr[x - 1] and arr[x] > arr[x + 1]:
		count += 1
	if arr[x] < arr[x - 1] and arr[x] < arr[x + 1]:
		count += 1
print(count)


num = input()
arr = [int(i) for i in input().split(' ')]
count = 0
for j in range(len(arr) - 2):
	i = j + 1
	if (arr[i - 1] - arr[i]) * (arr[i + 1] - arr[i]) > 0:
		count += 1
print(count)


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


def extreme(arr):
	ans = 0
	for i in range(1, len(arr) - 1):
		if arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
			ans += 1
		elif arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
			ans += 1
	return ans
n = int(input())
arr = list(map(int, input().split()))
print(extreme(arr))


n = int(input())
A = list(map(int, input().split()))
cpt = sum((int(A[i - 1] > A[i] < A[i + 1] or A[i - 1] < A[i] > A[i + 1]) for i in range(1, n - 1)))
print(cpt)


_ = input()
a = [int(i) for i in input().split(' ')]
count = 0
for i in range(1, len(a) - 1):
	if a[i] > a[i - 1] and a[i] > a[i + 1]:
		count += 1
	elif a[i] < a[i - 1] and a[i] < a[i + 1]:
		count += 1
print(count)


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


n = int(input())
if n < 3:
	print(0)
else:
	x = [int(i) for i in input().split()]
	t = 0
	a = x[0]
	b = x[1]
	c = x[2]
	if b > a and b > c or (b < a and b < c):
		t = t + 1
	a = b
	b = c
	for i in range(3, n):
		c = x[i]
		if b > a and b > c or (b < c and b < a):
			t = t + 1
		a = b
		b = c
	print(t)


number = int(input())
num = 0
lst = [int(i) for i in input().split()][:number]
for i in range(len(lst)):
	if not (i == 0 or i == len(lst) - 1) and (lst[i] > lst[i - 1] and lst[i] > lst[i + 1] or (lst[i] < lst[i - 1] and lst[i] < lst[i + 1])):
		num += 1
print(num)


n = int(input())
array = [int(i) for i in input().split()]
counter = 0
for i in range(1, n - 1):
	counter += (array[i - 1] > array[i] and array[i + 1] > array[i]) + (array[i - 1] < array[i] and array[i + 1] < array[i])
print(counter)


import sys
n = int(input())
array = [int(i) for i in input().split(' ')]
counter = 0
for i in range(1, len(array) - 1):
	if array[i - 1] < array[i] and array[i] > array[i + 1]:
		counter += 1
	if array[i - 1] > array[i] and array[i] < array[i + 1]:
		counter += 1
print(counter)


def main():
	read = lambda : tuple(map(int, input().split()))
	n = read()[0]
	a = read()
	k = 0
	for i in range(1, n - 1):
		(l, c, r) = (a[i - 1], a[i], a[i + 1])
		if c > l and c > r or (c < l and c < r):
			k += 1
	print(k)
main()


n = int(input())
L = [int(x) for x in input().split()]
if n <= 2:
	print(0)
else:
	s = 0
	for i in range(1, n - 1):
		if (L[i + 1] - L[i]) * (L[i - 1] - L[i]) > 0:
			s += 1
	print(s)


input()
k = list(input().split())
k = list(map(lambda x: int(x), k))
count = 0
for i in range(1, len(k) - 1):
	j = k[i]
	if k[i] > k[i - 1] and k[i] > k[i + 1]:
		count = count + 1
	if k[i] < k[i - 1] and k[i] < k[i + 1]:
		count = count + 1
print(count)


n = int(input())
l = [int(x) for x in 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)


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


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


n = int(input())
s = input().split()
for i in range(len(s)):
	s[i] = int(s[i])
ret = 0
for i in range(1, len(s) - 1):
	if s[i] < s[i - 1] and s[i] < s[i + 1] or (s[i] > s[i - 1] and s[i] > s[i + 1]):
		ret += 1
print(ret)


n = int(input())
a = [int(i) for i in input().split()]
if n < 2:
	print(0)
else:
	ans = 0
	for i in range(1, n - 1):
		if a[i - 1] > a[i] < a[i + 1]:
			ans += 1
		elif a[i - 1] < a[i] > a[i + 1]:
			ans += 1
	print(ans)


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


n = int(input())
a = map(int, input().split())
a = list(a)
(l, r) = (0, 2)
ans = 0
while r < n:
	if a[l + 1] < a[l] and a[l + 1] < a[r] or (a[l + 1] > a[l] and a[l + 1] > a[r]):
		ans += 1
	l += 1
	r += 1
print(ans)


import sys
n = int(sys.stdin.readline())
ls = sys.stdin.readline().split(' ')
arr = list(map(int, ls))
count = 0
for i in range(n):
	if i == 0 or i == n - 1:
		count += 0
	elif arr[i] > arr[i - 1] and arr[i] > arr[i + 1] or (arr[i] < arr[i - 1] and arr[i] < arr[i + 1]):
		count += 1
print(count)


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


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
n = ii()
a = li()
ans = 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]):
		ans += 1
print(ans)


def localextrema(arr1):
	n = len(arr1)
	count = 0
	for i in range(1, n - 1):
		if arr1[i] < arr1[i - 1] and arr1[i] < arr1[i + 1] or (arr1[i] > arr1[i - 1] and arr1[i] > arr1[i + 1]):
			count += 1
	return count
n = int(input())
arr1 = list(map(int, input().split()))
print(localextrema(arr1))