#include <iostream>

using namespace std;

class Dice
{
public:
	static const int SURFACE_NUM = 6; // ?????????????????¢??°
	static const int DIR_NUM = 4; // ?????¢?????????????????°
	static const int ROUND_NUM = 4; // ?????¢????????¢?????°
	enum DIR { N, W, S, E }; // ?????¢??????
private:
	static const int rotate_table[DIR_NUM][ROUND_NUM]; // ?????¢??¨????????¢????????\???????????????
	static const int front_right_rotate_table[ROUND_NUM]; // ?????¢??¨?????¢????????????
	static const int front_top_rotate_table[ROUND_NUM]; // ?????¢??¨?????¢????????????
	int surface_numbers[SURFACE_NUM]; // ??¢?????°???

public:
	Dice() {}
	Dice(int number[SURFACE_NUM])
	{
		setNumber(number);
	}
private:
	void rotate(const int table[ROUND_NUM])
	{
		// ????????????????????§????????¢????????¢?????????
		int backup = surface_numbers[table[0]];
		for (int i = 0; i < ROUND_NUM - 1; i++)
			surface_numbers[table[i]] = surface_numbers[table[i + 1]];
		surface_numbers[table[ROUND_NUM - 1]] = backup;
	}
	int *getSurfaceNumber() { return surface_numbers; }
public:
	void setNumber(int number[SURFACE_NUM])
	{
		// ??¢?????°???????¨????
		for (int i = 0; i < SURFACE_NUM; i++)
			surface_numbers[i] = number[i];
	}
	void rotate(DIR direction)
	{
		// ?????¢????????\????????????????????§?????????
		rotate(rotate_table[direction]);
	}
	bool equals(Dice dice2)
	{
		// ?????¢?????°?????????????????§?????¢????????¢?????????
		for (int i = 0; i < ROUND_NUM; i++) {
			// ????????¢
			if (surface_numbers[0] == dice2.surface_numbers[0]) break;
			rotate(N);
		}
		if (surface_numbers[0] != dice2.surface_numbers[0]) {
			for (int i = 0; i < ROUND_NUM; i++) {
				// ?¨??????¢
				if (surface_numbers[0] == dice2.surface_numbers[0]) break;
				rotate(W);
			}
			// ??????????????????????????£?????´??????false
			if (surface_numbers[0] != dice2.surface_numbers[0]) return false;
		}
		// ?????¢?????°?????¨???????????¢??????????????§?????¢????????¢?????????
		for (int i = 0; i < ROUND_NUM; i++) {
			// ?¨??????¢
			if (surface_numbers[1] == dice2.surface_numbers[1] &&
				surface_numbers[2] == dice2.surface_numbers[2] &&
				surface_numbers[3] == dice2.surface_numbers[3] &&
				surface_numbers[4] == dice2.surface_numbers[4] &&
				surface_numbers[5] == dice2.surface_numbers[5]) break;
			rotate(front_right_rotate_table);
		}
		if (surface_numbers[1] != dice2.surface_numbers[1]) {
			for (int i = 0; i < ROUND_NUM; i++) {
				// ????????¢
				if (surface_numbers[1] == dice2.surface_numbers[1] &&
					surface_numbers[2] == dice2.surface_numbers[2] &&
					surface_numbers[3] == dice2.surface_numbers[3] &&
					surface_numbers[4] == dice2.surface_numbers[4] &&
					surface_numbers[5] == dice2.surface_numbers[5]) break;
				rotate(front_top_rotate_table);
			}
		}
		// ??????????????????????????£?????´??????false
		if (surface_numbers[1] != dice2.surface_numbers[1] ||
			surface_numbers[2] != dice2.surface_numbers[2] ||
			surface_numbers[3] != dice2.surface_numbers[3] ||
			surface_numbers[4] != dice2.surface_numbers[4] ||
			surface_numbers[5] != dice2.surface_numbers[5]) return false;
		return true;
	}
};
// ?????¢???????????????????????¢????????¢????????????????????????????????????(?????¢??¨)
const int Dice::rotate_table[DIR_NUM][ROUND_NUM]
{
	{ 0, 1, 5, 4 },
	{ 0, 2, 5, 3 },
	{ 0, 4, 5, 1 },
	{ 0, 3, 5, 2 }
};
// ????????¢????????¢????????????????????????????????????(?????¢??¨)
const int Dice::front_right_rotate_table[ROUND_NUM]{ 1, 2, 4, 3 };
const int Dice::front_top_rotate_table[ROUND_NUM]{ 1, 5, 4, 0 };
int main()
{
	int n, nums[Dice::SURFACE_NUM];
	Dice dices[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < Dice::SURFACE_NUM; j++)
			cin >> nums[j];
		dices[i].setNumber(nums);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != j) {
				if (dices[i].equals(dices[j])) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1160