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

"use strict";
main(require("fs").readFileSync("/dev/stdin", "utf8").replace(/\r?\n$/, "").split(/\r?\n/));

function main(lines){
	function Dice(labels){
		this.t = labels[0];
		this.s = labels[1];
		this.e = labels[2];
		this.w = labels[3];
		this.n = labels[4];
		this.b = labels[5];
	}
	Dice.prototype.roll = function(dir){
		var temp;
		if(dir == "N"){
			temp = this.t;
			this.t = this.s;
			this.s = this.b;
			this.b = this.n;
			this.n = temp;
		}
		else if(dir == "S"){
			temp = this.t;
			this.t = this.n;
			this.n = this.b;
			this.b = this.s;
			this.s = temp;
		}
		else if(dir == "W"){
			temp = this.t;
			this.t = this.e;
			this.e = this.b;
			this.b = this.w;
			this.w = temp;
		}
		else if(dir == "E"){
			temp = this.t;
			this.t = this.w;
			this.w = this.b;
			this.b = this.e;
			this.e = temp;
		}
	};
	Dice.prototype.isSame = function(other){
		var dice1 = new Dice([this.t, this.s, this.e, this.w, this.n, this.b]);
		var dice2 = new Dice([other.t, other.s, other.e, other.w, other.n, other.b]);
		var dirs = "EEEENEEEENEEEENEEENEEEENNEEEE";
		for(var i=0;i<dirs.length;i++){
			if(dice1.t == dice2.t && dice1.s == dice2.s && dice1.e == dice2.e && dice1.w == dice2.w && dice1.n == dice2.n && dice1.b == dice2.b){
				return true;
			}
			dice2.roll(dirs[i]);
		}
		return false;
	};

	var dices = [];
	var times = +lines.shift();
	var i, j;
	for(i=0;i<times;i++) dices.push(new Dice(lines.shift().split(" ")));
	var found = false;
	loop: for(i=0;i<dices.length;i++) for(j=i+1;j<dices.length;j++){
		if(dices[i].isSame(dices[j])){
			found = true;
			break loop;
		}
	}
	console.log(found ? "No" : "Yes");
}