ans=chk=0
a=[0,2,5,3]
b=[0,1,5,4]
c=[1,2,4,3]
 
def sortdice(dice1,dice2,p,q,r):
    for i in range(4):
        dice1[p[0]],dice1[p[1]],dice1[p[2]],dice1[p[3]]=dice1[p[1]],dice1[p[2]],dice1[p[3]],dice1[p[0]]
        for j in range(4):
            dice1[q[0]],dice1[q[1]],dice1[q[2]],dice1[q[3]]=dice1[q[1]],dice1[q[2]],dice1[q[3]],dice1[q[0]]
            for k in range(4):
                dice1[r[0]],dice1[r[1]],dice1[r[2]],dice1[r[3]]=dice1[r[1]],dice1[r[2]],dice1[r[3]],dice1[r[0]]
                if dice1==dice2:
                    print 'Yes'
                    exit()
    return 0
  
l1=map(int,raw_input().split())
l2=map(int,raw_input().split())
sortdice(l1,l2,a,b,c)
print 'No'



### FIXED CODE ###

import sys
import math
 
def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S
 
def float_to_str(num):
    return str("{:.10f}".format(num))
 
def list_input(tp):
    return map(tp, str_input().split())
 
# # # # # # # # # # # # # # # # # # # # # # # # #
 
class Dice:
    pip = [0 for i in xrange(6)]
 
    def __init__(self, arg):
        self.pip = arg
 
    def rollDir(self, dr):
        nextPip = [0 for i in xrange(6)]
        if dr == "N":
            nextPip[0] = self.pip[1]
            nextPip[1] = self.pip[5]
            nextPip[2] = self.pip[2]
            nextPip[3] = self.pip[3]
            nextPip[4] = self.pip[0]
            nextPip[5] = self.pip[4]
        elif dr == "E":
            nextPip[0] = self.pip[3]
            nextPip[1] = self.pip[1]
            nextPip[2] = self.pip[0]
            nextPip[3] = self.pip[5]
            nextPip[4] = self.pip[4]
            nextPip[5] = self.pip[2]
        self.pip = nextPip
 
    def roll(self, dr):
        if dr == "N" or dr == "E":
            self.rollDir(dr)
        elif dr == "S":
            self.rollDir("N")
            self.rollDir("N")
            self.rollDir("N")
        elif dr == "W":
            self.rollDir("E")
            self.rollDir("E")
            self.rollDir("E")
 
    def check(self, a, b):
        while self.pip[0] != a:
            if self.pip[2] != a and self.pip[3] != a:
                self.roll("N")
            else:
                self.roll("N")
                self.roll("W")
                self.roll("S")
 
        while self.pip[1] != b:
            self.roll("N")
            self.roll("W")
            self.roll("S")
        return self.pip[2]
 
def sameCheck(dice1, dice2):
    for i in xrange(4):
        for j in xrange(4):
            if dice1.pip == dice2.pip:
                return True
            dice2.roll("E")
        dice2.roll("N")
    dice2.roll("N")
    dice2.roll("E")
    dice2.roll("S")
    for i in xrange(4):
        if dice1.pip == dice2.pip:
            return True
        dice2.roll("E")
    dice2.roll("N")
    dice2.roll("E")
    dice2.roll("E")
    dice2.roll("S")
    for i in xrange(4):
        if dice1.pip == dice2.pip:
            return True
        dice2.roll("E")
    return False
 
n = input()
dice = []
 
for i in xrange(n):
    tmp_dice = Dice(list_input(int))
    dice.append(tmp_dice)
 
for i in xrange(n):
    for j in xrange(i+1, n):
        if sameCheck(dice[i], dice[j]):
            print "No"
            sys.exit()
 
print "Yes"