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 num_dict
    @num=num_dict

    @top=1
    @bottom=6
    @right=3
    @left=4
    @forward=5
    @backward=2

  end

  def ==(other)
    tempOther=other.clone
    if tempOther.checkSameDice(@num[@top],@num[@right])
      tempOtherNum=tempOther.instance_variable_get(:@num)
      if ( (@num[@top]==tempOtherNum[tempOther.instance_variable_get('@top')])&&(@num[@bottom]==tempOtherNum[tempOther.instance_variable_get('@bottom')])&&(@num[@right]==tempOtherNum[tempOther.instance_variable_get('@right')])&&(@num[@left]==tempOtherNum[tempOther.instance_variable_get('@left')])&&(@num[@forward]==tempOtherNum[tempOther.instance_variable_get('@forward')])&&(@num[@backward]==tempOtherNum[tempOther.instance_variable_get('@backward')]) )
        return true
      else
        return false
      end
    end
  end

  def to_s
    <<"EOS"
    top:      #{@num[@top]}
    bottom:   #{@num[@bottom]}
    right:    #{@num[@right]}
    left:     #{@num[@left]}
    forward:  #{@num[@forward]}
    backward: #{@num[@backward]}
EOS
  end

  def getTop
    @num[@top]
  end

  def moveE
    temp=@top
    @top=@left
    @left=@bottom
    @bottom=@right
    @right=temp
  end

  def setRight(rightNum)
    top=@num.key(rightNum)
    3.times do |i|
      break if @top==top
      moveE
      moveN if @top!=top
    end
    if @top==top
      moveE
      return true
    end
    false
  end
    
  def checkSameDice(topNum,rightNum)
    if setRight(rightNum)
      3.times do
        return true if @top==@num.key(topNum)
        moveN
      end
    end
    false
  end
  def moveW
    temp=@top
    @top=@right
    @right=@bottom
    @bottom=@left
    @left=temp
  end

  def moveN
    temp=@top
    @top=@backward
    @backward=@bottom
    @bottom=@forward
    @forward=temp
  end
  
  def moveS
    temp=@top
    @top=@forward
    @forward=@bottom
    @bottom=@backward
    @backward=temp
  end

  def rotate(char)
    case char
      when "E"
        moveE
      when "W"
        moveW
      when "N"
        moveN
      when "S"
        moveS
    end
  end

  def setBackwardandRight(backNum,rightNum)
    back=@num.key(backNum)
    right=@num.key(rightNum)
    3.times{
      break if @backward==back
      moveN
    }
    if @backward!=back
      moveE
      while @backward!=back
        moveN
      end
    end
 
    while @right!=right
      moveE
    end
  end
end

a,b,c,d,e,f=STDIN.gets.split(" ")
dice1=Dice.new({1 => a.to_i , 2 => b.to_i , 3 => c.to_i , 4 => d.to_i , 5 => e.to_i , 6 => f.to_i})

a,b,c,d,e,f=STDIN.gets.split(" ")
dice2=Dice.new({1 => a.to_i , 2 => b.to_i , 3 => c.to_i , 4 => d.to_i , 5 => e.to_i , 6 => f.to_i})

if dice1==dice2
  puts "Yes"
else
  puts "No"
end