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 C# (judge verdict: Accepted)

using System;

public class Dice
{
	private int[] labels;
	public const int TOP = 0;
	public const int FRONT = 1;
	public const int RIGHT = 2;
	public const int LEFT = 3;
	public const int BACK = 4;
	public const int BOTTOM = 5;
	public Dice( int[] labels )
	{
		this.labels = labels;
	}
	public void roll( string cmds )
	{
		int t;
		for( int i=0; i<cmds.Length; 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 int getLabel( int face )
	{
		return this.labels[face];
	}
	public bool isEqual( Dice another )
	{
		string cmds = "SWWWSMMMM";
		for( int i=0; i<6; i++ ) {
			if( another.getLabel( Dice.TOP ) == this.getLabel( Dice.TOP ) ) {
				for( int j=5; j<9; j++ ) {
					if( another.getLabel( Dice.FRONT ) == this.getLabel( Dice.FRONT ) ) {
						int k;
						for( k=Dice.TOP; k<=Dice.BOTTOM; k++ ) {
							if( another.getLabel( k ) != this.getLabel( k ) ) { break; }		
						}
						if( 6 == k ) { return true; }
						break;
					}
					this.roll( cmds[j].ToString() );		
				}
			}
			this.roll( cmds[i].ToString() );			
		}
		return false;
	}
	
}

public class Test
{
	public static void Main( )
	{
		int n = int.Parse( Console.ReadLine() );
		Dice[] dices = new Dice[n];
		for( int i=0; i<n; i++ ) {
			int[] labels = Array.ConvertAll( Console.ReadLine().Split( ' ' ), int.Parse );
			dices[i] = new Dice( labels );
		}
		bool isDiff = true;
		for( int i=0; i<n-1; i++ ) {
			for( int j=i+1; j<n; j++ ) {
				if( dices[i].isEqual( dices[j] ) ) {
					isDiff = false;
					goto END;
				}
			}
		}
		END:
		if( isDiff ) {
			Console.WriteLine( "Yes" );
		} else {		
			Console.WriteLine( "No" );		
		}
	}
}