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
	def initialize(labels)
		@labels = labels
		@top    = labels[0]
		@front  = labels[1]
		@right  = labels[2]
		@left   = labels[3]
		@back   = labels[4]
		@bottom = labels[5]
	end
	attr_reader :top, :front, :right, :left, :back, :bottom

	def roll(op)
		case op
		when "E"
			@t      = @top
			@top    = @left
			@left   = @bottom
			@bottom = @right
			@right  = @t
		when "W"
			@t      = @top
			@top    = @right
			@right  = @bottom
			@bottom = @left
			@left   = @t
		when "N"
			@t      = @top
			@top    = @front
			@front  = @bottom
			@bottom = @back
			@back   = @t
		when "S"
			@t      = @top
			@top    = @back
			@back   = @bottom
			@bottom = @front
			@front  = @t
		when "R" # Roll around front and back
			@f      = @front
			@front  = @left
			@left   = @back
			@back   = @right
			@right  = @f 
		end
	end

	def same?(dice2)
		if dice2.top == @top && dice2.left == @left && dice2.front == @front &&
		   dice2.right == @right && dice2.back == @back && dice2.bottom == @bottom 
		   return true
		else
		   return false
		end
	end
end

def same_rolled?(dice1, dice2)
	for i in 0..3
		i.times{dice1.roll("E")}
		for j in 0..3
			j.times{dice1.roll("N")}
			for k in 0..3
				k.times{dice1.roll("W")}
				for l in 0..3
					l.times{dice1.roll("S")}
					return true if dice1.same?(dice2)
				end
			end
		end
	end
	return false
end


labels = gets.strip.split(" ").map{|i| i.to_i}
dice1 = Dice.new(labels)
labels = gets.strip.split(" ").map{|i| i.to_i}
dice2 = Dice.new(labels)

puts same_rolled?(dice1, dice2)