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)

MODE = "stdio"
require 'matrix'
include Math
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = '1 2 3 4 5 6
  6 2 4 3 5 1'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end
class Dice
  attr_accessor :top, :front, :right, :left, :back, :bottom
  def initialize(arr)
    @top = arr[0]
    @front = arr[1]
    @right = arr[2]
    @left = arr[3]
    @back = arr[4]
    @bottom = arr[5]
  end

  def get_arr
    [@top, @front, @right, @left, @back, @bottom]
  end

  def set_arr(arr)
    @top = arr[0]
    @front = arr[1]
    @right = arr[2]
    @left = arr[3]
    @back = arr[4]
    @bottom = arr[5]
  end

  def roll(s)
    case s
    when "E"
      @top, @right, @bottom, @left = @left,@top, @right, @bottom
    when "W"
      @top, @right, @bottom, @left = @right, @bottom, @left, @top
    when "N"
      @top, @back , @bottom, @front = @front,@top, @back , @bottom
    when "S"
      @top, @back , @bottom, @front = @back , @bottom, @front,@top
    end
    [@top, @front, @right, @left, @back, @bottom]
  end

  def rolls(s)
    s.chars.each do|s|
      roll(s)
    end
    [@top, @front, @right, @left, @back, @bottom]
  end

  def spin
    @front, @right, @left, @back = @right, @left, @back, @front
    [@top, @front, @right, @left, @back, @bottom]
  end

  def equal_top?(dice)
    tmp = self.get_arr
    cmd = ["" "E","W","N","S","EE"]
    cmd.each do |c|
      self.set_arr(tmp)
      self.rolls(c)
      if(self.top == dice.top)
        return true
      end
    end
    return false
  end

  def equal?(dice)
    if equal_top?(dice)
      4.times do
        if(self.front == dice.front) && (self.back == dice.back) && (self.right == dice.right)
          return true
        else
          self.spin
        end
      end
      return false
    else
      return false
    end
  end
end

arr1 = line[0].split(" ").map(&:to_i)
arr2 = line[1].split(" ").map(&:to_i)
dice1 = Dice.new(arr1)
dice2 = Dice.new(arr2)

r = dice1.equal?(dice2)
puts "Yes" if r
puts "No" if !r