def f(a) a.uniq.size == 3 && (a.min == a[1] || a.max == a[1]) end a, b = $<.map { _1.split.map &:to_i } puts (0..2).to_a.product((0..2).to_a).any? { |i, j| x, y = a.dup, b.dup x[i], y[j] = y[j], x[i] f(x) && f(y) } ? "Yes" : "No"