#include <iostream>
#include <vector>

class Dice{

public:

	Dice(int x0, int x1, int x2, int x3, int x4, int x5, int y0, int y1, int y2, int y3, int y4, int y5);//?????????????????????
	~Dice();
	void change(char X);
	int Dice_func();

private://Dice_box?????????????????§??????????????§????????????????????????
	std::vector <int> Dice_a;//Dice?????????????????°
	std::vector <int> Dice_b;//Dice?????????????????°
};

Dice::Dice(int x0, int x1, int x2, int x3, int x4, int x5, int y0, int y1, int y2, int y3, int y4, int y5){
	//Dice????????????Dice_a,Dice_b??¨???????????????????????????????????????????????§?????????
	Dice_a.push_back(x0);
	Dice_a.push_back(x1);
	Dice_a.push_back(x2);
	Dice_a.push_back(x3);
	Dice_a.push_back(x4);
	Dice_a.push_back(x5);
	Dice_b.push_back(y0);
	Dice_b.push_back(y1);
	Dice_b.push_back(y2);
	Dice_b.push_back(y3);
	Dice_b.push_back(y4);
	Dice_b.push_back(y5);

}

Dice::~Dice(){}//????????????????????????

//change??¢??°???Dice_func??????char??????{SENW}?????????????????????????????????Dice_b????????¢?????????
void Dice::change(char X){

	int Dice_copy[6] = {};

	//Dice_b???????????¨??????????????????Dice_copy?????????
	for (int i = 0; i < 6; i++){ Dice_copy[i] = Dice_b[i]; }


	switch (X){

	case 'S':
		Dice_copy[0] = Dice_b[4];
		Dice_copy[1] = Dice_b[0];
		Dice_copy[2] = Dice_b[2];//E
		Dice_copy[3] = Dice_b[3];//W
		Dice_copy[4] = Dice_b[5];
		Dice_copy[5] = Dice_b[1];
		break;

	case 'E':
		Dice_copy[0] = Dice_b[3];
		Dice_copy[1] = Dice_b[1];//S
		Dice_copy[2] = Dice_b[0];
		Dice_copy[3] = Dice_b[5];
		Dice_copy[4] = Dice_b[4];//N
		Dice_copy[5] = Dice_b[2];
		break;

	case 'W':
		Dice_copy[0] = Dice_b[2];
		Dice_copy[1] = Dice_b[1];//S
		Dice_copy[2] = Dice_b[5];
		Dice_copy[3] = Dice_b[0];
		Dice_copy[4] = Dice_b[4];//N
		Dice_copy[5] = Dice_b[3];
		break;
	case 'N':
		Dice_copy[0] = Dice_b[1];
		Dice_copy[1] = Dice_b[5];
		Dice_copy[2] = Dice_b[2];//E
		Dice_copy[3] = Dice_b[3];//W
		Dice_copy[4] = Dice_b[0];
		Dice_copy[5] = Dice_b[4];
		break;
	}//switch???

	//Dice_copy????????????Dice_b????????????
	for (int i = 0; i < 6; i++){
		Dice_b[i] = Dice_copy[i];
	}



}


//check????????????1??????1???0??????0???????????¢??°
//??????????????°???Dice_a??¨Dice_b????????¢???????????´??????????????????????¢????????????¢??°
//change??¢??°????????£????????¢???????????????
int Dice::Dice_func(){

	for (int i = 0; i < 3 && ((Dice_a[0] != Dice_b[0]) || (Dice_a[5] != Dice_b[5])); i++){

		change('S');
	}

	//????????????????????¢??????????????????
	for (int i = 0; i < 3 && ((Dice_a[0] != Dice_b[0]) || (Dice_a[5] != Dice_b[5])); i++){

		change('E');
	}


	//??????????????§?????¢??????????????¢????????£???????????´???0?????????
	if ((Dice_a[0] != Dice_b[0]) || (Dice_a[5] != Dice_b[5])){
		return 0;

	}
	else

		//??´??¢???????????????
		//??´??¢????????¢?????????????¨?????????????S???E???N???W??§??????
		//?????¢???????????´????????????S???E???N???W???S????????????????????????	
		//b???{SENW}{ENWS}{NWSE}{WSEN}?????????????????¨a???{SEWN}????????´?????????????¢??????????
		//{0,1,2,3,4,5}={???,S,E,W,N,???}

		if ((Dice_a[1] == Dice_b[1] && Dice_a[2] == Dice_b[2] && Dice_a[4] == Dice_b[4] && Dice_a[3] == Dice_b[3])
			|| (Dice_a[1] == Dice_b[2] && Dice_a[2] == Dice_b[4] && Dice_a[4] == Dice_b[3] && Dice_a[3] == Dice_b[1])
			|| (Dice_a[1] == Dice_b[4] && Dice_a[2] == Dice_b[3] && Dice_a[4] == Dice_b[1] && Dice_a[3] == Dice_b[2])
			|| (Dice_a[1] == Dice_b[3] && Dice_a[2] == Dice_b[1] && Dice_a[4] == Dice_b[2] && Dice_a[3] == Dice_b[4])){
			//????????§?????´????????´???1?????????
			return 1;

		}
		else{ //?????´???????????£?????´??????0?????????
			return 0;	
		}
		}





int main(){

	int n,num,sum=0;
	std::cin >> n;

	std::vector<std::vector<int> > Box;
	Box = std::vector<std::vector<int> >(n, std::vector<int>(6, 0));


	for (int i = 0; i < n; i++){//Dice???????¬????????????§??????
	
		for (int j = 0; j < 6; j++){
			std::cin >> num;
			Box[i][j] = num;
				}
	}


     //Dice?????????
	for (int i = 0; i<n - 1; i++){
		for (int j = 1 + i; j<n; j++){
			
			{//?????????????????§????????????????????????????????´?£???????
				Dice Dice_check(Box[i][0], Box[i][1], Box[i][2], Box[i][3], Box[i][4], Box[i][5], Box[j][0], Box[j][1], Box[j][2], Box[j][3], Box[j][4], Box[j][5]);

				//Dice_check??¢??°?????????0(No)?????????1(Yes)
				//sum???????????????????????????0?????????????????¨???????????´??§????????????
				sum+=Dice_check.Dice_func();
			}//???????????????????????¨?????????????????????????????´?£?????????????


		}

	}

	
	if (sum == 0){ std::cout << "Yes"<<std::endl; 
	}
	else{ std::cout << "No" << std::endl; }


	return 0;
}

Measured memory_bytes: 1224