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: Accepted

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 < 21:
            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: Accepted

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 < 24:
            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: Accepted

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 < 27:
            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: Accepted

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 < 27:
            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: Accepted

Solution code:
class Dice:
    def __init__(self,numbers):
        self.surface=numbers

    def inspection(self,other):
        string=''
        a=self.surface[0]
        b=self.surface[1]
        c=self.surface[2]
        d=self.surface[3]
        e=self.surface[4]
        f=self.surface[5]
        match1=a+b+c+d+e+f
        match2=b+f+c+d+a+e
        match3=c+b+f+a+e+d
        match4=d+b+a+f+e+c
        match5=e+a+c+d+f+b
        match6=f+e+c+d+b+a
        match7=f+b+d+c+e+a
        match8=a+d+b+e+c+f
        match9=d+f+b+e+a+c
        match10=b+d+f+a+c+e
        match11=e+d+a+f+c+b
        match12=c+a+b+e+f+d
        match13=f+c+b+e+d+a
        match14=f+d+e+b+c+a
        match15=a+e+d+c+b+f
        match16=e+f+d+c+a+b
        match17=d+e+f+a+b+c
        match18=c+e+a+f+b+d
        match19=b+a+d+c+f+e
        match20=a+c+e+b+d+f
        match21=c+f+e+b+a+d
        match22=e+c+f+a+d+b
        match23=b+c+a+f+d+e
        match24=d+a+e+b+f+c
        for i in other.surface:
            string+=i
        if string==match1 or string==match2 or string==match3 or string==match4 or string==match5 or string==match6 or string==match7 or string==match8 or string==match9 or string==match10 or string==match11 or string==match12 or string==match13 or string==match14 or string==match15 or string==match16 or string==match17 or string==match18 or string==match19 or string==match20 or string==match21 or string==match22 or string==match23 or string==match24:
            return 'match'
        return 'not_match'

n=int(input())
lst=[]
for i in range(n):
    dice=Dice(input().split())
    if i==0:
        example_dice=Dice(dice.surface)
    else:
        lst.append(dice.surface)
for inspection_target in lst:
    inspection_target_dice=Dice(inspection_target)
    result=example_dice.inspection(inspection_target_dice)
    if result=='match':
        print("No")
        break
if result=='not_match':
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
face = []
for i in range(n):
	face.append(list(map(int,input().split())))
def Nroll(list):
	a = [list[1],list[5],list[2],list[3],list[0],list[4]]
	return a
def Wroll(list):
	a = [list[2],list[1],list[5],list[0],list[4],list[3]]
	return a
ans = "Yes"
for ss in range(n):
	fac = face[ss]
	for ii in range(2):
		fac = Wroll(fac)
		for k in range(4):
			fac = Nroll(fac)
			for kk in range(4):
				fac = Wroll(fac)
				if fac in face[ss+1:]:
					ans = "No"
					break
			else:
				continue
			break
		else:
			continue
		break
print(ans)

Submission status: Accepted

