class A def initialize n = gets.chomp.to_i a = gets.chomp.split(' ').map(&:to_i) count = 0 a.each_cons(3) do |list| next if list.uniq.size != list.size if list.max == list[1] || list.min == list[1] count += 1 end end puts count end end A.new