def 🎍(a,b,c) a != c && ((a < b && b > c) || (a > b && b < c)) end n = gets.to_i arr = gets.split.map(&:to_i) not_kado_idxs = arr.each_cons(3).each_with_index.map{|a,i| 🎍(*a) ? nil : i}.compact if not_kado_idxs.size > 20 puts 'No' end ok = false n.times do |i| not_kado_idxs.each do |ji| 3.times do |jj| j = ji+jj next if i == j arr[i], arr[j] = arr[j], arr[i] ok ||= arr.each_cons(3).all?{|a| 🎍(*a)} arr[i], arr[j] = arr[j], arr[i] end end end puts ok ? 'Yes' : 'No'