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) ok = false (0...n).to_a.combination(2) do |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 puts ok ? 'Yes' : 'No'