def 🎍(a,b,c) a != c && ((a < b && b > c) || (a > b && b < c)) end line1 = gets.chomp! line2 = gets.chomp! abort unless !gets abort unless line1 =~ /^[1-9] [1-9] [1-9]$/ abort unless line2 =~ /^[1-9] [1-9] [1-9]$/ aa = line1.split.map(&:to_i) bb = line2.split.map(&:to_i) puts (3.times.to_a.repeated_permutation(2).find do |i, j| # a, b = aa.clone, bb.clone a, b = aa, bb a[i], b[j] = b[j], a[i] 🎍(*a) && 🎍(*b) end) ? 'Yes' : 'No'