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)


class Dice 
    attr_reader :nums
    def initialize(nums)
        @nums = [nil] + nums
    end
    def top
        @nums[1]
    end
    def front
        @nums[2]
    end
    def right
        @nums[3]
    end
    def rollx
        @nums[1], @nums[2], @nums[6], @nums[5] = @nums[5], @nums[1], @nums[2], @nums[6]
        self
    end
    def rolly
        @nums[1], @nums[3], @nums[6], @nums[4] = @nums[4], @nums[1], @nums[3], @nums[6]
        self
    end
    def rollz
        @nums[2], @nums[3], @nums[5], @nums[4] = @nums[4], @nums[2], @nums[3], @nums[5]
        self
    end
    def moveN
        rollx.rollx.rollx
    end
    def moveS
        rollx
    end
    def moveE
        rolly
    end
    def moveW
        rolly.rolly.rolly
    end
    def move(m)
        case m
        when 'N' then moveN
        when 'S' then moveS
        when 'E' then moveE
        when 'W' then moveW
        end
    end
    def move_all
        moves = [
            # top:1 front:2
            :y, :rollz, :y, :rollz, :y, :rollz, :y, :rollz, :moveN,
            # top:2 front:6
            :y, :rollz, :y, :rollz, :y, :rollz, :y, :rollz, :moveW,
            # top:3 front:6
            :y, :rollz, :y, :rollz, :y, :rollz, :y, :rollz, :moveW,
            # top:5 front:6
            :y, :rollz, :y, :rollz, :y, :rollz, :y, :rollz, :moveW,
            # top:4 front:6
            :y, :rollz, :y, :rollz, :y, :rollz, :y, :rollz, :moveN,
            # top:6 front:3
            :y, :rollz, :y, :rollz, :y, :rollz, :y, :rollz,
        ]
        moves.each do |m|
            if m == :y
                yield self
            else
                self.send(m)
            end
        end
    end
end

nums1 = STDIN.gets.split.map(&:to_i)
nums2 = STDIN.gets.split.map(&:to_i)

dice1 = Dice.new(nums1)
dice2 = Dice.new(nums2)

results = []
dice1.move_all do |d|
    if d.nums == dice2.nums
        puts "Yes"
        exit
    end
end

puts "No"