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)

#!/usr/bin/env ruby

def rotate(dice,direction)
    case direction
    when "N"
        return [dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]]
    when "E"
        return [dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]]
    when "W"
        return [dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]]
    when "S"
        return [dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]]
    when "Z"
        return [dice[0],dice[2],dice[4],dice[1],dice[3],dice[5]]
    end
end

def make_same_top(diceA,diceB)
    case diceA[0]
    when diceB[0]
        return diceB
    when diceB[1]
        return rotate(diceB,"N")
    when diceB[2]
        return rotate(diceB,"W")
    when diceB[3]
        return rotate(diceB,"E")
    when diceB[4]
        return rotate(diceB,"S")
    when diceB[5]
        return rotate(rotate(diceB,"N"),"N")
    end
end

diceA = gets.split.map(&:to_i)
diceB = gets.split.map(&:to_i)

diceB = make_same_top(diceA,diceB)
3.times do
    if diceA == diceB then 
        puts "Yes"
        break
    else
        diceB = rotate(diceB,"Z")
    end
end
diceB = rotate(diceB,"N")
3.times do
    if diceA == diceB then 
        puts "Yes"
        break
    else
        diceB = rotate(diceB,"Z")
    end
end
diceB = rotate(diceB,"N")
3.times do
    if diceA == diceB then 
        puts "Yes"
        break
    else
        diceB = rotate(diceB,"Z")
    end
end
puts "No" if diceA != diceB