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)

class Dice
    @numbers = []

    def initialize numbers
        @numbers = numbers
    end

    def roll direction
        old = @numbers.dup
        case direction
        when "N"
            @numbers[0] = old[1]
            @numbers[1] = old[5] 
            @numbers[5] = old[4]
            @numbers[4] = old[0]
            @numbers[2] = old[2]
            @numbers[3] = old[3]
        when "E"
            @numbers[3] = old[5]
            @numbers[0] = old[3] 
            @numbers[2] = old[0]
            @numbers[5] = old[2]
            @numbers[1] = old[1]
            @numbers[4] = old[4]
        when "S"
            @numbers[0] = old[4]
            @numbers[1] = old[0] 
            @numbers[5] = old[1]
            @numbers[4] = old[5]
            @numbers[2] = old[2]
            @numbers[3] = old[3]
        when "W"
            @numbers[3] = old[0]
            @numbers[0] = old[2] 
            @numbers[2] = old[5]
            @numbers[5] = old[3]
            @numbers[1] = old[1]
            @numbers[4] = old[4]
        end
    end

    def top
        @numbers[0]
    end
    
    def right t, f
        case @numbers.index(f)
        when 0 then roll "S"
        when 2 then roll "W"; roll "S"
        when 3 then roll "E"; roll "S"
        when 4 then roll "S"; roll "S"
        when 5 then roll "N"
        end

        case @numbers.index(t)
        when 0 then #pass
        when 2 then roll "W"
        when 3 then roll "E"
        when 5 then roll "E"; roll "E"
        else return nil
        end

        @numbers[2]
    end
end

numbers1 = gets.chomp.split.map(&:to_i)
dice1 = Dice.new(numbers1)
numbers2 = gets.chomp.split.map(&:to_i)
dice2 = Dice.new(numbers2)

result = "No"
if (numbers1.sort == numbers2.sort) && (dice1.right(numbers1[0], numbers1[1]) == dice2.right(numbers1[0], numbers1[1]))
    dice1.roll "S"; dice2.roll "S"
    if dice1.top == dice2.top
        dice1.roll "S"; dice2.roll "S"
            if dice1.top == dice2.top
            dice1.roll "E"; dice2.roll "E"
            if dice1.top == dice2.top
                result = "Yes"
            end
        end
    end
end
puts result