def kadomatsu?(abc) abc.uniq.size == 3 && abc[1] != abc.sort[1] end N = gets.to_i A = gets.split.map(&:to_i) puts A.each_cons(3).count{|abc| kadomatsu?(abc) }