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

<?php
class Dice
{
    private $top;
    private $south;
    private $east;
    private $west;
    private $north;
    private $bottom;
    
    public function __construct ($dice_values) {
        $this->top = $dice_values[0];
        $this->south = $dice_values[1];
        $this->east = $dice_values[2];
        $this->west = $dice_values[3];
        $this->north = $dice_values[4];
        $this->bottom = $dice_values[5];
    }
    
    public function dice_set($top, $south) {
        $this->set_top($top);
        $this->set_south($south);
    }
    
    public function dice_check($dice_values) {
        $value_count = array_count_values($dice_values);
        foreach ($value_count as $key =>$value) {
            if ($value == 5) {
                return true;
            }
        }
        if ($this->top != $dice_values[0])  return false;
        if ($this->south != $dice_values[1]) return false;
        if ($this->east != $dice_values[2]) return false;
        if ($this->west != $dice_values[3]) return false;
        if ($this->north != $dice_values[4]) return false;
        if ($this->bottom !== $dice_values[5]) return false;
        return true;
    }
    
    public function move($directions) {
        for ($i = 0; $i < strlen($directions); $i++) {
            $this->change_value($directions[$i]);
        }
    }
    
    public function change_value($direction) {
        $top = $this->top;
        if ($direction == 'N') {
            $this->top = $this->south;
            $this->south = $this->bottom;
            $this->bottom = $this->north;
            $this->north = $top;
        } elseif ($direction == 'E') {
            $this->top = $this->west;
            $this->west = $this->bottom;
            $this->bottom = $this->east;
            $this->east = $top;
        } elseif ($direction == 'S') {
            $this->top = $this->north;
            $this->north = $this->bottom;
            $this->bottom = $this->south;
            $this->south = $top;
        } elseif ($direction == 'W') {
            $this->top = $this->east;
            $this->east = $this->bottom;
            $this->bottom = $this->west;
            $this->west = $top;
        }
    }
    
    public function set_top($top) {
        if ($this->top == $top) {
            return;
        } elseif ($this->south == $top) {
            $this->move("N");
        } elseif ($this->bottom == $top) {
            $this->move("NN");
        } elseif ($this->north == $top) {
            $this->move("S");
        } elseif ($this->east == $top) {
            $this->move("W");
        } elseif ($this->west == $top) {
            $this->move("E");
        }
    }
    
    public function set_south($south) {
        if ($this->south == $south) {
            return;
        } elseif ($this->north == $south) {
            $this->move("NEES");
        } elseif ($this->east == $south) {
            $this->move("NWS");
        } elseif ($this->west == $south) {
            $this->move("NES");
        }
    }
    
}


$dice_first = array_map("intval", explode(" ", trim(fgets(STDIN))));
$dice_second = array_map("intval", explode(" ", trim(fgets(STDIN))));

$dice = new Dice($dice_first);
$dice->dice_set($dice_second[0], $dice_second[1]);
if ($dice->dice_check($dice_second)) {
    echo "Yes\n";
} else {
    echo "No\n";
}