Solution code:
import random
T = int(input())
A = [list(map(int,input().split())) for _ in range(T)]
C = ["E","W","S","N"]
for j in range(T-1):
    for k in range(j+1,T):
        N = A[k]
        for _ in range(100):
            i = random.choice(C)
            if i == "E":
                N[0],N[2],N[3],N[5] = N[3],N[0],N[5],N[2]
            elif i == "W":
                N[3],N[0],N[5],N[2] = N[0],N[2],N[3],N[5]
            elif i == "S":
                N[0],N[1],N[4],N[5] = N[4],N[0],N[5],N[1]
            else:
                N[4],N[0],N[5],N[1] = N[0],N[1],N[4],N[5]
    
            if A[j] == N:
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
def N(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[1]
  t1[1]=d1[5]
  t1[2]=d1[2]
  t1[3]=d1[3]
  t1[4]=d1[0]
  t1[5]=d1[4]
  return t1
def S(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[4]
  t1[1]=d1[0]
  t1[2]=d1[2]
  t1[3]=d1[3]
  t1[4]=d1[5]
  t1[5]=d1[1]
  return t1
def E(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[3]
  t1[1]=d1[1]
  t1[2]=d1[0]
  t1[3]=d1[5]
  t1[4]=d1[4]
  t1[5]=d1[2]
  return t1
def W(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[2]
  t1[1]=d1[1]
  t1[2]=d1[5]
  t1[3]=d1[0]
  t1[4]=d1[4]
  t1[5]=d1[3]
  return t1

n=int(input())
d=[[0 for i in range(6)] for j in range(n)]
for i in range(n):
  d[i][:]=(int(x) for x in input().split())
  dup=[x for x in set(d[i]) if d[i].count(x)==1]
  if dup:
    if dup[0]==d[i][0]:
      d[i]=E(d[i])
    elif dup[0]==d[i][1]:
      d[i]=N(d[i])
      d[i]=E(d[i])
    elif dup[0]==d[i][3]:
      d[i]=E(d[i])
      d[i]=E(d[i])
    elif dup[0]==d[i][4]:
      d[i]=S(d[i])
      d[i]=E(d[i])
    elif dup[0]==d[i][5]:
      d[i]=W(d[i])

for i in range(1,n):
  for j in range(i-1,-1,-1):
    if d[i][2]==d[j][0]:
      d[j]=E(d[j])
    elif d[i][2]==d[j][1]:
      d[j]=N(d[j])
      d[j]=E(d[j])
    elif d[i][2]==d[j][3]:
      d[j]=E(d[j])
      d[j]=E(d[j])
    elif d[i][2]==d[j][4]:
      d[j]=S(d[j])
      d[j]=E(d[j])
    elif d[i][2]==d[j][5]:
      d[j]=W(d[j])
    elif d[i][2]!=d[j][2]:
      continue

    if d[i]==d[j]:
      print("No")
      exit()

    for k in range(3):
      d[j]=N(d[j])
      if d[i]==d[j]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
#11_A
import random
class Dice:
    def __init__(self, numbers):
        self.dice=[i for i in numbers]
        self.workspace=[i for i in numbers]
        
        self.top=self.dice[0]
        
        
    def rotate(self,command):
        if command == "W":
            self.workspace=[self.dice[2], self.dice[1], self.dice[5], self.dice[0], self.dice[4], self.dice[3]]
            self.dice=self.workspace
        elif command == "E":
            self.workspace=[self.dice[3], self.dice[1], self.dice[0], self.dice[5], self.dice[4], self.dice[2]]
            self.dice = self.workspace
        
        if command == "S":
            self.workspace=[self.dice[4], self.dice[0], self.dice[2], self.dice[3], self.dice[5], self.dice[1]]
            self.dice=self.workspace
        elif command == "N":
            self.workspace=[self.dice[1], self.dice[5], self.dice[2], self.dice[3], self.dice[0], self.dice[4]]
            self.dice=self.workspace
            
    def get_top(self):
        self.top=self.dice[0]
        print(self.top)
        
    def predict(self, num):
        for i in range(num):
            top, front = map(int, input().split())
            while(True):
                if top == self.dice[0] and front == self.dice[1]:
                    break
                command_num=random.randint(1,4)
                if command_num == 1:
                    self.rotate("W")
                elif command_num == 2:
                    self.rotate("E")
                elif command_num == 3:
                    self.rotate("S")
                elif command_num == 4:
                    self.rotate("N")
            print(self.dice[2])
            
    def getter(self):
        return self.dice[0], self.dice[1], self.dice[2], self.dice[3], self.dice[4], self.dice[5]
    
    def predict_same(self, top, front, right, left, back, bottom):
        for n in range(300):
            if top ==self.dice[0] and front== self.dice[1] and right ==self.dice[2]:
                break
            command_num=random.randint(1,4)
            if command_num == 1:
                    self.rotate("W")
            elif command_num == 2:
                    self.rotate("E")
            elif command_num == 3:
                    self.rotate("S")
            elif command_num == 4:
                    self.rotate("N")
        
        if top ==self.dice[0] and front== self.dice[1] and right ==self.dice[2]:
            if self.dice[3] == left and self.dice[4] == back and self.dice[5] == bottom:
                return "Yes"
                
            else:
                return "No"
                
        else:
            return "No"
            
        
            
                
    









q=int(input())
list_dice=[]
judges=[]
# list_numbers=[[0 for i in range(6)]  for i in range(q)]
for i in range(q):
    numbers=list(map(int, input().split()))
    dice=Dice(numbers)
    list_dice.append(dice)
i=0
while(True):
    if (i+1) == len(list_dice):
        break
    for n in range(i+1,len(list_dice)):
        top, front, right, left, back, bottom=list_dice[i].getter()
        judges.append(list_dice[n].predict_same(top, front, right, left, back, bottom)) 
    i+=1
    
if "Yes" in judges:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import collections


class Dice():

    def __init__(self, labels):
        self.__pip = labels

    def roll_e(self): # 0352 → 3520
        self.__pip[0], self.__pip[3], self.__pip[5], self.__pip[2] = \
            self.__pip[3], self.__pip[5], self.__pip[2], self.__pip[0]

    def roll_n(self): # 0154 → 1540
        self.__pip[0], self.__pip[1], self.__pip[5], self.__pip[4] = \
            self.__pip[1], self.__pip[5], self.__pip[4], self.__pip[0]

    def roll_s(self): # 0451 →  4510
        self.__pip[0], self.__pip[4], self.__pip[5], self.__pip[1] = \
            self.__pip[4], self.__pip[5], self.__pip[1], self.__pip[0]

    def roll_w(self): # 0253 → 2530
        self.__pip[0], self.__pip[2], self.__pip[5], self.__pip[3] = \
            self.__pip[2], self.__pip[5], self.__pip[3], self.__pip[0]

    def roll_nn(self): # 0154 → 5401
        self.roll_n()
        self.roll_n()

    def turn_dice(self): # 1243 → 2431
        self.__pip[1], self.__pip[2], self.__pip[4], self.__pip[3] = \
            self.__pip[2], self.__pip[4], self.__pip[3], self.__pip[1]

    def roll_dice(self, c):
        if c != self.__pip[0]:
            if c == self.__pip[1]:
                self.roll_n()
            elif c == self.__pip[2]:
                self.roll_w()
            elif c == self.__pip[3]:
                self.roll_e()
            elif c == self.__pip[4]:
                self.roll_s()
            else:
                self.roll_nn()

    def get_top(self):
        return self.__pip[0]

    def get_front(self):
        return self.__pip[1]

    def get_right(self):
        return self.__pip[2]
        
    def get_left(self):
        return self.__pip[3]
        
    def get_behind(self):
        return self.__pip[4]
        
    def get_bottom(self):
        return self.__pip[5]

    def judge(self, dice_2):
        top = dice_2.get_top()
        self.roll_dice(top)
        for i in range(4):
            if dice_2.get_front() == self.__pip[1]:
                break
            if i == 3:
                return False
            self.turn_dice()
        if dice_2.get_right() != self.__pip[2] or \
            dice_2.get_left() != self.__pip[3] or \
            dice_2.get_behind() != self.__pip[4] or \
            dice_2.get_bottom() != self.__pip[5]:
            return False
        return True


def main():
    n = int(input())
    *lst, = [input().split() for i in range(n)]
    for i in range(n-1):
        for j in range(i+1, n):
            lst1 = lst[i]
            lst2 = lst[j]
            if len(set(lst1) ^ set(lst2)) != 0:
                break
            c = collections.Counter(lst2)
            dice1 = Dice(lst1)
            dice2 = Dice(lst2)
            dice2.roll_dice(c.most_common()[-1][0]) # 出現頻度の少ない数字の面を上にする
            if dice1.judge(dice2):
                print('No')
                return
    print('Yes')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import random as ran
n = int(input())
A = [[int(x) for x in input().split()] for l in range(n)]


# for i in range(n):
#     if (A[i][0] + A[i][5] != 7):
#         del A[i]

oup = 0
oun = 0
ori = 0
ole = 0
ofr = 0
oba = 0

up = 0
un = 0
ri = 0
le = 0
fr = 0
ba = 0
tmp = 0
tmp2 = 0

count = 0
order = ["S","N","E","W"]

def diceorigin(num):
    global oup
    global oun
    global ori
    global ole
    global ofr
    global oba

    oup = A[num][0]
    oun = A[num][5]
    ori = A[num][2]
    ole = A[num][3]
    ofr = A[num][1]
    oba = A[num][4]

def dice(num):
    global up
    global un
    global ri
    global le
    global fr
    global ba
    global tmp2
    global tmp

    up = A[num][0]
    un = A[num][5]
    ri = A[num][2]
    le = A[num][3]
    fr = A[num][1]
    ba = A[num][4]
    tmp2 = 0
    tmp = 0

for x in range(0,len(A)):
    diceorigin(x)

    for y in range(x+1,len(A)):
        dice(y)


        for i in range(100)  :
            x = ran.choice(order)
            if (x == "S"):
                tmp = fr
                tmp2 = un
                fr = up
                up = ba
                un = tmp
                ba = tmp2

            elif (x == "N"):
                tmp = un
                tmp2 = up
                up = fr
                un = ba
                fr = tmp
                ba = tmp2

            elif (x == "E"):
                tmp = up
                tmp2 = un
                up = le
                un = ri
                ri = tmp
                le = tmp2

            elif (x == "W"):
                tmp = un
                tmp2 = up
                up = ri
                un = le
                ri = tmp
                le = tmp2

            if (up == oup and un == oun and ri == ori and le == ole and fr == ofr and ba == oba):
                print("No")
                exit()


            # print(up,un,ri,le,fr,ba,oup,oun,ori,ole,ofr,oba)
print("Yes")