#include <cstdio>
#include <stdlib.h>

int main()
{
    int s[600];
    int t[6];
    int c = 0;
    char h[4] = {'N', 'S', 'W', 'E'};
    int n;
    bool a = false;
    scanf("%d", &n);
    for (int i = 0; i < 6 * n; i++)
    {
        scanf("%d", &s[i]);
    }
    for (int i = 0; i < n; i++)
    {
        while (1)
        {
            int k = rand() % 4;
            if (h[k] == 'N')
            {
                t[4] = s[0 + i * 6];
                t[0] = s[1 + i * 6];
                t[1] = s[5 + i * 6];
                t[5] = s[4 + i * 6];
                t[2] = s[2 + i * 6];
                t[3] = s[3 + i * 6];
            }
            if (h[k] == 'S')
            {
                t[0] = s[4 + i * 6];
                t[1] = s[0 + i * 6];
                t[5] = s[1 + i * 6];
                t[4] = s[5 + i * 6];
                t[2] = s[2 + i * 6];
                t[3] = s[3 + i * 6];
            }
            if (h[k] == 'W')
            {
                t[0] = s[2 + i * 6];
                t[2] = s[5 + i * 6];
                t[5] = s[3 + i * 6];
                t[3] = s[0 + i * 6];
                t[1] = s[1 + i * 6];
                t[4] = s[4 + i * 6];
            }
            if (h[k] == 'E')
            {
                t[2] = s[0 + i * 6];
                t[5] = s[2 + i * 6];
                t[3] = s[5 + i * 6];
                t[0] = s[3 + i * 6];
                t[1] = s[1 + i * 6];
                t[4] = s[4 + i * 6];
            }
            for (int j = 0; j < 6; j++)
            {
                s[j + i * 6] = t[j];
            }
            for (int j = i + 1; j < n; j++)
            {
                if (s[0 + i * 6] == s[0 + j * 6] && s[1 + i * 6] == s[1 + j * 6] && s[2 + i * 6] == s[2 + j * 6] && s[3 + i * 6] == s[3 + j * 6] && s[4 + i * 6] == s[4 + j * 6] && s[5 + i * 6] == s[5 + j * 6])
                {
                    a = true;
                    break;
                }
            }
            if (c == 1000)
            {
                break;
            }
            c += 1;
        }
    }

    if (a == false)
    {
        printf("Yes\n");
    }
    if (a == true)
    {
        printf("No\n");
    }
}

#include<iostream>

using namespace std;


class DICE {
	enum {
		Top,
		Front,
		Right,
		Left,
		Rear,
		Bottom
	};

	void Roll(const char*Directions) {
		for (int i = 0; Directions[i] != '\0'; i++) {
			Roll(Directions[i]);
		}
	}

	void Roll(const char Direction) {
		int tmpTop = Num[Top];

		switch (Direction) {
		case'E':
			Num[Top] = Num[Left];
			Num[Left] = Num[Bottom];
			Num[Bottom] = Num[Right];
			Num[Right] = Num[tmpTop];
			break;
		case'N':
			Num[Top] = Num[Front];
			Num[Front] = Num[Bottom];
			Num[Bottom] = Num[Rear];
			Num[Rear] = tmpTop;
			break;
		case'S':
			Num[Top] = Num[Rear];
			Num[Rear] = Num[Bottom];
			Num[Bottom] = Num[Front];
			Num[Front] = tmpTop;
			break;
		case'W':
			Num[Top] = Num[Right];
			Num[Right] = Num[Bottom];
			Num[Bottom] = Num[Left];
			Num[Left] = tmpTop;
			break;
		}
	}

	bool SameDiceDirectionFlag(DICE Dice) {
		for (int i = 0; i < 6; i++) {
			if (Num[i] != Dice.Num[i])return false;
		}
		return true;
	}

public:
	int Num[6];

	bool SameDiceNoneDirectionFlag(DICE Dice) {
		const char Directions[][3] = { "N","N","N","NW","WW","\0" };

		for (int i = 0; i < 6; i++) {
			if (Num[Top] == Dice.Num[Top]) {
				for (int j = 0; j < 4; j++) {
					if (SameDiceDirectionFlag(Dice))return true;

					int tmpFront = Dice.Num[Front];
					Dice.Num[Front] = Dice.Num[Right];
					Dice.Num[Right] = Dice.Num[Rear];
					Dice.Num[Rear] = Dice.Num[Left];
					Dice.Num[Left] = tmpFront;
				}
			}

			Dice.Roll(Directions[i]);
		}

		return false;
	}

};

int main() {
	DICE Dice[101];
	int n;

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 6; j++)cin >> Dice[i].Num[j];
	}

	for (int i = 1; i < n; i++) {
		if (Dice[0].SameDiceNoneDirectionFlag(Dice[i])) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}