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

Starter code:

Solutions:
'''input
4
1 5 2 5
'''
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)

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


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


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)


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

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


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


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)

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

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

ans = 0
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
print(ans)


n = int(input())

nums = list(map(int,input().strip().split(' ')))

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

print(ans)

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

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

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

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)


# ecr32a

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

locex = 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]):
        locex += 1

print(locex)



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

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

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

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

print(ans)


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)


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