#include <bits/stdc++.h>
using namespace std;

int dice[100][6];

bool rotateAndCheck(int d1, int d2, int s0, int s1, int s2){
	if(
		dice[d1][0] == dice[d2][s0-1] &&
		dice[d1][1] == dice[d2][s1-1] &&
		dice[d1][2] == dice[d2][s2-1] &&
		dice[d1][3] == dice[d2][6-s2] &&
		dice[d1][4] == dice[d2][6-s1] &&
		dice[d1][5] == dice[d2][6-s0]
	){
		return true;
	}
	return false;
}
int main(){
	int n;
	cin >> n;
	
	for(int i=0; i<n; i++)
		for(int j=0; j<6; j++) cin >> dice[i][j];
	
	for(int i=0; i<n-1; i++){
		for(int j=i+1; j<n; j++){
			if(
				rotateAndCheck(i, j, 1, 2, 3) ||
				rotateAndCheck(i, j, 1, 3, 5) ||
				rotateAndCheck(i, j, 1, 4, 2) ||
				rotateAndCheck(i, j, 1, 5, 4) ||
				rotateAndCheck(i, j, 2, 1, 4) ||
				rotateAndCheck(i, j, 3, 1, 2) ||
				rotateAndCheck(i, j, 4, 1, 5) ||
				rotateAndCheck(i, j, 5, 1, 3) ||
				rotateAndCheck(i, j, 2, 3, 1) ||
				rotateAndCheck(i, j, 3, 5, 1) ||
				rotateAndCheck(i, j, 4, 2, 1) ||
				rotateAndCheck(i, j, 5, 4, 1) ||
				rotateAndCheck(i, j, 2, 4, 6) ||
				rotateAndCheck(i, j, 3, 2, 6) ||
				rotateAndCheck(i, j, 4, 5, 6) ||
				rotateAndCheck(i, j, 5, 3, 6) ||
				rotateAndCheck(i, j, 2, 6, 3) ||
				rotateAndCheck(i, j, 3, 6, 5) ||
				rotateAndCheck(i, j, 4, 6, 2) ||
				rotateAndCheck(i, j, 5, 6, 4) ||
				rotateAndCheck(i, j, 6, 2, 4) ||
				rotateAndCheck(i, j, 6, 3, 2) ||
				rotateAndCheck(i, j, 6, 4, 5) ||
				rotateAndCheck(i, j, 6, 5, 3)
			){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}
