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: WA: Presentation Error)

<?php
define( "TOP", 0 );
define( "FRONT", 1 );
define( "RIGHT", 2 );
define( "LEFT", 3 );
define( "BACK", 4 );
define( "BOTTOM", 5 );
class Dice
{
	private $labels;
	public function __construct( $labels )
	{
		$this->labels = $labels;
	}
	public function roll( $cmds )
	{
		$len = strlen( $cmds );
		for( $i=0; $i<$len; $i++ ) {
			if( 'E' == $cmds[$i] ) {
				$t = $this->labels[TOP];
				$this->labels[TOP] = $this->labels[LEFT];
				$this->labels[LEFT] = $this->labels[BOTTOM];
				$this->labels[BOTTOM] = $this->labels[RIGHT];
				$this->labels[RIGHT] = $t;
			} else if( 'S' == $cmds[$i] ) {
				$t = $this->labels[TOP];
				$this->labels[TOP] = $this->labels[BACK];
				$this->labels[BACK] = $this->labels[BOTTOM];
				$this->labels[BOTTOM] = $this->labels[FRONT];
				$this->labels[FRONT] = $t;
			} else if( 'W' == $cmds[$i] ) {
				$t = $this->labels[TOP];
				$this->labels[TOP] = $this->labels[RIGHT];
				$this->labels[RIGHT] = $this->labels[BOTTOM];
				$this->labels[BOTTOM] = $this->labels[LEFT];
				$this->labels[LEFT] = $t;
			} else if( 'N' == $cmds[$i] ) {
				$t = $this->labels[TOP];
				$this->labels[TOP] = $this->labels[FRONT];
				$this->labels[FRONT] = $this->labels[BOTTOM];
				$this->labels[BOTTOM] = $this->labels[BACK];
				$this->labels[BACK] = $t;
			} else if( 'M' == $cmds[$i] ) {
				$t = $this->labels[FRONT];
				$this->labels[FRONT] = $this->labels[RIGHT];
				$this->labels[RIGHT] = $this->labels[BACK];
				$this->labels[BACK] = $this->labels[LEFT];
				$this->labels[LEFT] = $t;
			}
		}
	}
	public function getLabel( $face )
	{
		return $this->labels[ $face ];
	}
	public function isEqual( $another )
	{
		$cmds = "NEEENMMMM";
		$len = strlen( $cmds );
		for( $i=0; $i<=5; $i++ ) {
			if( $another->getLabel( TOP ) == $this->getLabel( TOP ) ) {
				for( $j=5; $j<$len; $j++ ) {
					if( $another->getLabel( FRONT ) == $this->getLabel( FRONT ) ) {
						for( $k=TOP; $k<=BOTTOM; $k++ ) {
							if( $another->getLabel($k) != $this->getLabel($k) ) { break; }
						}
						if( 6 == $k ) { return true; }
					}
					$this->roll( $cmds[$j] );
				}
			}
			$this->roll( $cmds[$i] );
		}		
		return false;
	}	
}
	$n = intval( trim( fgets( STDIN ) ) );
	$dices = [];
	for( $i=0; $i<$n; $i++ ) {
		$labels = explode( " ", trim( fgets( STDIN ) ) );
		array_push( $dices, new Dice( $labels ) );
	}
	for( $i=0; $i<$n-1; $i++ ) {
		for( $j=$i+1; $j<$n; $j++ ) {
			if( $dices[$i]->isEqual( $dices[$j] ) ) {
				print "No";
				return;
			}
		}
	}
	print "Yes";
?>