Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Dice III

Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.

Input

In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels.

In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.

Output

Print "Yes" if two dices are identical, otherwise "No" in a line.

Constraints

$0 \leq $ the integer assigned to a face $ \leq 100$

Sample Input 1

1 2 3 4 5 6
6 2 4 3 5 1

Sample Output 1

Yes

Sample Input 2

1 2 3 4 5 6
6 5 4 3 2 1

Sample Output 2

No

Solution in Ruby (judge verdict: Wrong Answer)

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