using System;
using System.Collections.Generic;

class Program {
    class DICE {
        public int top = 0;
        public int right = 0;
        int left = 0;
        int front = 0;
        public int back = 0;
        int bottom = 0;

        private List<string> ptnList = new List<string>();

        public DICE(string[] no) {
            top = int.Parse(no[0]);
            back = int.Parse(no[1]);
            right = int.Parse(no[2]);
            left = int.Parse(no[3]);
            front = int.Parse(no[4]);
            bottom = int.Parse(no[5]);

            LoadPatternList(no);
        }

        private void LoadPatternList(string[] no) {
            ptnList.Clear();

            ptnList.Add(string.Format("{0},{1},{2},{3},{4},{5}", top, right, front, left, back, bottom));
            ptnList.Add(string.Format("{0},{2},{3},{4},{1},{5}", top, right, front, left, back, bottom));
            ptnList.Add(string.Format("{0},{3},{4},{1},{2},{5}", top, right, front, left, back, bottom));
            ptnList.Add(string.Format("{0},{4},{1},{2},{3},{5}", top, right, front, left, back, bottom));

            ptnList.Add(string.Format("{5},{1},{4},{3},{2},{0}", top, right, front, left, back, bottom));
            ptnList.Add(string.Format("{5},{4},{3},{2},{1},{0}", top, right, front, left, back, bottom));
            ptnList.Add(string.Format("{5},{3},{2},{1},{4},{0}", top, right, front, left, back, bottom));
            ptnList.Add(string.Format("{5},{2},{1},{4},{3},{0}", top, right, front, left, back, bottom));

            ptnList.Add(string.Format("{0},{1},{2},{3},{4},{5}", right, top, back, bottom, front, left));
            ptnList.Add(string.Format("{0},{2},{3},{4},{1},{5}", right, top, back, bottom, front, left));
            ptnList.Add(string.Format("{0},{3},{4},{1},{2},{5}", right, top, back, bottom, front, left));
            ptnList.Add(string.Format("{0},{4},{1},{2},{3},{5}", right, top, back, bottom, front, left));

            ptnList.Add(string.Format("{5},{1},{4},{3},{2},{0}", right, top, back, bottom, front, left));
            ptnList.Add(string.Format("{5},{4},{3},{2},{1},{0}", right, top, back, bottom, front, left));
            ptnList.Add(string.Format("{5},{3},{2},{1},{4},{0}", right, top, back, bottom, front, left));
            ptnList.Add(string.Format("{5},{2},{1},{4},{3},{0}", right, top, back, bottom, front, left));

            ptnList.Add(string.Format("{0},{1},{2},{3},{4},{5}", front, top, right, bottom, left, back));
            ptnList.Add(string.Format("{0},{2},{3},{4},{1},{5}", front, top, right, bottom, left, back));
            ptnList.Add(string.Format("{0},{3},{4},{1},{2},{5}", front, top, right, bottom, left, back));
            ptnList.Add(string.Format("{0},{4},{1},{2},{3},{5}", front, top, right, bottom, left, back));

            ptnList.Add(string.Format("{5},{1},{4},{3},{2},{0}", front, top, right, bottom, left, back));
            ptnList.Add(string.Format("{5},{4},{3},{2},{1},{0}", front, top, right, bottom, left, back));
            ptnList.Add(string.Format("{5},{3},{2},{1},{4},{0}", front, top, right, bottom, left, back));
            ptnList.Add(string.Format("{5},{2},{1},{4},{3},{0}", front, top, right, bottom, left, back));

        }

        public bool Compare(DICE x) {
            string wk = string.Format("{0},{1},{2},{3},{4},{5}", x.top, x.right, x.front, x.left, x.back, x.bottom);
            return ptnList.Contains(wk);
        }
    }

    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());

        List<DICE> diceList = new List<DICE>();

        for (int i = 0; i < n; i++) {
            string[] x = Console.ReadLine().Split(' ');
            diceList.Add(new DICE(x));
        }

        for (int i = 0; i < diceList.Count - 1; i++) {
            for (int k = i + 1; k < diceList.Count; k++) {
                if (diceList[i].Compare(diceList[k])) {
                    Console.WriteLine("No");
                    return;
                }
            }
        }
        Console.WriteLine("Yes");
        return;
    }
}


Measured memory_bytes: 17992