#include <vector>
#include <string>
#include <iostream>
using namespace std;

#define ROT(a,b,c,d) tmp = o[(a)]; o[(a)]=o[(b)]; o[(b)]=o[(c)]; o[(c)]=o[(d)]; o[(d)]=tmp 


class Dice
{
public:
	vector<int> label;

	Dice(int l[6]) : label(7)
	{ for(int i=1; i<7; ++i) label[i] = l[i-1]; }
	Dice(const Dice &d) = default;
	Dice &operator=(const Dice &d) = default;

	Dice &rotate(int face) {
		auto &o = label;
		int tmp;

		switch(face) {
		case 1: ROT(2,3,5,4); break;
		case 2: ROT(1,4,6,3); break;
		case 3: ROT(1,2,6,5); break;
		case 4: ROT(1,5,6,2); break;
		case 5: ROT(1,3,6,4); break;
		case 6: ROT(2,4,5,3); break;
		}

		return *this;
	}

	friend bool test_cur(const Dice &a, const Dice &b) {
		bool equal = true;
		for(int i=1; i<7; ++i) equal &= a.label[i] == b.label[i];
		return equal;
	}

	friend bool operator==(Dice dice1, Dice dice2) {
		for(int a=0; a<6; ++a) {
			for(int i=0; i<4; ++i) {
				dice1.rotate(1);
				if(test_cur(dice1, dice2))
					return true;
			}
			if(a<4) dice1.rotate(4);

			if(a==3) dice1.rotate(2);
			else if(a==4) dice1.rotate(2).rotate(2);
		}

		return false;
	}

};


int main()
{
	int n; cin >> n;
	vector<Dice> v;

	int label[6];
	while(n--) {
		for(auto &l : label) cin >> l;
		v.emplace_back(label);
	}

	bool diff = false;
	for(auto d1=v.cbegin(); d1 != v.cend(); ++d1) {
		for(auto d2 = d1+1; d2 != v.cend(); ++d2) {
			diff |= (*d1 == *d2);
			if(diff) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;
	
	return 0;
}

