#include <iostream>
#include <string>
#include <vector>

#define el endl
#define fd fixed

using namespace std;

class Dice
{
private:
  int top;
  int face;
  int right;
  int left;
  int back;
  int bottom;
public:
  void setTop(int a);
  void setFace(int a);
  void setRight(int a);
  void setLeft(int a);
  void setBack(int a);
  void setBottom(int a);
  int getTop();
  int getFace();
  int getRight();
  int getLeft();
  int getBack();
  int getBottom();
  void roll(string s);
  void rollE();
  void rollN();
  void rollS();
  void rollW();
  void arrangeTop(int a);
  void arrangeFace(int a);
  bool isDice(Dice d);
  bool checkDice(Dice d);
};

void Dice::setTop(int a) {
  top = a;
}

void Dice::setFace(int a) {
  face = a;
}

void Dice::setRight(int a) {
  right = a;
}

void Dice::setLeft(int a) {
  left = a;
}

void Dice::setBack(int a) {
  back = a;
}

void Dice::setBottom(int a) {
  bottom = a;
}

int Dice::getTop() {
  return top;
}

int Dice::getFace() {
  return face;
}

int Dice::getRight() {
  return right;
}

int Dice::getLeft() {
  return left;
}

int Dice::getBack() {
  return back;
}

int Dice::getBottom() {
  return bottom;
}

void Dice::roll(string s) {
  int n = s.length();
  for (int i = 0; i < n; i++) {
    if (s[i] == 'E') rollE();
    if (s[i] == 'N') rollN();
    if (s[i] == 'S') rollS();
    if (s[i] == 'W') rollW();
  }
}

void Dice::rollE() {
  int tmp = top;
  top = left;
  left = bottom;
  bottom = right;
  right = tmp;
}

void Dice::rollN() {
  int tmp = top;
  top = face;
  face = bottom;
  bottom = back;
  back = tmp;
}

void Dice::rollS() {
  int tmp = top;
  top = back;
  back = bottom;
  bottom = face;
  face = tmp;
}

void Dice::rollW() {
  int tmp = top;
  top = right;
  right = bottom;
  bottom = left;
  left = tmp;
}

void Dice::arrangeTop(int a) {
  for (int i = 0; i < 3; i++) {
    if (top == a) break;
    roll("N");
    if (top == a) break;
    roll("E");
  }
}

void Dice::arrangeFace(int a) {
  for (int i = 0; i < 4; i++) {
    if (face == a) break;
    roll("NES");
  }
}

bool Dice::isDice(Dice d) {
  arrangeTop(d.getTop());
  arrangeFace(d.getFace());
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  arrangeTop(d.getFace());
  arrangeFace(d.getRight());
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  arrangeTop(d.getRight());
  arrangeFace(d.getBottom());
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  arrangeTop(d.getBottom());
  arrangeFace(d.getBack());
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  arrangeTop(d.getBack());
  arrangeFace(d.getLeft());
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  arrangeTop(d.getTop());
  arrangeFace(d.getFace());
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  roll("NES");
  if (checkDice(d))
    return true;
  return false;
}

bool Dice::checkDice(Dice d) {
  if (top != d.getTop() || face != d.getFace() || right != d.getRight() || left != d.getLeft() || back != d.getBack() || bottom != d.getBottom()) return false;
  return true;
}

int main() {
  int n;
  cin >> n;
  vector<Dice> d;
  int m = n;
  while (m--) {
    int a[6];
    Dice d_tmp;
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5];
    d_tmp.setTop(a[0]);
    d_tmp.setFace(a[1]);
    d_tmp.setRight(a[2]);
    d_tmp.setLeft(a[3]);
    d_tmp.setBack(a[4]);
    d_tmp.setBottom(a[5]);
    d.push_back(d_tmp);
  }
  bool flag = true;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      if(d[i].isDice(d[j])) {
        flag = false;
        break;
      }
    }
  }
  if (flag) cout << "Yes" << el;
  else cout << "No" << el;
  return 0;
}

Measured memory_bytes: 1228