class Calc0116 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @n = args.shift.first.to_i @as = args.shift.map(&:to_i) end def run (1..(@n - 2)).count { |i| as = @as[(i - 1)..(i + 1)] as.uniq.size == as.size && [0, 2].include?(as.index(as.sort[1])) } end end puts Calc0116.new(STDIN.readlines).run if __FILE__ == $0