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(dice = [])
    @dice = dice
  end

  def getTop
    @dice[0]
  end
  
  def getFront
    @dice[1]
  end

  def getRight
    @dice[2]
  end

  def getLeft
    @dice[3]
  end

  def getBack
    @dice[4]
  end

  def getBottom
    @dice[5]
  end

  def getDiceArray
    [ 
      @dice[0],
      @dice[1],
      @dice[2],
      @dice[3],
      @dice[4],
      @dice[5]
    ]
  end

  def setTop(t)
    case t
    when @dice[0]
      return
    when @dice[1]
      self.role("N")
    when @dice[2]
      self.role("W")
    when @dice[3]
      self.role("E")
    when @dice[4]
      self.role("S")
    when @dice[5]
      self.role("N")
      self.role("N")
    end
  end


  def role(c)
    case c
    when "N"
      @dice = 
        [
          @dice[1],
          @dice[5],
          @dice[2],
          @dice[3],
          @dice[0],
          @dice[4]
        ]

    when "S"
      @dice = 
        [
          @dice[4],
          @dice[0],
          @dice[2],
          @dice[3],
          @dice[5],
          @dice[1]
        ]
    
    when "E"
      @dice = 
        [
          @dice[3],
          @dice[1],
          @dice[0],
          @dice[5],
          @dice[4],
          @dice[2]
        ]
    
    when "W"
      @dice = 
        [
          @dice[2],
          @dice[1],
          @dice[5],
          @dice[0],
          @dice[4],
          @dice[3]
        ]
    end
  end

  def setFront(n)
    case n
    when @dice[0]
      return false
    when @dice[1]
      return true
    when @dice[2]
      self.turn("L")
    when @dice[3]
      self.turn("R")
    when @dice[4]
      self.turn("R")
      self.turn("R")
    when @dice[5]
      return false
    end
  end

  def turn(c)
    case c
    when "R"
      @dice =
        [
          @dice[0],
          @dice[2],
          @dice[4],
          @dice[1],
          @dice[3],
          @dice[5]
        ]
    when "L"
      @dice =
        [
          @dice[0],
          @dice[3],
          @dice[1],
          @dice[4],
          @dice[2],
          @dice[5]
        ]
    end
  end
end

dice_arr = gets.split.map(&:to_i)
@dice_origin = Dice.new(dice_arr)
dice_arr = gets.split.map(&:to_i)
@dice = Dice.new(dice_arr)

same_dice = false
3.times do
  4.times do
    if @dice_origin.getDiceArray == @dice.getDiceArray
      same_dice = true
    end
    @dice.turn("R")
  end
  @dice.role("N")
end

3.times do
  4.times do
    if @dice_origin.getDiceArray == @dice.getDiceArray
      same_dice = true
    end
    @dice.turn("R")
  end
  @dice.role("E")
end



if same_dice 
  puts "Yes" 
else
  puts "No"
end