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
  @north = 5
  @south = 2
  @east = 3
  @west = 4
  @top = 1
  @bottom = 6

  def initialize(input_t, input_s, input_e, input_w, input_n, input_b)
    @north = input_n
    @south = input_s
    @east = input_e
    @west = input_w
    @top = input_t
    @bottom = input_b
  end

  def set(top, front, east)
    set_output = []
    10000.times do
      output =  self.move(["N", "S", "E", "W"].sample)
      if output[4] == top && output[1] == front && output[2] == east
        return true
        break
      end
    end
    return false
    #@top = top, @south = front???????????????????????¶??????move??????
    #???????????°?????????false?????§????????´??????true?????????
  end

  def move(order_array)
    length = order_array.length
    for i in 0..(length-1)
      if order_array[i] == "N"
        move_north
      elsif order_array[i] == "S"
        move_south
      elsif order_array[i] == "E"
        move_east
      else
        move_west
      end
    end
    output = [@north, @south, @east, @west, @top, @bottom]
    return output
  end

  def move_north
    tmp = []
    tmp.push(@north)
    tmp.push(@south)
    tmp.push(@top)
    tmp.push(@bottom)
    @bottom = tmp[0]
    @top = tmp[1]
    @north = tmp[2]
    @south = tmp[3]
  end

  def move_south
    tmp = []
    tmp.push(@north)
    tmp.push(@south)
    tmp.push(@top)
    tmp.push(@bottom)
    @top = tmp[0]
    @bottom = tmp[1]
    @south = tmp[2]
    @north = tmp[3]

  end

  def move_east
    tmp = []
    tmp.push(@east)
    tmp.push(@west)
    tmp.push(@top)
    tmp.push(@bottom)
    @bottom = tmp[0]
    @top = tmp[1]
    @east = tmp[2]
    @west = tmp[3]
  end

  def move_west
    tmp = []
    tmp.push(@east)
    tmp.push(@west)
    tmp.push(@top)
    tmp.push(@bottom)
    @top = tmp[0]
    @west = tmp[2]
    @bottom = tmp[1]
    @east = tmp[3]
  end

end

dice_numbers = gets.chomp.split.map(&:to_i)
input_t = dice_numbers[0]
input_s = dice_numbers[1]
input_e = dice_numbers[2]
input_w = dice_numbers[3]
input_n = dice_numbers[4]
input_b = dice_numbers[5]
dice = Dice.new(input_t, input_s, input_e, input_w, input_n, input_b)
other_dice_numbers = gets.chomp.split.map(&:to_i)
dice2 = Dice.new(other_dice_numbers[0], other_dice_numbers[1],other_dice_numbers[2],other_dice_numbers[3],other_dice_numbers[4],other_dice_numbers[5])
dice2_result = dice2.set(input_t, input_s, input_e)
if dice2_result == true
  puts "Yes"
else
  puts "No"
end