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
  attr_accessor :face

  def rotate(dir)
    case dir
    when "N"
      @face[0],@face[1],@face[5],@face[4] = @face[1],@face[5],@face[4],@face[0]
    when "E"
      @face[0],@face[2],@face[5],@face[3] = @face[3],@face[0],@face[2],@face[5]
    when "S"
      @face[0],@face[1],@face[5],@face[4] = @face[4],@face[0],@face[1],@face[5]
    when "W"
      @face[0],@face[2],@face[5],@face[3] = @face[2],@face[5],@face[3],@face[0]
    when "cw" #ClockWise rotation
      self.rotate("E").rotate("N").rotate("W")
      #@face[1],@face[2],@face[4],@face[3] = @face[2],@face[4],@face[3],@face[1]
    when "acw" #Anti ClockWise rotation
      self.rotate("W").rotate("N").rotate("E")
      #@face[1],@face[2],@face[4],@face[3] = @face[3],@face[1],@face[2],@face[4]
    end
    return self
  end

  def aline_dir(top, front)
    alined_dice = []
    @face.each_with_index do |item, index|
      if item == top
        case index
        when 1
          self.rotate("N")
        when 2
          self.rotate("W")
        when 3
          self.rotate("E")
        when 4
          self.rotate("S")
        when 5
          self.rotate("N").rotate("N")
        end
        (1..4).each do |i|
          if @face[i] == front
            case i
            when 2
              self.rotate("cw")
            when 3
              self.rotate("acw")
            when 4
              self.rotate("cw").rotate("cw")
            end
            alined_dice.push(self.face.clone)
          end
        end
      end
    end
    return alined_dice
  end
  
  def same?(dice_alined)
    bool = false
    dice_alined.each do |item|
      bool = true if self.face.eql?(item)
    end
    return bool
  end
end

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

dice2_alined = dice2.aline_dir(dice1.face[0], dice1.face[1])
puts dice1.same?(dice2_alined) ? "Yes" : "No"