<?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";
}




Measured memory_bytes: 9392