# frozen_string_literal: true def swap(a, b) [A.dup.tap { _1[a] = B[b] }, B.dup.tap { _1[b] = A[a] }] end def kadomatsu?(seq) seq.uniq.size == seq.size && (seq.max == seq[1] || seq.min == seq[1]) end def solve 3.times.each do |a| 3.times.each do |b| return 'Yes' if swap(a, b).all? { kadomatsu? _1 } end end 'No' end A = gets.chomp.split.map { _1.to_i } B = gets.chomp.split.map { _1.to_i } puts solve