A = gets.split.map(&:to_i) B = gets.split.map(&:to_i) def f(a) return false if a.uniq.size < 3 return true if a[0] > a[1] && a[1] < a[2] return true if a[0] < a[1] && a[1] > a[2] false end 3.times do |i| 3.times do |j| A[i], B[j] = B[j], A[i] if f(A) && f(B) puts 'Yes' exit end A[i], B[j] = B[j], A[i] end end puts 'No'