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 :top, :front, :right, :left, :back, :bottom
  def initialize a,b,c,d,e,f
    @top = a; @front = b; @right = c; @left = d; @back = e; @bottom = f
  end
  def == other
    other.top == @top && other.front == @front && other.right == @right \
    && other.left == @left && other.back == @back && other.bottom == @bottom
  end
  def rotN
    t = @top; @top = @front; @front = @bottom; @bottom = @back; @back = t; self
  end
  def rotE
    t = @top; @top = @left; @left = @bottom; @bottom = @right; @right = t; self
  end
  def rotW
    t = @top; @top = @right; @right = @bottom; @bottom = @left; @left = t; self
  end
  def rotS
    t = @top; @top = @back; @back = @bottom; @bottom = @front; @front = t; self
  end
  def rotV
    t = @front; @front = @left; @left = @back; @back = @right; @right = t; self
  end
  def show
#    printf("%d %d %d %d %d %d\n",@top,@front,@right,@left,@back,@bottom)
  end
end

a,b,c,d,e,f = gets.split.map {|s| s.to_i}
die1 = Dice.new(a,b,c,d,e,f)
a,b,c,d,e,f = gets.split.map {|s| s.to_i}
die = Dice.new(a,b,c,d,e,f)
ret = false
for i in 1..4
  die.rotV
  die.show
  ret = true if die == die1
end
die.rotE
for i in 1..4
  die.rotV
  die.show
  ret = true if die == die1
end
die.rotE
for i in 1..4
  die.rotV
  die.show
  ret = true if die == die1
end
die.rotE
for i in 1..4
  die.rotV
  die.show
  ret = true if die == die1
end
die.rotE.rotN
for i in 1..4
  die.rotV
  die.show
  ret = true if die == die1
end
die.rotS.rotS
for i in 1..4
  die.rotV
  die.show
  ret = true if die == die1
end
if ret
  puts "Yes"
else
  puts "No"
end