n=gets.to_i as=gets.split.map &:to_i count=0 (n-2).times do |n| three=[as[n], as[n+1], as[n+2]] second=three.sort[1] next unless second!=three[1] next unless three==three.uniq count+=1 end p count