#include <bits/stdc++.h>

using namespace std;

class Cube 
{
	public:
		int f[6];
		Cube(){}
		void roll_z() {roll(1, 2, 4, 3);}
		void roll_y() {roll(0, 2, 5, 3);}
		void roll_x() {roll(0, 1, 5, 4);}
		void roll(int i, int j, int k, int l)
		{
			int t = f[i];
			f[i] = f[j];
			f[j] = f[k];
			f[k] = f[l];
			f[l] = t;
		}
		void move(char ch)
		{
			if(ch == 'E')
				for(int i = 0; i < 3; i++)
					roll_y();
            else if(ch == 'W')
            	roll_y();
            else if(ch == 'N')
            	roll_x();
            else if(ch == 'S')
            	for(int i = 0; i < 3; i++)
            		roll_x();
		}
};

bool isIdentical(string s[], Cube c1, Cube c2)
{	
	for(int i = 0; i < 340; i++)
	{
		for(int j = 0; j < s[i].size(); j++)
		{
			c2.move(s[i][j]);
			
			if(c1.f[0] == c2.f[0] && c1.f[1] == c2.f[1] && c1.f[2] == c2.f[2]
				&& c1.f[3] == c2.f[3] && c1.f[4] == c2.f[4] && c1.f[5] == c2.f[5])
			{
				return true;
			}
		}
	}
	return false;
}
int main()
{
	int n, m;
	Cube c;
	vector<Cube> v;
	string s[340] = { "SSSS","SSSE","SSSW","SSSN","SSES","SSEE","SSEW","SSEN","SSWS","SSWE"
					 "SSWW","SSWN","SSNS","SSNE","SSNW","SSNN","SESS","SESE","SESW","SESN"
					 "SEES","SEEE","SEEW","SEEN","SEWS","SEWE","SEWW","SEWN","SENS","SENE"
					 "SENW","SENN","SWSS","SWSE","SWSW","SWSN","SWES","SWEE","SWEW","SWEN"
					 "SWWS","SWWE","SWWW","SWWN","SWNS","SWNE","SWNW","SWNN","SNSS","SNSE"
					 "SNSW","SNSN","SNES","SNEE","SNEW","SNEN","SNWS","SNWE","SNWW","SNWN"
					 "SNNS","SNNE","SNNW","SNNN","ESSS","ESSE","ESSW","ESSN","ESES","ESEE"
					 "ESEW","ESEN","ESWS","ESWE","ESWW","ESWN","ESNS","ESNE","ESNW","ESNN"
					 "EESS","EESE","EESW","EESN","EEES","EEEE","EEEW","EEEN","EEWS","EEWE"
					 "EEWW","EEWN","EENS","EENE","EENW","EENN","EWSS","EWSE","EWSW","EWSN"
					 "EWES","EWEE","EWEW","EWEN","EWWS","EWWE","EWWW","EWWN","EWNS","EWNE"
					 "EWNW","EWNN","ENSS","ENSE","ENSW","ENSN","ENES","ENEE","ENEW","ENEN"
					 "ENWS","ENWE","ENWW","ENWN","ENNS","ENNE","ENNW","ENNN","WSSS","WSSE"
					 "WSSW","WSSN","WSES","WSEE","WSEW","WSEN","WSWS","WSWE","WSWW","WSWN"
					 "WSNS","WSNE","WSNW","WSNN","WESS","WESE","WESW","WESN","WEES","WEEE"
					 "WEEW","WEEN","WEWS","WEWE","WEWW","WEWN","WENS","WENE","WENW","WENN"
					 "WWSS","WWSE","WWSW","WWSN","WWES","WWEE","WWEW","WWEN","WWWS","WWWE"
					 "WWWW","WWWN","WWNS","WWNE","WWNW","WWNN","WNSS","WNSE","WNSW","WNSN"
					 "WNES","WNEE","WNEW","WNEN","WNWS","WNWE","WNWW","WNWN","WNNS","WNNE"
					 "WNNW","WNNN","NSSS","NSSE","NSSW","NSSN","NSES","NSEE","NSEW","NSEN"
					 "NSWS","NSWE","NSWW","NSWN","NSNS","NSNE","NSNW","NSNN","NESS","NESE"
					 "NESW","NESN","NEES","NEEE","NEEW","NEEN","NEWS","NEWE","NEWW","NEWN"
					 "NENS","NENE","NENW","NENN","NWSS","NWSE","NWSW","NWSN","NWES","NWEE"
					 "NWEW","NWEN","NWWS","NWWE","NWWW","NWWN","NWNS","NWNE","NWNW","NWNN"
					 "NNSS","NNSE","NNSW","NNSN","NNES","NNEE","NNEW","NNEN","NNWS","NNWE"
					 "NNWW","NNWN","NNNS","NNNE","NNNW","NNNN","SSS","SSE","SSW","SSN"
					 "SES","SEE","SEW","SEN","SWS","SWE","SWW","SWN","SNS","SNE"
					 "SNW","SNN","ESS","ESE","ESW","ESN","EES","EEE","EEW","EEN"
					 "EWS","EWE","EWW","EWN","ENS","ENE","ENW","ENN","WSS","WSE"
					 "WSW","WSN","WES","WEE","WEW","WEN","WWS","WWE","WWW","WWN"
					 "WNS","WNE","WNW","WNN","NSS","NSE","NSW","NSN","NES","NEE"
					 "NEW","NEN","NWS","NWE","NWW","NWN","NNS","NNE","NNW","NNN"
					 "SS","SE","SW","SN","ES","EE","EW","EN","WS","WE"
					 "WW","WN","NS","NE","NW","NN","S","E","W","N"};
	
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < 6; j++)
		{
			cin >> m;
			c.f[j] = m;
		}
		v.push_back(c);
	}
	
	vector<Cube>::iterator it1;
	vector<Cube>::iterator it2;
	bool cond = false;
	int i = 1;
	
	for(it1 = v.begin(); it1 != v.end(); it1++)
	{	
		for(it2 = v.begin()+i; it2 != v.end(); it2++)
		{
			if(isIdentical(s, *it1, *it2))
			{
				cond = true;
				break;
			}
		}
		if(cond)
			break;
		i++;
	}
	 
	if(cond)
		printf("No\n");
	else 
		printf("Yes\n");
	
	return 0;
}


Measured memory_bytes: 3300