def comp(gen,n)
    ht0=Hash.new
    gen[0].each{|key,value|
       str=""
       value.each{|v|
          str+=v.to_s
       }
       ht0.store(key,str+str)
    }
    for i in 1..n-1 do
       ht=Hash.new
       gen[i].each_key{|key|
           if gen[0].has_key?(key)==false then
              return false
           end
           arr=gen[i][key]
           str=""
           arr.each do |v|
              str+=v.to_s
           end
           ht.store(key,str)
       }
       ht.each{|key,value|
          if ht0[key].include?(value)==false then
             return false
          end
       }
    end
    return true
end

def generate(src,lbl)
     gen=Hash.new
     src.each{|key,arr|
       r=Array.new
       arr.each_with_index{|v,i|
         r.push(lbl[v[i]])
       }
       gen.store(lbl[key],r)
     }
     return gen
end

src={1=>[2,3,5,4],
     2=>[1,4,6,3],
     3=>[1,2,6,5],
     4=>[2,1,5,6],
     5=>[3,6,4,1],
     6=>[2,4,5,3]}

gen=Hash.new
for p in 0..1 do
    lbl=Hash.new
    mp=gets.split(' ').map(&:to_i)
    mp.each_with_index {|x,i|
       lbl.store(i+1,x)
    }
    gen.store(p,generate(src,lbl))
end
if comp(gen,2) == true then
    puts "Yes"
else
    puts "No"
end