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(n=Array.new(6,0))
		@num = n
		@LRRoll = [:u, :b, :d, :f]
		@FBRoll = [:u, :l, :d, :r]
		@UDRoll = [:r, :b, :l, :f]
		reset
	end

	def reset
		@position = { u: @num[0],
									d: @num[5],
									r: @num[2],
									l: @num[3],
									f: @num[4],
									b: @num[1]
		}
	end

	def move(v)
		case v
		when "N"
			Roll(@LRRoll)
		when "S"
			Roll(@LRRoll, -1)
		when "E"
			Roll(@FBRoll)
		when "W"
			Roll(@FBRoll, -1)
		end
	end

	def move_roll(n)
		n.times { Roll(@UDRoll) }
	end

	def Roll(roll, v=1)
		v = -1 if v != 1
		t = @position[roll[0]]
		@position[roll[  0]] = @position[roll[1*v]]
		@position[roll[1*v]] = @position[roll[2*v]]
		@position[roll[2*v]] = @position[roll[3*v]]
		@position[roll[3*v]] = t
	end

	def v_up
		@position[:u]
	end

	def v_down
		@position[:d]
	end

	def v_foward
		@position[:f]
	end

	def v_back
		@position[:b]
	end

	def v_right
		@position[:r]
	end

	def v_left
		@position[:l]
	end

end

n1 = gets.chomp.split(" ").map &:to_i
d1 = Dice.new(n1)
n2 = gets.chomp.split(" ").map &:to_i
d2 = Dice.new(n2)

same = true

2.times {
	break if d1.v_up == d2.v_up and d1.v_down == d2.v_down
	d2.move("E")
}

2.times {
	break if d1.v_up == d2.v_up and d1.v_down == d2.v_down
	d2.move("N")
}

same = false if d1.v_down != d2.v_down

if same
	case d1.v_back
	when d2.v_left
		d2.move_roll(1)
	when d2.v_foward
		d2.move_roll(2)
	when d2.v_right
		d2.move_roll(3)
	end
end

if same
	same = false if not  (d1.v_foward == d2.v_foward and
												d1.v_right  == d2.v_right  and
										 		d1.v_left   == d2.v_left)
end

if same
	print("Yes\n")
else
	print("No\n")
end