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 PHP (judge verdict: Wrong Answer)

<?php
define("TOP",1);
define("FRONT",2);
define("RIGHT",3);
define("LEFT",4);
define("BEHIND",5);
define("BOTTOM",6);
class Dice{
    private $numbers;
    // before => after
    private $IDX_ROLL = [
        "E" => [TOP => RIGHT,RIGHT => BOTTOM,LEFT => TOP,BOTTOM => LEFT],
        "N" => [TOP => BEHIND,FRONT => TOP,BEHIND => BOTTOM,BOTTOM => FRONT],
        "S" => [TOP => FRONT,FRONT => BOTTOM,BEHIND => TOP,BOTTOM => BEHIND],
        "W" => [TOP => LEFT,RIGHT => TOP,LEFT => BOTTOM,BOTTOM => RIGHT],
        "C" => [FRONT => LEFT,RIGHT => FRONT,LEFT => BEHIND,BEHIND => RIGHT]    // spin:clockwise
    ];
    public function __construct($numbers){
        $this->numbers = $numbers;
    }
    public function roll($dir){
        $pos = $this->numbers;
        foreach($this->IDX_ROLL[$dir] as $before => $after){
            $this->numbers[$after] = $pos[$before];
        }
    }
    public function isEq($dice2){
        for($i = 1; $i <= 6; $i++){
            if($this->numbers[$i] !== $dice2[$i]) return false;
        }
        return true;
    }
    public function isEqual($dice2){
        $cnt = 0;
        while($this->numbers[TOP] !== $dice2[TOP]){
            if($cnt % 2) $this->roll("W");
            else $this->roll("N");
            $cnt++;
        }
        for($i = 0; $i <4; $i++){
            if($this->isEq($dice2)) return true;
            $this->roll("C");
        }
        return false;
    }
}
//=====================================
$numbers = getStdin();
$dice2 = getStdin();
if(count(array_diff($numbers, $dice2)) !== 0){
    echo "No\n";
    exit();
}
$dice1 = new Dice($numbers);
if($dice1->isEqual($dice2)){
    echo "Yes\n";
} else {
    echo "No\n";
}

function getStdin(){
    $l = explode(" ",trim(fgets(STDIN)));
    return array_combine(range(1,6),$l);
}