def is_kadomatsu? (a, b, c) if a == b || b == c || c == a return false end tmp = [a, b, c] return b == tmp.max || b == tmp.min end gets arr = gets.chomp.split.map{|str| str.to_i} count = 0 2.upto(arr.length - 1) {|idx| if is_kadomatsu?(arr[idx - 2], arr[idx - 1], arr[idx]) count += 1 end } puts count