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: Accepted)

#!/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 changetop(dice,i)
    case i
    when 0 
        return dice
    when 1 
        return rotate(dice,"N")
    when 2
        return rotate(dice,"W")
    when 3
        return rotate(dice,"E")
    when 4
        return rotate(dice,"S")
    when 5
        return rotate(rotate(dice,"N"),"N")
    end
end


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

tempdice = []
6.times do |index|
    tempdice = changetop(diceB,index)
    if tempdice == diceA then
        puts "Yes"
        exit
    end
    3.times do 
        tempdice = rotate(tempdice,"Z")
        if tempdice == diceA then
            puts "Yes"
            exit
        end
    end
end
puts "No"