Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Dice IV

 Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.

Input

  In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.

Output

  Print "Yes" if given dices are all different, otherwise "No" in a line.

Constraints

$2 \leq n \leq 100$

$0 \leq $ the integer assigned to a face $ \leq 100$

Sample Input 1

3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1

Sample Output 1

No

Sample Input 2 

3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6

Sample Output 2

Yes



Sample input:
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1


Sample output:
No

Submission status: Time Limit Exceeded

Solution code:
import random


class Dice(object):
    def __init__(self):
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6

    def __init__(self, faces):
        self.t = faces[0]
        self.s = faces[1]
        self.e = faces[2]
        self.w = faces[3]
        self.n = faces[4]
        self.b = faces[5]

    def roll(self, direct):
        if direct == 0:
            self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
        elif direct == 1:
            self.t, self.w, self.b, self.e = self.e, self.t, self.w, self.b
        elif direct == 2:
            self.n, self.w, self.s, self.e = self.w, self.s, self.e, self.n

    def is_equal(self, dice):
        if self.t == dice.t and self.s == dice.s and self.e == dice.e and self.w == dice.w and self.n == dice.n and self.b == dice.b:
            return True
        else:
            return False

n = int(input())
dice_list = []
flag_list = []
for _ in range(n):
    flag = False
    faces = list(map(int, input().split()))
    dice_list.append(Dice(faces))

    if n == 0:
        continue

    dice_a = dice_list[-1]
    for i in range(len(dice_list) - 1):
        dice_b = dice_list[i]

        for i in range(10000):
            dice_b.roll(random.randint(0, 3))
            if dice_a.is_equal(dice_b):
                flag = True
                break

        flag_list.append(flag)

if any(flag_list):
    print('No')
else:
    print('Yes')

Submission status: Time Limit Exceeded

Solution code:
import random


class Dice(object):
    def __init__(self):
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6

    def __init__(self, faces):
        self.t = faces[0]
        self.s = faces[1]
        self.e = faces[2]
        self.w = faces[3]
        self.n = faces[4]
        self.b = faces[5]

    def roll(self, direct):
        if direct == 0:
            self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
        elif direct == 1:
            self.t, self.w, self.b, self.e = self.e, self.t, self.w, self.b
        elif direct == 2:
            self.n, self.w, self.s, self.e = self.w, self.s, self.e, self.n

    def is_equal(self, dice):
        if self.t == dice.t and self.s == dice.s and self.e == dice.e and self.w == dice.w and self.n == dice.n and self.b == dice.b:
            return True
        else:
            return False

n = int(input())
dice_list = []
flag_list = []
for _ in range(n):
    flag = False
    faces = list(map(int, input().split()))
    dice_list.append(Dice(faces))

    if n == 0:
        continue

    dice_a = dice_list[-1]
    for i in range(len(dice_list) - 1):
        dice_b = dice_list[i]

        for i in range(1000):
            dice_b.roll(random.randint(0, 3))
            if dice_a.is_equal(dice_b):
                flag = True
                break

        flag_list.append(flag)

if any(flag_list):
    print('No')
else:
    print('Yes')

Submission status: Time Limit Exceeded

Solution code:
import random


class Dice(object):
    def __init__(self):
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6

    def __init__(self, faces):
        self.t = faces[0]
        self.s = faces[1]
        self.e = faces[2]
        self.w = faces[3]
        self.n = faces[4]
        self.b = faces[5]

    def roll(self, direct):
        if direct == 0:
            self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
        elif direct == 1:
            self.t, self.w, self.b, self.e = self.e, self.t, self.w, self.b
        elif direct == 2:
            self.n, self.w, self.s, self.e = self.w, self.s, self.e, self.n

    def is_equal(self, dice):
        if self.t == dice.t and self.s == dice.s and self.e == dice.e and self.w == dice.w and self.n == dice.n and self.b == dice.b:
            return True
        else:
            return False

n = int(input())
dice_list = []
flag_list = []
for _ in range(n):
    flag = False
    faces = list(map(int, input().split()))
    dice_list.append(Dice(faces))

    if n == 0:
        continue

    dice_a = dice_list[-1]
    for i in range(len(dice_list) - 1):
        dice_b = dice_list[i]

        for i in range(500):
            dice_b.roll(random.randint(0, 3))
            if dice_a.is_equal(dice_b):
                flag = True
                break

        flag_list.append(flag)

if any(flag_list):
    print('No')
else:
    print('Yes')

