class Array def kadomatsu? return nil unless size == 3 return false unless uniq.size == 3 self[1] == min || self[1] == max end end a = gets.to_s.split.map{ |e| e.to_i } b = gets.to_s.split.map{ |e| e.to_i } [0, 1, 2].product([0, 1, 2]) do |i, j| c = a.dup d = b.dup c[i], d[j] = d[j], c[i] if c.kadomatsu? && d.kadomatsu? puts "Yes" exit end end puts "No"