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)

# Dice for AOJ
class Dice
  def initialize(input)
    @t, @s, @e, @w, @n, @b = input
  end

  def roll_e
    tmp = @e
    @e = @t
    @t = @w
    @w = @b
    @b = tmp
  end

  def roll_n
    tmp = @n
    @n = @t
    @t = @s
    @s = @b
    @b = tmp
  end

  def roll_w
    tmp = @w
    @w = @t
    @t = @e
    @e = @b
    @b = tmp
  end

  def roll_s
    tmp = @s
    @s = @t
    @t = @n
    @n = @b
    @b = tmp
  end

  def spin_r
    tmp = @s
    @s = @e
    @e = @n
    @n = @w
    @w = tmp
  end

  attr_reader :t
  attr_reader :s
  attr_reader :e
  attr_reader :w
  attr_reader :n
  attr_reader :b
end

d = gets.split.map(&:to_i)
dice1 = Dice.new(d)
d = gets.split.map(&:to_i)
dice2 = Dice.new(d)

case dice2.t
when dice1.s
  dice1.roll_n
when dice1.e
  dice1.roll_w
when dice1.w
  dice1.roll_e
when dice1.n
  dice1.roll_s
when dice1.b
  dice1.roll_n
  dice1.roll_n
end

4.times do
  dice1.spin_r
  break if dice2.s == dice1.s
end

if dice1.e == dice2.e && dice1.w == dice2.w \
    && dice1.n == dice2.n && dice1.b == dice2.b
  puts 'Yes'
else
  puts 'No'
end