Submission status: Time Limit Exceeded

Solution code:
import random
class Dice:
    def __init__(self, num_list):
        self.top = num_list[0]
        self.dside = num_list[1]
        self.rside = num_list[2]
        self.lside = num_list[3]
        self.uside = num_list[4]
        self.bottom = num_list[5]
    def north(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.dside, 
            self.bottom, self.uside, self.top)
    def east(self):
        (self.top, self.lside, self.bottom, self.rside) = (self.lside,
            self.bottom, self.rside, self.top)
    def south(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.uside, 
            self.top, self.dside, self.bottom)

n = int(input())
num = [list(map(int, input().split())) for i in range(n)]
dice = [Dice(num[i]) for i in range(n)]
for idx1, i in enumerate(dice):
    for idx2, j in enumerate(dice):
        if idx2 <= idx1:
            continue
        elif len(set(num[0])) < 4:
            while(i.top != j.top or i.rside != j.rside
                  or i.dside != j.dside):
                mode = random.randint(0, 2)
                if mode==0:
                    j.north()
                elif mode==1:
                    j.east()
                else:
                    j.south()
        else:
            while i.top != j.top or i.rside != j.rside:
                mode = random.randint(0, 2)
                if mode==0:
                    j.north()
                elif mode==1:
                    j.east()
                else:
                    j.south()
        if (i.bottom == j.bottom and i.lside == j.lside 
            and i.dside == j.dside):
            print("No")
            break
    else:
        continue
    break
else:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import random
class Dice:
    def __init__(self, num_list):
        self.top = num_list[0]
        self.dside = num_list[1]
        self.rside = num_list[2]
        self.lside = num_list[3]
        self.uside = num_list[4]
        self.bottom = num_list[5]
        self.dlist = num_list
    def north(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.dside, 
            self.bottom, self.uside, self.top)
    def east(self):
        (self.top, self.lside, self.bottom, self.rside) = (self.lside,
            self.bottom, self.rside, self.top)
    def south(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.uside, 
            self.top, self.dside, self.bottom)

n = int(input())
num = [list(map(int, input().split())) for i in range(n)]
dice = [Dice(num[i]) for i in range(n)]
for idx1, i in enumerate(dice):
    for idx2, j in enumerate(dice):
        if idx2 <= idx1:
            continue
        elif len(set(num[0])) < 4:
            while(i.top != j.top or i.rside != j.rside
                  or i.dside != j.dside):
                mode = random.randint(0, 2)
                if mode == 0:
                    j.north()
                elif mode == 1:
                    j.east()
                else:
                    j.south()
        else:
            while(i.top != j.top or 
                 (i.rside != j.rside and i.uside != j.uside)):
                mode = random.randint(0, 2)
                if mode == 0:
                    j.north()
                elif mode == 1:
                    j.east()
                elif mode == 2:
                    j.south()
        if (i.bottom == j.bottom and i.lside == j.lside 
            and i.dside == j.dside):
            print("No")
            break
    else:
        continue
    break
else:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
# Dice I - IV

