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: Runtime Error)

class Dice
  attr_accessor :face

  Edge = [[0,1,2],[0,2,4],[0,4,3],[0,3,1],[1,5,2],[2,5,4],[4,5,3],[3,5,1]]

  #topとfrontの数字を渡すと右の面のindexを返してくれる
  def query(top, front)
    x,y = @face.index(top),@face.index(front)
    Edge.each do |item|
      if i = item.index(y)
        if item[i-1] == x
          right = item[i-2]
          return right
        end
      end
    end
  end

  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]
    end
  end
end

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

if dice1.face[dice1.query(dice2.face[0], dice2.face[1])] == dice2.face[dice2.query(dice2.face[0], dice2.face[1])] && \
  dice1.face[dice1.query(dice2.face[1], dice2.face[5])] == dice2.face[dice2.query(dice2.face[1], dice2.face[5])] && \
  dice1.face[dice1.query(dice2.face[5], dice2.face[4])] == dice2.face[dice2.query(dice2.face[5], dice2.face[4])] && \
  dice1.face[dice1.query(dice2.face[1], dice2.face[0])] == dice2.face[dice2.query(dice2.face[1], dice2.face[0])]
  puts "Yes"
else
  puts "No"
end