#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

//#define __DEBUG__

class Dice {

	private:
		int iNS[4];
		int iEW[4];

	public:
		Dice( int v1, int v2, int v3, int v4, int v5, int v6 ) {
			iNS[0] = v1;
			iNS[1] = v2;
			iNS[2] = v6;
			iNS[3] = v5;

			iEW[0] = v1;
			iEW[1] = v3;
			iEW[2] = v6;
			iEW[3] = v4;

#ifdef __DEBUG__
			printf("NS[%d %d %d %d]\n", iNS[0], iNS[1], iNS[2], iNS[3]);
			printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif
		}

		void rotateN() {
			int iTmp = iNS[0];
			iNS[0] = iNS[1];
			iNS[1] = iNS[2];
			iNS[2] = iNS[3];
			iNS[3] = iTmp;

			iEW[0] = iNS[0];
			iEW[2] = iNS[2];

#ifdef __DEBUG__
			printf("RotateN ");
			printf("NS[%d %d %d %d] ", iNS[0], iNS[1], iNS[2], iNS[3]);
			printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif
		}

		void rotateS() {
			int iTmp = iNS[0];
			iNS[0] = iNS[3];
			iNS[3] = iNS[2];
			iNS[2] = iNS[1];
			iNS[1] = iTmp;

			iEW[0] = iNS[0];
			iEW[2] = iNS[2];

#ifdef __DEBUG__
			printf("RotateS ");
			printf("NS[%d %d %d %d] ", iNS[0], iNS[1], iNS[2], iNS[3]);
			printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif
		}

		void rotateE() {
			int iTmp = iEW[0];
			iEW[0] = iEW[3];
			iEW[3] = iEW[2];
			iEW[2] = iEW[1];
			iEW[1] = iTmp;

			iNS[0] = iEW[0];
			iNS[2] = iEW[2];

#ifdef __DEBUG__
			printf("RotateE ");
			printf("NS[%d %d %d %d] ", iNS[0], iNS[1], iNS[2], iNS[3]);
			printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif

		}

		void rotateW() {
			int iTmp = iEW[0];
			iEW[0] = iEW[1];
			iEW[1] = iEW[2];
			iEW[2] = iEW[3];
			iEW[3] = iTmp;

			iNS[0] = iEW[0];
			iNS[2] = iEW[2];

#ifdef __DEBUG__
			printf("RotateW ");
			printf("NS[%d %d %d %d] ", iNS[0], iNS[1], iNS[2], iNS[3]);
			printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif
		}

		void setDice(int v1, int v2, int v3, int v4, int v5, int v6) {
			iNS[0] = v1;
			iNS[1] = v2;
			iNS[2] = v6;
			iNS[3] = v5;

			iEW[0] = v1;
			iEW[1] = v3;
			iEW[2] = v6;
			iEW[3] = v4;
		}

		int getTop() {
			return iNS[0];
		}
		int getBottom() {
			return iNS[2];
		}
		int getFront() {
			return iNS[1];
		}
		int getBack() {
			return iNS[3];
		}
		int getRight() {
			return iEW[1];
		}
		int getLeft() {
			return iEW[3];
		}

		bool compareDice(Dice *dest) {
			if (iNS[0] == dest->getTop() && iNS[1] == dest->getFront() &&
				iNS[2] == dest->getBottom() && iNS[3] == dest->getBack() &&
				iEW[1] == dest->getRight() && iEW[3] == dest->getLeft() ) {
				return true;
			}
			return false;
		}

};

int main(void) {


	int v1[100], v2[100], v3[100], v4[100], v5[100], v6[100];
	Dice *d[100];
	int cnt;

	// read data num
	scanf("%d", &cnt);
	for (int i = 0; i < cnt; i++) {
		// dice definition
		scanf("%d %d %d %d %d %d", &v1[i], &v2[i], &v3[i], &v4[i], &v5[i], &v6[i]);
		d[i] = new Dice(v1[i], v2[i], v3[i], v4[i], v5[i], v6[i]);
	}

	for (int a = 0; a < cnt - 1; a++) {
		for ( int b = a + 1; b < cnt; b++ ) {

			for (int i = 0; i < 4; i++) {
				if (d[b]->getFront() == d[a]->getFront()) {	// front value match
					for (int j = 0; j < 4; j++) {
						if (d[a]->compareDice(d[b]) == true) {
							printf("No\n");
							return 0;
						}
						d[b]->rotateE();
					}
				}
				if (d[a]->compareDice(d[b]) == true) {
					printf("No\n");
					return 0;
				}
				d[b]->rotateN();
			}
			if (d[a]->compareDice(d[b]) == true) {
				printf("No\n");
				return 0;
			}
			d[b]->setDice(v1[b], v2[b], v3[b], v4[b], v5[b], v6[b]);
			d[b]->rotateE();
			for (int i = 0; i < 4; i++) {
				if (d[b]->getFront() == d[a]->getFront()) {	// front value match
					for (int j = 0; j < 4; j++) {
						if (d[a]->compareDice(d[b]) == true) {
							printf("No\n");
							return 0;
						}
						d[b]->rotateE();
					}
				}
				if (d[a]->compareDice(d[b]) == true) {
					printf("No\n");
					return 0;
				}
				d[b]->rotateN();
			}
			if (d[a]->compareDice(d[b]) == true) {
				printf("No\n");
				return 0;
			}
		}
	}

	printf("Yes\n");
	return 0;

}

Measured memory_bytes: 2676