#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

class Dice
{
public:
    int label[6], tmp;

    void in()
    {
        rep(i, 6) scanf("%d", &label[i]);
    }

    void rollS()
    {
        tmp = label[0];
        label[0] = label[4];
        label[4] = label[5];
        label[5] = label[1];
        label[1] = tmp;
    }

    void rollN()
    {
        tmp = label[0];
        label[0] = label[1];
        label[1] = label[5];
        label[5] = label[4];
        label[4] = tmp;
    }

    void rollE()
    {
        tmp = label[0];
        label[0] = label[3];
        label[3] = label[5];
        label[5] = label[2];
        label[2] = tmp;
    }

    void rollW()
    {
        tmp = label[0];
        label[0] = label[2];
        label[2] = label[5];
        label[5] = label[3];
        label[3] = tmp;
    }

    void sideturn()
    {
        tmp = label[1];
        label[1] = label[2];
        label[2] = label[4];
        label[4] = label[3];
        label[3] = tmp;
    }
};

bool check2(Dice d1, Dice d2)
{
    bool c = true;
    FOR(i, 1, 5)
    {
        c = c && d1.label[i] == d2.label[i];
    }

    return c;
}

bool check1(Dice d1, Dice d2)
{
    bool b = false;

    if (d1.label[0] == d2.label[0] && d1.label[5] == d2.label[5])
    {
        rep(i, 4)
        {
            b = b || check2(d1, d2);
            d2.sideturn();
        }
    }
    return b;
}

bool isSame(Dice d1, Dice d2)
{
    bool a = false;

    a = a || check1(d1, d2);
    d2.rollN();
    a = a || check1(d1, d2);
    d2.rollE();
    a = a || check1(d1, d2);
    d2.rollE();
    a = a || check1(d1, d2);
    d2.rollE();
    a = a || check1(d1, d2);
    d2.rollN();
    a = a || check1(d1, d2);

    return a;
}

int main()
{
    int n;
    bool ans = false;
    scanf("%d", &n);
    Dice dice[n];
    rep(i, n) dice[i].in();

    rep(i, n)
    {
        FOR(j, i + 1, n)
        {
            ans = ans || isSame(dice[i], dice[j]);
        }
    }

    if (ans)
        printf("No\n");
    else
        printf("Yes\n");
}

#include<stdio.h>
#include<string.h>
typedef struct {
	char direction[100];
	int num1,num2,num3,num4,num5,num6;
}DICE_t;
int main(){
	int n;
	scanf("%d",&n);
	DICE_t a[n];
	for(int x=0;x<n;x++){
	    scanf("%d %d %d %d %d %d",&a[x].num1,&a[x].num2,&a[x].num3,&a[x].num4,&a[x].num5,&a[x].num6);
	}
	int x,y;
	for(x=0;x<(n-1);x++){
		for(y=(x+1);y<n;y++){
	        int dummy,turn=0;
	        while(turn<24){
		        if(turn%4==0&&turn!=0){
		    	    strcpy(a[y].direction,(turn%8==4 ?"SSEN":"ESEN"));
	    	    }
    		    else{
        			strcpy(a[y].direction,"SEN");
    	    	}
    	        for(int i=0;a[y].direction[i]!=0;i++){
    	            if(a[y].direction[i]=='N'){
		                dummy=a[y].num5;
	            	    a[y].num5=a[y].num1;
	            	    a[y].num1=a[y].num2;
	            	    a[y].num2=a[y].num6;
	        	        a[y].num6=dummy;
	                }
	                else if(a[y].direction[i]=='S'){
		                dummy=a[y].num6;
	            	    a[y].num6=a[y].num2;
	            	    a[y].num2=a[y].num1;
	            	    a[y].num1=a[y].num5;
	            	    a[y].num5=dummy;
	                }
    	    	    else if(a[y].direction[i]=='E'){
		                dummy=a[y].num4;
	        	        a[y].num4=a[y].num6;
	        	        a[y].num6=a[y].num3;
	        	        a[y].num3=a[y].num1;
	        	        a[y].num1=dummy;
	                }
	                else if(a[y].direction[i]=='W'){
	                    dummy=a[y].num1;
    	            	a[y].num1=a[y].num3;
	                	a[y].num3=a[y].num6;
	                	a[y].num6=a[y].num4;
	                	a[y].num4=dummy;
	                }	
    	        }
	        	if(a[x].num1==a[y].num1&&a[x].num2==a[y].num2&&a[x].num3==a[y].num3&&a[x].num4==a[y].num4&&a[x].num5==a[y].num5&&a[x].num6==a[y].num6){
	        		printf("No\n");
	        		goto end;
	        	}
	    	    turn++;
	        }
		}
	}
	printf("Yes\n");
end:	
	
	return 0;
}