class Dice:
    def __init__(self, a1, a2, a3, a4, a5, a6):
        # サイコロを縦横にたどると書いてある数字(index1は真上、index3は真下の数字)
        self.face = [a1, a2, a3, a4, a5, a6]
        self.v = [a5, a1, a2, a6] # 縦方向
        self.h = [a4, a1, a3, a6] # 横方向
        self.det = 1
        # print(self.v, self.h)

    # サイコロの上面の数字を表示
    def top(self):
        return self.v[1]

    # サイコロを北方向に倒す
    def north(self):
        newV = [self.v[1], self.v[2], self.v[3], self.v[0]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    # サイコロを南方向に倒す
    def south(self):
        newV = [self.v[3], self.v[0], self.v[1], self.v[2]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    # サイコロを東方向に倒す
    def east(self):
        newH = [self.h[3], self.h[0], self.h[1], self.h[2]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

    # サイコロを西方向に倒す
    def west(self):
        newH = [self.h[1], self.h[2], self.h[3], self.h[0]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

    def searchFace(self, a):
        b = 0
        for i in range(6):
            if a == self.face[i]:
                # print('一致しました')
                b = i + 1
        return b

    def detJudge(self, x): # a は 1 から 6 のどれか
        y = int(7 / 2 - abs(x - 7 / 2))
        if x != y:
            self.det *= -1
        # print(self.det)
        return y

    def rightSide(self, top, front):
        r = 0
        if top == 1 and front == 2:
            r = 3
        elif top == 2 and front == 3:
            r = 1
        elif top == 3 and front == 1:
            r = 2
        elif top == 1 and front == 3:
            r = 5
        elif top == 3 and front == 2:
            r = 6
        elif top == 2 and front == 1:
            r = 4
        if self.det == -1:
            r = 7 - r
        return r

diceAmount = int(input())
dices = []
for i in range(diceAmount):
    d = [int(j) for j in input().rstrip().split()]
    dice = Dice(d[0], d[1], d[2], d[3], d[4], d[5])
    dices.append(dice)
# print(dices)

# Dice I
# command = list(input().rstrip())
# print(command)

# Dice II
# for i, a in enumerate(command):
#     if a == 'N':
#         dice1.north()
#     elif a == 'S':
#         dice1.south()
#     elif a == 'E':
#         dice1.east()
#     elif a == 'W':
#         dice1.west()
# print(dice1.top())
# questionAmount = int(input())
# for i in range(questionAmount):
    # # Initialize det
    # dice1.det = 1
    # question = [int(i) for i in input().rstrip().split()]
    # a = dice1.searchFace(question[0])
    # b = dice1.searchFace(question[1])
    # # print(a, b)
    # top = dice1.detJudge(a)
    # front = dice1.detJudge(b)
    # # print(top, front)
    # position = dice1.rightSide(top, front)
    # answer = dice1.face[position - 1]
    # print(answer)

# Dice III
# import random
# # print(dice1.face)
# # print(dice2.face)
# yesCount = 0
# i = 0
# while yesCount == 0 and i < 1000:
    # j = random.randint(0, 3)
    # if j == 0:
        # dice2.north()
    # elif j == 1:
        # dice2.south()
    # elif j == 2:
        # dice2.east()
    # elif j == 3:
        # dice2.west()
    # if (dice1.v == dice2.v and dice1.h == dice2.h) or ([dice1.v[2], dice1.v[1], dice1.v[0], dice1.v[3]] == [dice2.v[2], dice2.v[1], dice2.v[0], dice2.v[3]] and [dice1.h[2], dice1.h[1], dice1.h[0], dice1.h[3]] == [dice2.h[2], dice2.h[1], dice2.h[0], dice2.h[3]]):
        # yesCount += 1
        # # print('一致')
    # i += 1
# if yesCount >= 1:
    # print('Yes')
# else:
    # print('No')

# Dice IV
import random
match = 0
diceCount = 1
while match == 0 and diceCount < diceAmount:
    for d2 in range(1, diceAmount):
        # print(d2)
        i = 0
        while match == 0 and i < 1000:
            j = random.randint(0, 3)
            if j == 0:
                dices[d2].north()
            elif j == 1:
                dices[d2].south()
            elif j == 2:
                dices[d2].east()
            elif j == 3:
                dices[d2].west()
            for d1 in range(d2):
                if (dices[d1].v == dices[d2].v and dices[d1].h == dices[d2].h) or ([dices[d1].v[2], dices[d1].v[1], dices[d1].v[0], dices[d1].v[3]] == [dices[d2].v[2], dices[d2].v[1], dices[d2].v[0], dices[d2].v[3]] and [dices[d1].h[2], dices[d1].h[1], dices[d1].h[0], dices[d1].h[3]] == [dices[d2].h[2], dices[d2].h[1], dices[d2].h[0], dices[d2].h[3]]):
                    match += 1
                    # print('一致')
            i += 1
    diceCount += 1
if match >= 1:
    print('No')
else:
    print('Yes')

Submission status: Time Limit Exceeded

Solution code:
# Dice I - IV

class Dice:
    def __init__(self, a1, a2, a3, a4, a5, a6):
        # サイコロを縦横にたどると書いてある数字(index1は真上、index3は真下の数字)
        self.face = [a1, a2, a3, a4, a5, a6]
        self.v = [a5, a1, a2, a6] # 縦方向
        self.h = [a4, a1, a3, a6] # 横方向
        self.det = 1
        # print(self.v, self.h)

    # サイコロの上面の数字を表示
    def top(self):
        return self.v[1]

    # サイコロを北方向に倒す
    def north(self):
        newV = [self.v[1], self.v[2], self.v[3], self.v[0]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    # サイコロを南方向に倒す
    def south(self):
        newV = [self.v[3], self.v[0], self.v[1], self.v[2]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    # サイコロを東方向に倒す
    def east(self):
        newH = [self.h[3], self.h[0], self.h[1], self.h[2]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

    # サイコロを西方向に倒す
    def west(self):
        newH = [self.h[1], self.h[2], self.h[3], self.h[0]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

    def searchFace(self, a):
        b = 0
        for i in range(6):
            if a == self.face[i]:
                # print('一致しました')
                b = i + 1
        return b

    def detJudge(self, x): # a は 1 から 6 のどれか
        y = int(7 / 2 - abs(x - 7 / 2))
        if x != y:
            self.det *= -1
        # print(self.det)
        return y

    def rightSide(self, top, front):
        r = 0
        if top == 1 and front == 2:
            r = 3
        elif top == 2 and front == 3:
            r = 1
        elif top == 3 and front == 1:
            r = 2
        elif top == 1 and front == 3:
            r = 5
        elif top == 3 and front == 2:
            r = 6
        elif top == 2 and front == 1:
            r = 4
        if self.det == -1:
            r = 7 - r
        return r

diceAmount = int(input())
dices = []
for i in range(diceAmount):
    d = [int(j) for j in input().rstrip().split()]
    dice = Dice(d[0], d[1], d[2], d[3], d[4], d[5])
    dices.append(dice)
# print(dices)

# Dice I
# command = list(input().rstrip())
# print(command)

# Dice II
# for i, a in enumerate(command):
#     if a == 'N':
#         dice1.north()
#     elif a == 'S':
#         dice1.south()
#     elif a == 'E':
#         dice1.east()
#     elif a == 'W':
#         dice1.west()
# print(dice1.top())
# questionAmount = int(input())
# for i in range(questionAmount):
    # # Initialize det
    # dice1.det = 1
    # question = [int(i) for i in input().rstrip().split()]
    # a = dice1.searchFace(question[0])
    # b = dice1.searchFace(question[1])
    # # print(a, b)
    # top = dice1.detJudge(a)
    # front = dice1.detJudge(b)
    # # print(top, front)
    # position = dice1.rightSide(top, front)
    # answer = dice1.face[position - 1]
    # print(answer)

# Dice III
# import random
# # print(dice1.face)
# # print(dice2.face)
# yesCount = 0
# i = 0
# while yesCount == 0 and i < 100:
    # j = random.randint(0, 3)
    # if j == 0:
        # dice2.north()
    # elif j == 1:
        # dice2.south()
    # elif j == 2:
        # dice2.east()
    # elif j == 3:
        # dice2.west()
    # if (dice1.v == dice2.v and dice1.h == dice2.h) or ([dice1.v[2], dice1.v[1], dice1.v[0], dice1.v[3]] == [dice2.v[2], dice2.v[1], dice2.v[0], dice2.v[3]] and [dice1.h[2], dice1.h[1], dice1.h[0], dice1.h[3]] == [dice2.h[2], dice2.h[1], dice2.h[0], dice2.h[3]]):
        # yesCount += 1
        # # print('一致')
    # i += 1
# if yesCount >= 1:
    # print('Yes')
# else:
    # print('No')

# Dice IV
import random
match = 0
diceCount = 1
while match == 0 and diceCount < diceAmount:
    for d2 in range(1, diceAmount):
        # print(d2)
        i = 0
        while match == 0 and i < 1000:
            j = random.randint(0, 3)
            if j == 0:
                dices[d2].north()
            elif j == 1:
                dices[d2].south()
            elif j == 2:
                dices[d2].east()
            elif j == 3:
                dices[d2].west()
            for d1 in range(d2):
                if (dices[d1].v == dices[d2].v and dices[d1].h == dices[d2].h) or ([dices[d1].v[2], dices[d1].v[1], dices[d1].v[0], dices[d1].v[3]] == [dices[d2].v[2], dices[d2].v[1], dices[d2].v[0], dices[d2].v[3]] and [dices[d1].h[2], dices[d1].h[1], dices[d1].h[0], dices[d1].h[3]] == [dices[d2].h[2], dices[d2].h[1], dices[d2].h[0], dices[d2].h[3]]):
                    match += 1
                    # print('一致')
            i += 1
    diceCount += 1
if match >= 1:
    print('No')
else:
    print('Yes')

Submission status: Time Limit Exceeded

Solution code:
# Dice I - IV

class Dice:
    def __init__(self, a1, a2, a3, a4, a5, a6):
        # サイコロを縦横にたどると書いてある数字(index1は真上、index3は真下の数字)
        self.face = [a1, a2, a3, a4, a5, a6]
        self.v = [a5, a1, a2, a6] # 縦方向
        self.h = [a4, a1, a3, a6] # 横方向
        self.det = 1
        # print(self.v, self.h)

    # サイコロの上面の数字を表示
    def top(self):
        return self.v[1]

    # サイコロを北方向に倒す
    def north(self):
        newV = [self.v[1], self.v[2], self.v[3], self.v[0]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    # サイコロを南方向に倒す
    def south(self):
        newV = [self.v[3], self.v[0], self.v[1], self.v[2]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    # サイコロを東方向に倒す
    def east(self):
        newH = [self.h[3], self.h[0], self.h[1], self.h[2]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

    # サイコロを西方向に倒す
    def west(self):
        newH = [self.h[1], self.h[2], self.h[3], self.h[0]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

    def searchFace(self, a):
        b = 0
        for i in range(6):
            if a == self.face[i]:
                # print('一致しました')
                b = i + 1
        return b

    def detJudge(self, x): # a は 1 から 6 のどれか
        y = int(7 / 2 - abs(x - 7 / 2))
        if x != y:
            self.det *= -1
        # print(self.det)
        return y

    def rightSide(self, top, front):
        r = 0
        if top == 1 and front == 2:
            r = 3
        elif top == 2 and front == 3:
            r = 1
        elif top == 3 and front == 1:
            r = 2
        elif top == 1 and front == 3:
            r = 5
        elif top == 3 and front == 2:
            r = 6
        elif top == 2 and front == 1:
            r = 4
        if self.det == -1:
            r = 7 - r
        return r

diceAmount = int(input())
dices = []
for i in range(diceAmount):
    d = [int(j) for j in input().rstrip().split()]
    dice = Dice(d[0], d[1], d[2], d[3], d[4], d[5])
    dices.append(dice)
# print(dices)

# Dice I
# command = list(input().rstrip())
# print(command)

# Dice II
# for i, a in enumerate(command):
#     if a == 'N':
#         dice1.north()
#     elif a == 'S':
#         dice1.south()
#     elif a == 'E':
#         dice1.east()
#     elif a == 'W':
#         dice1.west()
# print(dice1.top())
# questionAmount = int(input())
# for i in range(questionAmount):
    # # Initialize det
    # dice1.det = 1
    # question = [int(i) for i in input().rstrip().split()]
    # a = dice1.searchFace(question[0])
    # b = dice1.searchFace(question[1])
    # # print(a, b)
    # top = dice1.detJudge(a)
    # front = dice1.detJudge(b)
    # # print(top, front)
    # position = dice1.rightSide(top, front)
    # answer = dice1.face[position - 1]
    # print(answer)

# Dice III
# import random
# # print(dice1.face)
# # print(dice2.face)
# yesCount = 0
# i = 0
# while yesCount == 0 and i < 1000:
    # j = random.randint(0, 3)
    # if j == 0:
        # dice2.north()
    # elif j == 1:
        # dice2.south()
    # elif j == 2:
        # dice2.east()
    # elif j == 3:
        # dice2.west()
    # if (dice1.v == dice2.v and dice1.h == dice2.h) or ([dice1.v[2], dice1.v[1], dice1.v[0], dice1.v[3]] == [dice2.v[2], dice2.v[1], dice2.v[0], dice2.v[3]] and [dice1.h[2], dice1.h[1], dice1.h[0], dice1.h[3]] == [dice2.h[2], dice2.h[1], dice2.h[0], dice2.h[3]]):
        # yesCount += 1
        # # print('一致')
    # i += 1
# if yesCount >= 1:
    # print('Yes')
# else:
    # print('No')

# Dice IV
import random
match = 0
diceCount = 1
while match == 0 and diceCount < diceAmount:
    for d2 in range(1, diceAmount):
        # print(d2)
        i = 0
        while match == 0 and i < 100:
            j = random.randint(0, 3)
            if j == 0:
                dices[d2].north()
            elif j == 1:
                dices[d2].south()
            elif j == 2:
                dices[d2].east()
            elif j == 3:
                dices[d2].west()
            for d1 in range(d2):
                if (dices[d1].v == dices[d2].v and dices[d1].h == dices[d2].h):
                    match += 1
                    # print('一致')
            i += 1
    diceCount += 1
if match >= 1:
    print('No')
else:
    print('Yes')

Submission status: Time Limit Exceeded

Solution code:
# Dice I - IV

class Dice:
    def __init__(self, a1, a2, a3, a4, a5, a6):
        # サイコロを縦横にたどると書いてある数字(index1は真上、index3は真下の数字)
        self.face = [a1, a2, a3, a4, a5, a6]
        self.v = [a5, a1, a2, a6] # 縦方向
        self.h = [a4, a1, a3, a6] # 横方向
        self.det = 1
        # print(self.v, self.h)

    # サイコロの上面の数字を表示
    def top(self):
        return self.v[1]

    # サイコロを北方向に倒す
    def north(self):
        newV = [self.v[1], self.v[2], self.v[3], self.v[0]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    # サイコロを南方向に倒す
    def south(self):
        newV = [self.v[3], self.v[0], self.v[1], self.v[2]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    # サイコロを東方向に倒す
    def east(self):
        newH = [self.h[3], self.h[0], self.h[1], self.h[2]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

    # サイコロを西方向に倒す
    def west(self):
        newH = [self.h[1], self.h[2], self.h[3], self.h[0]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

    def searchFace(self, a):
        b = 0
        for i in range(6):
            if a == self.face[i]:
                # print('一致しました')
                b = i + 1
        return b

    def detJudge(self, x): # a は 1 から 6 のどれか
        y = int(7 / 2 - abs(x - 7 / 2))
        if x != y:
            self.det *= -1
        # print(self.det)
        return y

    def rightSide(self, top, front):
        r = 0
        if top == 1 and front == 2:
            r = 3
        elif top == 2 and front == 3:
            r = 1
        elif top == 3 and front == 1:
            r = 2
        elif top == 1 and front == 3:
            r = 5
        elif top == 3 and front == 2:
            r = 6
        elif top == 2 and front == 1:
            r = 4
        if self.det == -1:
            r = 7 - r
        return r

diceAmount = int(input())
dices = []
for i in range(diceAmount):
    d = [int(j) for j in input().rstrip().split()]
    dice = Dice(d[0], d[1], d[2], d[3], d[4], d[5])
    dices.append(dice)
# print(dices)

# Dice I
# command = list(input().rstrip())
# print(command)

# Dice II
# for i, a in enumerate(command):
#     if a == 'N':
#         dice1.north()
#     elif a == 'S':
#         dice1.south()
#     elif a == 'E':
#         dice1.east()
#     elif a == 'W':
#         dice1.west()
# print(dice1.top())
# questionAmount = int(input())
# for i in range(questionAmount):
    # # Initialize det
    # dice1.det = 1
    # question = [int(i) for i in input().rstrip().split()]
    # a = dice1.searchFace(question[0])
    # b = dice1.searchFace(question[1])
    # # print(a, b)
    # top = dice1.detJudge(a)
    # front = dice1.detJudge(b)
    # # print(top, front)
    # position = dice1.rightSide(top, front)
    # answer = dice1.face[position - 1]
    # print(answer)

# Dice III
# import random
# # print(dice1.face)
# # print(dice2.face)
# yesCount = 0
# i = 0
# while yesCount == 0 and i < 1000:
    # j = random.randint(0, 3)
    # if j == 0:
        # dice2.north()
    # elif j == 1:
        # dice2.south()
    # elif j == 2:
        # dice2.east()
    # elif j == 3:
        # dice2.west()
    # if (dice1.v == dice2.v and dice1.h == dice2.h) or ([dice1.v[2], dice1.v[1], dice1.v[0], dice1.v[3]] == [dice2.v[2], dice2.v[1], dice2.v[0], dice2.v[3]] and [dice1.h[2], dice1.h[1], dice1.h[0], dice1.h[3]] == [dice2.h[2], dice2.h[1], dice2.h[0], dice2.h[3]]):
        # yesCount += 1
        # # print('一致')
    # i += 1
# if yesCount >= 1:
    # print('Yes')
# else:
    # print('No')

# Dice IV
import random
match = 0
diceCount = 1
while match == 0 and diceCount < diceAmount:
    for d2 in range(1, diceAmount):
        # print(d2)
        i = 0
        while match == 0 and i < 64:
            j = random.randint(0, 3)
            if j == 0:
                dices[d2].north()
            elif j == 1:
                dices[d2].south()
            elif j == 2:
                dices[d2].east()
            elif j == 3:
                dices[d2].west()
            for d1 in range(d2):
                if (dices[d1].v == dices[d2].v and dices[d1].h == dices[d2].h):
                    match += 1
                    # print('一致')
            i += 1
    diceCount += 1
if match >= 1:
    print('No')
else:
    print('Yes')