n = gets.chop.to_i
p = gets.chop.split.map(&:to_i)

count = 0
for i in 0..n-3
  sort_array = []
  sort_array << p[i]
  sort_array << p[i+1]
  sort_array << p[i+2]
  sort_array.sort!

  if sort_array[1] == p[i+1]
    count += 1
  end
end

puts count