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_accessor :t, :b, :n, :e, :s, :w
	def initialize(*labels)
		@t = labels[0]
		@s = labels[1]
		@e = labels[2]
		@w = labels[3]
		@n = labels[4]
		@b = labels[5]
	end
	def roll(dir)
		case dir
		when 'N'
			@t, @s, @b, @n = @s, @b, @n, @t
		when 'S'
			@s, @b, @n, @t = @t, @s, @b, @n
		when 'W'
			@t, @e, @b, @w = @e, @b, @w, @t
		when 'E'
			@e, @b, @w, @t = @t, @e, @b, @w
		end
	end
	def ==(other)
		dice1 = dup
		dice2 = other.dup
		dirs = "EEEENEEEENEEEENEEENEEEENNEEEE"
		found = false
		dirs.chars{|d|
			if dice1.t == dice2.t && dice1.s == dice2.s && dice1.e == dice2.e && dice1.w == dice2.w && dice1.n == dice2.n && dice1.b == dice2.b
				found = true
				break
			else
				dice2.roll d
			end
		}
		found
	end
end

dice1 = Dice.new(*gets.split)
dice2 = Dice.new(*gets.split)
puts dice1 == dice2 ? "Yes" : "No"