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

#include <iostream>
#include <random>
#include <functional>
#include <ctime>
#include <set>
#include <utility>
using std::cout;
using std::endl;
using std::cin;

constexpr char dir[] = {'N','E','W','S'};

class dice{
public:
	dice(int in[6]){
		for(int i=0;i<6;i++){
			v[i]=in[i];
		}
	}
	dice(){}
	void mov(const char c){
		int buf;
		switch(c){
			case dir[0]:{
				buf = v[0];
				v[0] = v[1];
				v[1] = v[5];
				v[5] = v[4];
				v[4] = buf;
				break;
			}
			case dir[1]:{
				buf = v[0];
				v[0] = v[3];
				v[3] = v[5];
				v[5] = v[2];
				v[2] = buf;
				break;
			}
			case dir[2]:{
				buf = v[0];
				v[0] = v[2];
				v[2] = v[5];
				v[5] = v[3];
				v[3] = buf;
				break;
			}
			case dir[3]:{
				buf = v[0];
				v[0] = v[4];
				v[4] = v[5];
				v[5] = v[1];
				v[1] = buf;
				break;
			}
		}
	}
	int operator[](size_t i){return v[i];}
	bool operator==(dice d){
		for(int i=0;i<6;i++){
			if(v[i]!=d[i])return false;
		}
		return true;
	}
	bool operator!=(dice d){
		return !operator==(d);
	}
private:
	int v[6];
};

bool issame(dice d1,dice d2){
	int i=0;
	auto rgen = std::bind(std::uniform_int_distribution<>(0,3),std::mt19937(time(nullptr)));
	while(i<100){
		d1.mov(dir[rgen()]);
		if(d1==d2)return true;
		i++;
	}
	return false;
}

bool alldiff(dice d[],int n){
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			if(issame(d[i],d[j])) return false;
		}
	}
	return true;
}

int main(){
	dice d[100];
	int in[6],n;
	cin >> n;
	for (int i=0;i<n;i++) {
		for(int j=0;j<6;j++){
			cin >> in[j];
		}
		d[i]=dice(in);
	}

	cout << (alldiff(d,n)?"Yes":"No") << endl;
}