def kadomatsu?(arr) arr.uniq == arr and arr.minmax.any?(arr[1]) end a = gets.split.map(&:to_i) b = gets.split.map(&:to_i) 3.times do |i| 3.times do |j| a[i], b[j] = b[j], a[i] if kadomatsu?(a) and kadomatsu?(b) puts "Yes" exit end a[i], b[j] = b[j], a[i] end end puts "No"