Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Dice IV

Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.

Input

In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.

Output

Print "Yes" if given dices are all different, otherwise "No" in a line.

Constraints

$2 \leq n \leq 100$

$0 \leq $ the integer assigned to a face $ \leq 100$

Sample Input 1

3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1

Sample Output 1

No

Sample Input 2

3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6

Sample Output 2

Yes

Solution in PHP (judge verdict: Accepted)

<?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 getNumbers(){
        return $this->numbers;
    }
    public function roll($dir){
        $pos = $this->numbers;
        foreach($this->IDX_ROLL[$dir] as $before => $after){
            $this->numbers[$after] = $pos[$before];
        }
    }
    // is equal
    public function isEq($another){
        for($i = 1; $i <= 6; $i++){
            if($this->numbers[$i] !== $another[$i]) return false; 
        }
        return true;
    }
    public function isEqual($another){
        for($i = 0; $i < 6; $i++){
            for($j = 0; $j < 4; $j++){
                if($this->isEq($another)) return true;
                $this->roll("C");
            }
            if($i % 2) $this->roll("W");
            else $this->roll("N");
        }
        return false;
    }
}
//============== main ==============
$num = getStdin();
for($i = 0; $i < $num; $i++){
    $dice[$i] = getInstance();
}
for($i = 0; $i < $num - 1; $i++){
    for($j = $i + 1; $j < $num; $j++){
        if($dice[$i]->isEqual($dice[$j]->getNumbers())){
            echo "No\n";
            exit;
        }
    }
}
echo "Yes\n";
//============== input ==============
function getStdin(){
    return trim(fgets(STDIN));
}
function getInstance(){
    $a = explode(" ",getStdin());
    $numbers = array_combine(range(1,6),$a);
    return new Dice($numbers);
}