def kadomatsu a if a.uniq.size == 3 && (a[1] == a.max || a[1] == a.min) return true else return false end end ans = 0 n = gets.to_i s = gets.split.map(&:to_i) (n - 2).times{|i| if kadomatsu([s[i],s[i + 1],s[i + 2]]) ans += 1 end } p ans