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
  def initialize(n)
    @n = n
  end
  #     ^N
  #     [0]:top
  # [3] [1] [2] [4]  2:right 3:left 4:back
  #     [5]:bottom
  #     vS
  attr_reader :n

  def roll(d)
    case d
    when ?N
      @n = [@n[1], @n[5], @n[2], @n[3], @n[0], @n[4]]
    when ?S
      @n = [@n[4], @n[0], @n[2], @n[3], @n[5], @n[1]]
    when ?E
      @n = [@n[3], @n[1], @n[0], @n[5], @n[4], @n[2]]
    when ?W
      @n = [@n[2], @n[1], @n[5], @n[0], @n[4], @n[3]]
    else
      raise
    end
    self
  end
  def rotate_right
    @n = [@n[0], @n[2], @n[4], @n[1], @n[3], @n[5]]
    self
  end
  def rotate_left
    @n = [@n[0], @n[3], @n[1], @n[4], @n[2], @n[5]]
    self
  end
  def print
    puts "  #{@n[0]}"
    puts "#{@n[3]} #{@n[1]} #{@n[2]} #{@n[4]}"
    puts "  #{@n[5]}"
  end
  # THIS FUNCTION WILL ROTATE DICE
  def ==(other)
    c = @n.uniq.map{|e| [e, @n.count(e)]}.sort{|a,b|a[1]<=>b[1]}
    other.set_upper_by_value(c[0][0])
    return true if c.size < 2 # only 1 number
    idx = @n.map.with_index{|p,i| i if p==c[0][0]}.compact
    idx.each{|i|
      set_upper_by_index(i)
      4.times{
        return true if self.n == other.n
        rotate_right
      }
    }
    return false
  end
  def set_upper_by_index(idx)
    case idx
    when 0
      ;
    when 1
      self.roll(?N)
    when 2
      self.roll(?W)
    when 3
      self.roll(?E)
    when 4
      self.roll(?S)
    when 5
      self.roll(?N)
      self.roll(?N)
    when nil
      raise "@n:#{@n} u:#{u} f:#{f}"
    end
    self
  end
  def set_upper_by_value(u)
    set_upper_by_index(@n.index(u))
  end
  def set_up_n_front(u, f)
    set_upper_by_value(u)
    case @n.index(f)
    when 1
      ;
    when 2
      self.rotate_right
    when 3
      self.rotate_left
    when 4
      self.rotate_left.rotate_left
    when 0, 5, nil
      raise "@n:#{@n} u:#{u} f:#{f}"
    end
    self
  end
end

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