#include<cstdio>

int main(){
	int n,x;
	scanf("%d", &n);
	int dice[n][6];
	int tmp[6];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 6; j++){
			scanf("%d", &dice[i][j]);
		}
	}

	int pt[5][6] = {	{5,1,3,4,6,2}, 
				 	{0,0,0,0,0,0},
					{4,2,1,6,5,3},
					{2,6,3,4,1,5},
					{3,2,6,1,5,4}};
	int t[24] = {0,0,0,2,0,0,0,2,0,0,0,4,0,0,0,4,0,0,0,2,0,0,0,0};

	for(int a = 0; a < n; a++){
		for(int b = a + 1; b < n; b++){
			for(int i = 0; i < 24 ; i++){
				int c = 0;
				while(!(dice[a][c] - dice[b][c])){
					c++;
					if(c == 6){
						printf("No\n");
						return 0;
					}
				}

				for(int j = 0; j < 6; j++){
					tmp[j] = dice[a][j];
				}
				for(int j = 0; j < 6; j++){
					x = pt[t[i]][j];
					dice[a][j] = tmp[x - 1];
				}
			}
		}
	}
	printf("Yes\n");
	return 0;
}
#include<iostream>
#include<string>
#include<vector>

using namespace std;

enum Diceface {
	DICETOP,
	DICEFRONT,
	DICERIGHT,
	DICELEFT,
	DICEBACK,
	DICEBOTTOM,
	DICENUM
};

class Dice {
private:
	int *face;
public:
	Dice( ) { face = new int[DICENUM]; }
	Dice( int top, int front, int right, int left, int back, int bottom ) {
		face = new int[DICENUM];
		
		face[DICETOP] = top;
		face[DICEFRONT] = front;
		face[DICERIGHT] = right;
		face[DICELEFT] = left;
		face[DICEBACK] = back;
		face[DICEBOTTOM] = bottom;
	}
	~Dice( ) {
		delete [ ] face;
	}
	void setFace( int top, int front, int right, int left, int back, int bottom ) {
		face[DICETOP] = top;
		face[DICEFRONT] = front;
		face[DICERIGHT] = right;
		face[DICELEFT] = left;
		face[DICEBACK] = back;
		face[DICEBOTTOM] = bottom;
	
		return;
	}
	void roll( char cmd ) {
		int t;
		if( 'E' == cmd ) {
			t = face[DICETOP];
			face[DICETOP] = face[DICELEFT];
			face[DICELEFT] = face[DICEBOTTOM];
			face[DICEBOTTOM] = face[DICERIGHT];
			face[DICERIGHT] = t;
		} else if( 'N' == cmd ) {
			t = face[DICETOP];
			face[DICETOP] = face[DICEFRONT];
			face[DICEFRONT] = face[DICEBOTTOM];
			face[DICEBOTTOM] = face[DICEBACK];
			face[DICEBACK] = t;
		} else if( 'S' == cmd ) {
			t = face[DICETOP];
			face[DICETOP] = face[DICEBACK];
			face[DICEBACK] = face[DICEBOTTOM];
			face[DICEBOTTOM] = face[DICEFRONT];
			face[DICEFRONT] = t;
		} else if( 'W' == cmd ) {
			t = face[DICETOP];
			face[DICETOP] = face[DICERIGHT];
			face[DICERIGHT] = face[DICEBOTTOM];
			face[DICEBOTTOM] = face[DICELEFT];
			face[DICELEFT] = t;
		} else if( 'M' == cmd ) {
			t = face[DICEBACK];
			face[DICEBACK] = face[DICERIGHT];
			face[DICERIGHT] = face[DICEFRONT];
			face[DICEFRONT] = face[DICELEFT];
			face[DICELEFT] = t;
		}
		return;
	}
	int getFace( int diceface ) {
		return face[ diceface ];
	}

	bool isDiff( Dice &dice ) {
		int cnt;
		string cmd = "MMMMNMMMMWMMMMWMMMMWMMMMNMMMM";

		for( int i=0; i<cmd.length(); i++ ) {		
			if( dice.getFace( DICETOP ) == face[ DICETOP ] ) {
				for( cnt=0; cnt<DICENUM; cnt++ ) {
					if( dice.getFace( cnt ) != face[ cnt ] ) { break; }
				}
				if( DICENUM == cnt ) { break; }
			}
			dice.roll( cmd[i] );
		}
		
		if( DICENUM == cnt ) {
			return false;
		} else {
			return true;
		}
	}

};

int main( )
{
	int t, f, r, l, ba, bo;
	int n;
	
	cin>>n;
	Dice *dice = new Dice[n];
	if( NULL == dice ) { return 0; }
	
	int cnt = 0;
	while( cnt < n ) {
		cin>>t>>f>>r>>l>>ba>>bo;
		dice[ cnt++ ].setFace( t, f, r, l, ba, bo );
	}
	
	bool isDiff = false;
	for( int i=0; i<n-1; i++ ) {
		for( int j=i+1; j<n; j++ ) {
			if( !( isDiff = dice[i].isDiff( dice[j] ) ) ) { break; }
		}
		if( !isDiff ) { break; }
	}
	if( isDiff ) {
		cout<<"Yes"<<endl;		
	} else {
		cout<<"No"<<endl;
	}

	delete [ ] dice; 
	
	return 0;
}