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: Accepted)

class Dice
  attr_accessor :status
  def initialize(status)
    @status = status
  end

  def compareSpec(dice)
    @d2 = dice.status
    d1 = matchDirect(@d2)
    return (d1 == @d2) ? true : false
  end

  def matchDirect(d2)
    dt = Array.new(6)
    2.times do |i|
      idx = detectIndex(i)
      dt[i] = @status[idx]
      dt[5-i] = @status[5-idx]
    end
    top = @status.index(dt[0]) + 1
    front = @status.index(dt[1]) + 1
    idx = detectSideIndex(top,front)
    dt[2] = @status[idx]
    dt[3] = @status[5-idx]
    return dt
  end

  def detectIndex(i)
    idx = 0
    @status.each_with_index do |dir,j|
      if ((dir == @d2[i]) && (@status[5-j] == @d2[5-i]))
        idx = j
        break
      end
    end
    return idx
  end

  def detectSideIndex(top,front)
    idx = 0
    case top
    when 1,6
      s = [2,3,5,4]
      while (s.include?(front))&&(s[0] != front) do
        s.unshift(s.pop)
      end
      idx = (top == 1) ? s[1] - 1 : s[-1] - 1
    when 2,5
      s = [1,4,6,3]
      while (s.include?(front))&&(s[0] != front) do
        s.unshift(s.pop)
      end
      idx = (top == 2) ? s[1] - 1 : s[-1] - 1
    when 3,4
      s = [1,2,6,5]
      while (s.include?(front))&&(s[0] != front) do
        s.unshift(s.pop)
      end
      idx = (top == 3) ? s[1] - 1 : s[-1] - 1
    end
    return idx
  end
end

d1 = Dice.new(gets.split.map(&:to_i))
d2 = Dice.new(gets.split.map(&:to_i))
result = d1.compareSpec(d2)
puts (result == true) ? "Yes" : "No"