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

struct Dice {
  int s[6];
  void turnN() {
    int tmp = s[0];
    s[0] = s[1]; s[1] = s[5]; s[5] = s[4]; s[4] = tmp;
  }
  void turnS() {
    int tmp = s[0];
    s[0] = s[4]; s[4] = s[5]; s[5] = s[1]; s[1] = tmp;
  }
  void turnW() {
    int tmp = s[0];
    s[0] = s[2]; s[2] = s[5]; s[5] = s[3]; s[3] = tmp;
  }
  void turnE() {
    int tmp = s[0];
    s[0] = s[3]; s[3] = s[5]; s[5] = s[2]; s[2] = tmp;
  }
};

int main() {
  
  int n; cin >> n; int table[n][6];
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      cin >> table[i][j];
    }
  }
  
  for (int i = 0; i < n - 1; i++) {
    
    for (int j = i + 1; j < n; j++) {
      
      Dice a; Dice b;
      
      for (int k = 0; k < 6; k++) a.s[k] = table[i][k];
      
      for (int k = 0; k < 6; k++) b.s[k] = table[j][k];
      
      for (int k = 0; k < 10000; k++) {
      
        int r = rand();
      
        if (r % 4 == 0) a.turnN();
        if (r % 4 == 1) a.turnS();
        if (r % 4 == 2) a.turnW();
        if (r % 4 == 3) a.turnE();
      
        for (int l = 0; l < 6; l++) {
          if (a.s[l] != b.s[l]) break;
          if (l == 5) {
            cout << "No" << endl;
            return 0;
          }
        }
        
      }
      
    }
    
  }
  
  cout << "Yes" << endl;
  
}
