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(i1, i2, i3, i4, i5, i6)
    @nums = [i1, i2, i3, i4, i5, i6]
  end
  def get_top
    @nums[0]
  end
  def get_front
    @nums[1]
  end
  def get_right
    @nums[2]
  end
  def move_n
    move(1, 5, 2, 3, 0, 4)
  end
  def move_s
    move(4, 0, 2, 3, 5, 1)
  end
  def move_w
    move(2, 1, 5, 0, 4, 3)
  end
  def move_e
    move(3, 1, 0, 5, 4, 2)
  end
  def normalize(top, front)
    i = @nums.index(top)
    case i
    when 1 then move_n
    when 2 then move_w
    when 3 then move_e
    when 4 then move_s
    when 5 then move_n; move_n
    end
    i = @nums.index(front)
    case i
    when 0 then return false
    when 1 then return true
    when 2 then move_s; move_e; move_n; return true
    when 3 then move_s; move_w; move_n; return true
    when 4 then move_e; move_n; move_w; move_s; move_e; move_n; return true
    when 5 then return false
    else return false
    end
  end
  def to_i
    @nums.join(' ')
  end
  private
  def move(i1, i2, i3, i4, i5, i6)
    @nums[0], @nums[1], @nums[2], @nums[3], @nums[4], @nums[5] =
      @nums[i1], @nums[i2], @nums[i3], @nums[i4], @nums[i5], @nums[i6]
  end
end

nums = STDIN.gets.chomp.split(' ').map(&:to_i)
dice1 = Dice.new(*nums)

nums = STDIN.gets.chomp.split(' ').map(&:to_i)
dice2 = Dice.new(*nums)
dice2.normalize(dice1.get_top, dice1.get_front)

if dice1.to_i === dice2.to_i
  puts 'Yes'
else
  puts 'No'
end