import std.stdio, std.string, std.array, std.conv, std.range;

class Dice6 {
    int[string] dice6;
    int[] _dice6 = new int[6];

    this(int[] _dice6) {
        dice6["top"] = _dice6[0];
        dice6["front"] = _dice6[1];
        dice6["right"] = _dice6[2];
        dice6["left"] = _dice6[3];
        dice6["back"] = _dice6[4];
        dice6["bottom"] = _dice6[5];
    }

    void roll(char c) {
        int tmp = dice6["top"];
        if (c == 'E') {
            dice6["top"] = dice6["left"];
            dice6["left"] = dice6["bottom"];
            dice6["bottom"] = dice6["right"];
            dice6["right"] = tmp;
        } else if (c == 'N') {
            dice6["top"] = dice6["front"];
            dice6["front"] = dice6["bottom"];
            dice6["bottom"] = dice6["back"];
            dice6["back"] = tmp;
        } else if (c == 'S') {
            dice6["top"] = dice6["back"];
            dice6["back"] = dice6["bottom"];
            dice6["bottom"] = dice6["front"];
            dice6["front"] = tmp;
        } else {
            dice6["top"] = dice6["right"];
            dice6["right"] = dice6["bottom"];
            dice6["bottom"] = dice6["left"];
            dice6["left"] = tmp;
        }
    }

    void clockwise() {
        int tmp = dice6["front"];
        dice6["front"] = dice6["right"];
        dice6["right"] = dice6["back"];
        dice6["back"] = dice6["left"];
        dice6["left"] = tmp;
    }

    int surface(string dir) {
        int result;
        if (dir == "top") {
            result = dice6["top"];
        } else if (dir == "front") {
            result = dice6["front"];
        } else if (dir == "right") {
            result = dice6["right"];
        } else if (dir == "left") {
            result = dice6["left"];
        } else if (dir == "back") {
            result = dice6["back"];
        } else {
            result = dice6["bottom"];
        }
        return result;
    }
}

bool areIdentical(Dice6 x, Dice6 y) {
    string[] dirs = ["top", "front", "right", "left", "back", "bottom"];
    foreach (dir; dirs) {
        if (x.surface(dir) != y.surface(dir)) return false;
    }
    return true;
}

void main() {
    int n = readln.chomp.to!int;
    Dice6[] dices;
    foreach (i; 0 .. n) {
        int[] _dices = readln.chomp.split.to!(int[]);
        dices ~= new Dice6(_dices);
    }
    bool ok = true;
    foreach (i; 0 .. n-1) {
        Dice6 dice1 = dices[i];
        foreach (j; i+1 .. n) {
            Dice6 dice2 = dices[j];
            foreach (k; 0 .. 6) {
                foreach (l; 0 .. 4) {
                    if (areIdentical(dice1, dice2)) ok = false;
                    dice2.clockwise;
                }
                k % 2 == 0 ? dice2.roll('E') : dice2.roll('N');
            }
        }
    }
    writeln(ok ? "Yes" : "No");
}
