#include <iostream>
#include<string>

using namespace std;
class Dice{
public:
	int num[6],t;//t=top
		/*
		dice.num[0] = ???
		dice.num[1] = ???
		dice.num[2] = ???
		dice.num[3] = ???
		dice.num[4] = ???
		dice.num[5] = ???*/

	void North(){
		t = num[0];
		num[0] = num[1];//??????1?????¨???
		num[1] = num[5];//??????2?????¨???
		num[5] = num[4];//??????6?????¨???
		num[4] = t;//??????5?????¨???
		}

	void East(){
		t = num[0];
		num[0] = num[3];//??????1?????¨???
		num[3] = num[5];//??????4?????¨???
		num[5] = num[2];//??????6?????¨???
		num[2] = t;//??????3?????¨???
		}

	void West(){
		t = num[0];
		num[0] = num[2];//??????1?????¨???
		num[2] = num[5];//??????5?????¨???
		num[5] = num[3];//??????6?????¨???
		num[3] = t;//??????2?????¨???
		}
		
	void South(){
		t = num[0];
		num[0] = num[4];//??????1?????¨???
		num[4] = num[5];//??????3?????¨???
		num[5] = num[1];//??????6?????¨???
		num[1] = t;//??????3?????¨???
		}
	
	void Rotation(){//?????¢??????????????§?????¢???????????¨???
		t = num[1];
		num[1] = num[2];//?????¢???2?????¨???
		num[2] = num[4];//?????¢???3?????¨???
		num[4] = num[3];//?????¢???5?????¨???
		num[3] = t;//?????¢???4?????¨???
		}
};

int main()
{
	Dice d[100];
	
	int n;
	cin >> n;
	
	for(int i=0; i<n; i++){
		cin >> d[i].num[0] >> d[i].num[1] >> d[i].num[2] >> d[i].num[3] >> d[i].num[4] >> d[i].num[5];
	}
	
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
		//?????¢??????????????????
		if(( d[i].num[2] == d[j].num[0] || d[i].num[3] == d[j].num[0]) && d[i].num[0] != d[j].num[5]){
			d[i].East();
		}
		//?????¢??????????¨???????
		for(int k = 0; k<4; k++){
			if(d[i].num[0] == d[j].num[0])break;
			d[i].North();
		}
		////?????¢?????????????????????
		for(int k = 0; k<4; k++){
			if(d[i].num[1] == d[j].num[1])break;
			d[i].Rotation();
		}
		for(int k = 0; k<4; k++){
			if(d[i].num[2] == d[j].num[2])break;
			d[i].Rotation();
		}
		for(int k = 0; k<4; k++){
			if(d[i].num[3] == d[j].num[3])break;
			d[i].Rotation();
		}
		for(int k = 0; k<4; k++){
			if(d[i].num[4] == d[j].num[4])break;
			d[i].Rotation();
		}
		for(int k = 0; k<4; k++){
			if(d[i].num[5] == d[j].num[3])break;
			d[i].Rotation();
		}
			if( d[i].num[0] == d[j].num[0] &&
				d[i].num[1] == d[j].num[1] &&
				d[i].num[2] == d[j].num[2] &&
				d[i].num[3] == d[j].num[3] &&
				d[i].num[4] == d[j].num[4] &&
				d[i].num[5] == d[j].num[5] ){
					cout << "No" << endl;
					return 0;
			}
		}
		
	}
	cout << "Yes" << endl;
	return 0;
}
#include <iostream>
#include <vector>

using namespace std;

class Dice
{
  public:
    vector<int> diceNum;
    Dice(vector<int>& inputs);
    void toW();
    void toS();
    void ParallelRotation();
};

Dice::Dice(vector<int>& inputs)
{
  diceNum=inputs;
}

void Dice::toW()
{
  swap(diceNum[0],diceNum[3]);
  swap(diceNum[0],diceNum[5]);
  swap(diceNum[0],diceNum[2]);
}

void Dice::toS()
{
  swap(diceNum[0],diceNum[1]);
  swap(diceNum[0],diceNum[5]);
  swap(diceNum[0],diceNum[4]);
}

void Dice::ParallelRotation()
{
  swap(diceNum[1],diceNum[2]);
  swap(diceNum[2],diceNum[4]);
  swap(diceNum[4],diceNum[3]);
}

bool Judge(Dice& dice1,Dice& dice2)
{
  int count=0;
  for(int i=0;i<6;i++)
  {
    if(dice1.diceNum[i]==dice2.diceNum[i]) count++;
  }
  if(count==6)return true;
  else return false;
    
}

bool preJudge(Dice& dice1,Dice& dice2)
{
  int count=0;
  bool flag=false;
  while(1)
  {
    dice2.toS();
    for(int j=0;j<4;j++)
    {
      dice2.ParallelRotation();
      flag=Judge(dice1,dice2);
      if(flag==true) break;
    }
    if(flag==true) break;
    dice2.toW();
    for(int j=0;j<4;j++)
    {
      dice2.ParallelRotation();
      flag=Judge(dice1,dice2);
      if(flag==true) break;
    }
    count++;
    if(flag==true) break;
    if(count==3)break;
  } 
  return flag;
}

int main(int argc,char* argv[])
{
  vector<int> inputs(6);
  int number;
  int count =0;
  cin >> number;
  bool flag=false;
  
  vector<Dice> Dices;
  for(int i=0;i<number;i++)
  {
    for(int j=0;j<6;j++)
    {
      cin >> inputs[j];
    }
    Dices.push_back(Dice(inputs));
  }
  for(int i=0;i<number-1;i++)
  {
    for(int j=i+1;j<number;j++)
    {
      flag = preJudge(Dices[i],Dices[j]);
      if(flag==true) break;
    }
    if(flag==true) break;
  }
  if(flag==true) cout << "No" << endl;
  else if(flag==false) cout << "Yes" << endl;
}