#include <iostream>
#include <cstdio>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
typedef struct{
    int head;
    int tail;
    int right;
    int left;
    int up;
    int down;
} dice;
dice s(dice a) {
    int buf;
    buf = a.tail;
    a.tail = a.down;
    a.down = a.head;
    a.head = a.up;
    a.up = buf;
	return a;
}
dice n(dice a) {
	return s(s(s(a)));
}
dice e(dice a) {
    int buf;
    buf = a.tail;
    a.tail = a.right;
    a.right = a.head;
    a.head = a.left;
    a.left = buf;
	return a;
}
dice w(dice a) {
	return e(e(e(a)));
}
dice rev(dice a) {
	return e(e(a));
}
dice round(dice a) {
	int buf;
	buf = a.right;
	a.right = a.up;
	a.up = a.left;
	a.left = a.down;
	a.down = buf;
	return a;
}
bool same(dice a, dice b) {
	dice c = a;
	rep(i,4) {
		if(c.head == b.head && c.tail == b.tail && c.up == b.up && c.down == b.down && c.right == b.right && c.left == b.left) return true;
		c = round(c);
	}
	return false;
}

int main() {
    int k, a[105][6];
	cin >> k;
	rep(i,k) {
		rep(j,6) {
	        cin >> a[i][j];
		}
	}
	rep(i,k) {
		rep2(j,i+1,k) {
			dice da, db;
			da.head = a[i][0];
			da.down = a[i][1];
			da.right = a[i][2];
			da.left = a[i][3];
			da.up = a[i][4];
			da.tail = a[i][5];
			db.head = a[i+j][0];
			db.down = a[i+j][1];
			db.right = a[i+j][2];
			db.left = a[i+j][3];
			db.up = a[i+j][4];
			db.tail = a[i+j][5];	
			if(same(da,db) || same(s(da), db) || same(n(da), db) || same(e(da), db) || same(w(da), db) || same(rev(da), db)) {
				cout << "No" <<endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;	
	return 0;
}
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

const int COUNT = 6;


class Dice
{
public:
	int num[6];

public:
	Dice();
	void play_dice(string);
	void play(int, int, int, int);
	void print_(int x) {printf("%d\n", num[x]);}
	void to_top_and_front(int, int);
};

Dice::Dice()
{
	for (int i = 0; i < COUNT; ++i)
	{
		cin >> num[i];
		
	}
}


void Dice::play_dice(string s)
{
	if(s == "E") {play(0, 2, 5, 3); }
		
	if(s == "N") {play(0, 4, 5, 1); }
		
	if(s == "S") {play(0, 1, 5, 4); }
	
	if(s == "W") {play(0, 3, 5, 2); }
}

void Dice::play(int a, int b, int c, int d)
{
	int temp;
	temp = num[d]; num[d] = num[c]; num[c] = num[b]; num[b] = num[a]; num[a] = temp;
}


void Dice::to_top_and_front(int top, int front)
{
	string str[7] = {"N", "N", "N", "W", "N", "N", "N"};
	for (int i = 0; i < 7; ++i)
	{
		if(front == num[1]) break;
		play_dice(str[i]);
	}
	for (int k = 0; k < 4; k++)
	{
		if(top == num[0]) break;
		play_dice("W");
	}
}

bool compare(Dice a, Dice b)
{
	a.to_top_and_front(b.num[0], b.num[1]);
	
	for (int i = 0; i < COUNT; ++i)
	{
		if (a.num[i] != b.num[i])
		{
			return false;
		}
	}
	return true;
}



int main(int argc, char const *argv[])
{
	Dice *cs;
	int times;

	cin >> times;

	cs = new Dice[times];
	
	for (int i = 0; i < times; ++i)
	{
		for (int k = i+1; k < times; ++k)
		{
			if(compare(cs[i], cs[k]))
			{
				delete[] cs;
				printf("No\n");
				return 0;
			}
		}	
	}
	
	delete[] cs;
	printf("Yes\n");
	return 0;
}