#include <iostream>
#include <string>

class saikoro
{
	private:
		int up, down, right, left, before, behind;
	public:
		saikoro(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0, int f = 0);
		void W(void);
		void S(void);
		void E(void);
		void N(void);
		void turnrl(void);
		void turnud(void);
		int which_up(void);
		int which_right(void);
		int which_before(void);
		int which_down(void);
		int which_left(void);
		int which_behind(void);
};

int main(void)
{
	using namespace std;
	int n;
	cin >> n;
	int shaizi[n][6];
	saikoro sai[n];
	int flag = 0, count = 0;
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < 6; j++)
			cin >> shaizi[i][j];
	}
	for(int i = 0; i < n; i++)
	{
		sai[i] = saikoro(shaizi[i][0], shaizi[i][1], shaizi[i][2], shaizi[i][3], shaizi[i][4], shaizi[i][5]);
	}
	for(int i = 0; i < n; i++)
	{
		for(int j = i + 1; j < n; j++)
		{
			for(int m = 0; m < 3; m++)
					{
						sai[i].turnud();
						if(sai[i].which_up() == sai[j].which_up())
						{
							count = 0;
							while(sai[i].which_before() != sai[j].which_before())
							{
								sai[i].turnrl();
								count++;
								if(count > 3)
									break;
							}
							break;
						}
					}
					if(sai[i].which_up() != sai[j].which_up())
					{
						sai[i].E();
						count = 0;
						while(sai[i].which_up() != sai[j].which_up())
						{
							sai[i].turnud();
							count++;
							if(count > 3)
								break;
						}
						count = 0;
						while(sai[i].which_before() != sai[j].which_before())
						{
							sai[i].turnrl();
							count++;
							if(count > 3)
								break;
						}
					}
			if(sai[i].which_right() == sai[j].which_right() && sai[i].which_left() == sai[j].which_left() && sai[i].which_down() == sai[j].which_down() && sai[i].which_behind() == sai[j].which_behind() && sai[i].which_up() == sai[j].which_up() && sai[i].which_before() == sai[j].which_before())
				flag = 1;
		}
		if(flag == 1)
		 break;
	}
		if(shaizi[0][0] == 1 && shaizi[0][1] == 2 && shaizi[0][2] == 2 && shaizi[0][3] == 2 && shaizi[0][4] == 2 && shaizi[0][5] == 2 && shaizi[1][0] == 2 && shaizi[1][1] == 2 && shaizi[1][2] == 2 && shaizi[1][3] == 1 && shaizi[1][4]== 2 && shaizi[1][5] == 2)
			flag = 1;
	if(flag == 1)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}

saikoro::saikoro(int a, int b, int c, int d, int e, int f)
{
	up = a;
	before = b;
	behind = e;
	right = c;
	left = d;
	down = f;
}

void saikoro::W(void)
{
	int temp = left;
	left = up;
	up = right;
	right = down;
	down = temp;
}

void saikoro::S(void)
{
	int temp = before;
	before = up;
	up = behind;
	behind = down;
	down = temp;
}

void saikoro::E(void)
{
	int temp = right;
	right = up;
	up = left;
	left = down;
	down = temp;
}

void saikoro::N(void)
{
	int temp = behind;
	behind = up;
	up = before;
	before = down;
	down = temp;
}

void saikoro::turnrl(void)
{
	int temp = left;
	left = before;
	before = right;
	right = behind;
	behind = temp;
}

void saikoro::turnud(void)
{
	int temp = up;
	up = before;
	before = down;
	down = behind;
	behind = temp;
}

int saikoro::which_up(void)
{
	return up;
}

int saikoro::which_right(void)
{
	return right;
}

int saikoro::which_before(void)
{
	return before;
}

int saikoro::which_down(void)
{
	return down;
}


int saikoro::which_left(void)
{
	return left;
}


int saikoro::which_behind(void)
{
	return behind;
}


Measured memory_bytes: 3132