class dice:

	def __init__(self,data):

		self.faces = data

	

	def turn(self,direction):

		if direction == 'N':

			idx = [1,5,2,3,0,4]

			self.faces = [self.faces[i] for i in idx]

		elif direction == 'S':

			[self.turn('N') for i in range(3)]

		elif direction == 'E':

			idx = [3,1,0,5,4,2]

			self.faces = [self.faces[i] for i in idx]

		elif direction == 'W':

			[self.turn('E') for i in range(3)]

		elif direction == 'c':

			self.turn('N')

			self.turn('W')

			self.turn('S')



def isunique(d1,d2):

	for o in 'cccWcccEcccNcccWcccWccc':

		if d1.faces == d2.faces:

			break

		else:

			d2.turn(o)

	if d1.faces == d2.faces:

		return False

	else:

		return True



if __name__ == '__main__':

	from itertools import combinations

	n = int(eval(input()))

	dices = []

	for i in range(n):

		dices.append(dice([int(s) for s in input().split()]))

	ans = True

	check = [isunique(d1,d2) for d1,d2 in combinations(dices,2)]

	if all(check):

		print('Yes')

	else:

		print('No')
class dice:

	def __init__(self,data):

		self.faces = data

	

	def turn(self,direction):

		if direction == 'N':

			idx = [1,5,2,3,0,4]

			self.faces = [self.faces[i] for i in idx]

		elif direction == 'S':

			[self.turn('N') for i in range(3)]

		elif direction == 'E':

			idx = [3,1,0,5,4,2]

			self.faces = [self.faces[i] for i in idx]

		elif direction == 'W':

			[self.turn('E') for i in range(3)]

		elif direction == 'c':

			self.turn('N')

			self.turn('W')

			self.turn('S')



def min_side(dice):

	num = [int(''.join([str(i) for i in dice.faces]))]

	for o in 'cccWcccEcccNcccWcccWccc':

		dice.turn(o)

		num.append(int(''.join([str(i) for i in dice.faces])))

	return min(num)



if __name__ == '__main__':

	from itertools import combinations

	n = int(eval(input()))

	dices = []

	for i in range(n):

		dices.append(dice([int(s) for s in input().split()]))

	ans = True

	mins1 = [min_side(d) for d in dices]

	mins2 = list(set(mins1))

	if len(mins1) == len(mins2):

		print('Yes')

	else:

		print('No')
class dice:
    def __init__(self, data):
        self.faces = data

    def turn(self, direction):
        if direction == "N":
            idx = [1, 5, 2, 3, 0, 4]
            self.faces = [self.faces[i] for i in idx]
        elif direction == "S":
            [self.turn("N") for i in range(3)]
        elif direction == "E":
            idx = [3, 1, 0, 5, 4, 2]
            self.faces = [self.faces[i] for i in idx]
        elif direction == "W":
            [self.turn("E") for i in range(3)]
        elif direction == "c":
            self.turn("N")
            self.turn("W")
            self.turn("S")


def isunique(d1, d2):
    for o in "cccWcccEcccNcccWcccWccc":
        if d1.faces == d2.faces:
            break
        else:
            d2.turn(o)
    if d1.faces == d2.faces:
        return False
    else:
        return True


if __name__ == "__main__":
    from itertools import combinations

    n = int(eval(input()))
    dices = []
    for i in range(n):
        dices.append(dice([int(s) for s in input().split()]))
    ans = True
    check = [isunique(d1, d2) for d1, d2 in combinations(dices, 2)]
    if all(check):
        print("Yes")
    else:
        print("No")

class dice:
    def __init__(self, data):
        self.faces = data

    def turn(self, direction):
        if direction == "N":
            idx = [1, 5, 2, 3, 0, 4]
            self.faces = [self.faces[i] for i in idx]
        elif direction == "S":
            [self.turn("N") for i in range(3)]
        elif direction == "E":
            idx = [3, 1, 0, 5, 4, 2]
            self.faces = [self.faces[i] for i in idx]
        elif direction == "W":
            [self.turn("E") for i in range(3)]
        elif direction == "c":
            self.turn("N")
            self.turn("W")
            self.turn("S")


def min_side(dice):
    num = [int("".join([str(i) for i in dice.faces]))]
    for o in "cccWcccEcccNcccWcccWccc":
        dice.turn(o)
        num.append(int("".join([str(i) for i in dice.faces])))
    return min(num)


if __name__ == "__main__":
    from itertools import combinations

    n = int(eval(input()))
    dices = []
    for i in range(n):
        dices.append(dice([int(s) for s in input().split()]))
    ans = True
    mins1 = [min_side(d) for d in dices]
    mins2 = list(set(mins1))
    if len(mins1) == len(mins2):
        print("Yes")
    else:
        print("No")

-def isunique(d1, d2): +def min_side(dice): +    num = [int("".join([str(i) for i in dice.faces]))] -        if d1.faces == d2.faces: -            break -        else: -            d2.turn(o) -    if d1.faces == d2.faces: -        return False -    else: -        return True +        dice.turn(o) +        num.append(int("".join([str(i) for i in dice.faces]))) +    return min(num) -    check = [isunique(d1, d2) for d1, d2 in combinations(dices, 2)] -    if all(check): +    mins1 = [min_side(d) for d in dices] +    mins2 = list(set(mins1)) +    if len(mins1) == len(mins2):