#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Dice{
public:
	array<int,6> F;
	array<map<int,int>,6> R;
	map<int,int> L,C;
	Dice(){
		R[0][1]=2;
		R[0][2]=4;
		R[0][4]=3;
		R[0][3]=1;

		R[1][0]=3;
		R[1][3]=5;
		R[1][5]=2;
		R[1][2]=0;

		R[2][0]=1;
		R[2][1]=5;
		R[2][5]=4;
		R[2][4]=0;

		R[3][0]=4;
		R[3][4]=5;
		R[3][5]=1;
		R[3][1]=0;

		R[4][0]=2;
		R[4][2]=5;
		R[4][5]=3;
		R[4][3]=0;

		R[5][1]=3;
		R[5][3]=4;
		R[5][4]=2;
		R[5][2]=1;
	}
	void Roll(char ch){
		int temp;
		switch(ch){
		case 'W':
			temp = F[0];
			F[0] = F[2];
			F[2] = F[5];
			F[5] = F[3];
			F[3] = temp;
			break;
		case 'E':
			temp = F[0];
			F[0] = F[3];
			F[3] = F[5];
			F[5] = F[2];
			F[2] = temp;
			break;
		case 'N':
			temp = F[0];
			F[0] = F[1];
			F[1] = F[5];
			F[5] = F[4];
			F[4] = temp;
			break;
		default:
			temp = F[0];
			F[0] = F[4];
			F[4] = F[5];
			F[5] = F[1];
			F[1] = temp;
		}
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N=in();
	vector<vector<int>> DA(N,vector<int>(6));
	REP(i,N){
		REP(j,6){
			DA[i][j]=in();
		}
	}
	REP(first,N){
		for(int second=first+1;second<N;second++){
			auto X=DA[first];
			Dice D1,D2;
			REP(i,6){
				D1.F[i] = X[i];
				D1.L[X[i]] = i;
				D1.C[X[i]]++;
			}
			X=DA[second];
			REP(i,6){
				D2.F[i] = X[i];
				D2.L[X[i]] = i;
				D2.C[X[i]]++;
			}

			int minDF1 = min_element(ALL(D2.C))->first;
			if(D2.L.find(minDF1)==D2.L.end()){
				continue;
			}

			switch(D1.L[minDF1]){
			case 1:
				D1.Roll('N');
				break;
			case 2:
				D1.Roll('W');
				break;
			case 3:
				D1.Roll('E');
				break;
			case 4:
				D1.Roll('S');
				break;
			case 5:
				D1.Roll('W');
				D1.Roll('W');
				break;
			}

			int DF1=D1.F[0];
			int DFR1=D1.F[5];

			bool fit = false;
			int DL2;
			for(int i=0;i<6;i++){
				if(D2.F[i]==DF1 && D2.F[5-i]==DFR1){
					fit = true;
					DL2 = i;
					break;
				}
			}
			if(!fit){
				continue;
			}

			switch(DL2){
			case 1:
				D2.Roll('N');
				break;
			case 2:
				D2.Roll('W');
				break;
			case 3:
				D2.Roll('E');
				break;
			case 4:
				D2.Roll('S');
				break;
			case 5:
				D2.Roll('W');
				D2.Roll('W');
				break;
			}

			array<int,4> DFS1={D1.F[1],D1.F[2],D1.F[4],D1.F[3]};
			array<int,4> DFS2={D2.F[1],D2.F[2],D2.F[4],D2.F[3]};

			bool exist=false;
			int start = 0;
			for(int i=0;i<4;i++){
				if(DFS2[i]==DFS1[0]){
					exist = true;
					start = i;
					break;
				}
			}
			if(!exist){
				continue;
			}
			exist = false;
			for(int i=1;i<4;i++){
				if(DFS1[i]!=DFS2[(start+i)%4]){
					exist = true;
					break;
				}
			}
			if(exist){
				continue;
			}
			out("No");
			return 0;
		}
	}

	out("Yes");
	return 0;
}



Measured memory_bytes: 3212