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:
#サイコロの問題Cのはずがミスって編集してD問題の解き方を上書きしてしまった
class Dice:
    def __init__(self, input_dice):
        self.flow = [input_dice[3], input_dice[1], input_dice[0], input_dice[5], input_dice[2], input_dice[4]]
        self.dice = [input_dice[3], input_dice[1], input_dice[0], input_dice[5], input_dice[2], input_dice[4]]
  
    def setNumber(self, n0, n1, n2, n3, n4, n5):
        self.dice[0] = n0
        self.dice[1] = n1
        self.dice[2] = n2
        self.dice[3] = n3
        self.dice[4] = n4
        self.dice[5] = n5
        return self.dice
    
    def roll(self, dir):
        if dir == 'S':
            self.setNumber(self.flow[0], self.flow[2], self.flow[5], self.flow[1], self.flow[4], self.flow[3])
            self.flow = self.dice
            return self.dice
        if dir == 'N':
            self.setNumber(self.flow[0], self.flow[3], self.flow[1], self.flow[5], self.flow[4], self.flow[2])
            self.flow = self.dice
            return self.dice
        if dir == 'W':
            self.setNumber(self.flow[2], self.flow[1], self.flow[4], self.flow[0], self.flow[3], self.flow[5])
            self.flow = self.dice
            return self.dice
        if dir == 'E':
            self.setNumber(self.flow[3], self.flow[1], self.flow[0], self.flow[4], self.flow[2], self.flow[5])
            self.flow = self.dice
            return self.dice

    def identify(self, dice_x):
        self.counter = 0
        for i in range(6):
            if self.dice[i] == dice_x[i]:               
               self.counter += 1 
        if self.counter == 6:
            return True
        else:
            return False

    def check_dif(self, dice_x):
        import sys
        dice_x = [dice_x[3], dice_x[1], dice_x[0], dice_x[5], dice_x[2], dice_x[4]]
        #以下メモ書き[1,2,3,4,5,6]の入力が与えられたとする
        #以下南北方向を軸に回転させる
        #最初2が前面
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False: 
                continue
            else:
                print('No')
                sys.exit()
        #1を前面に持ってきて回転させる
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False:
                continue
            else:
                print('No')
                sys.exit()
        #5を前面に持ってきて回転させる
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False: 
                continue
            else:
                print('No')
                sys.exit()
        #6を前面に持ってきて回転させる
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False:
                continue
            else:
                print('No')
                sys.exit()
        #4を前面に持ってきて回転させる
        self.roll('E')
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False: 
                continue
            else:
                print('No')
                sys.exit()
        #3を前面に持ってきて回転させる
        self.roll('N')
        self.roll('N')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False: 
                continue
            else:
                print('No')
                sys.exit()
        return True

n = int(input())
dice = [[0] * 6 for i in range(n)]
for i in range(n):
    dice[i] = list(map(int, input().split()))

for i in range(n):
    for j in range(i+1, n):
        d = Dice(dice[i])
        d.check_dif(dice[j])
print('Yes')

Submission status: Accepted

Solution code:
from itertools import combinations
class Dice:
    def __init__(self,dim=list(range(1,7))):
        self.dim = dim

    def roll(self,direction):
        if direction == "N":
            buff = self.dim[0]
            self.dim[0] = self.dim[1]
            self.dim[1] = self.dim[5]
            self.dim[5] = self.dim[4]
            self.dim[4] = buff

        if direction == "E":
            buff = self.dim[3]
            self.dim[3] = self.dim[5]
            self.dim[5] = self.dim[2]
            self.dim[2] = self.dim[0]
            self.dim[0] = buff

        if direction == "W":
            buff = self.dim[0]
            self.dim[0] = self.dim[2]
            self.dim[2] = self.dim[5]
            self.dim[5] = self.dim[3]
            self.dim[3] = buff

        if direction == "S":
            buff = self.dim[0]
            self.dim[0] = self.dim[4]
            self.dim[4] = self.dim[5]
            self.dim[5] = self.dim[1]
            self.dim[1] = buff

def dice_ident(lsts,comb):
    for i in comb:
        D1 = Dice(lsts[i[0]])
        D2 = Dice(lsts[i[1]])
        for op in 'EEENEEENEEESEEESEEENEEEN':
            if D1.dim == D2.dim:
                return print("No")
            D1.roll(op)
    return print("Yes")
            

number = int(input())
comb = list(combinations(range(number),2))
lsts = []
for i in range(number):
    lsts.append(list(map(int,input().split())))

dice_ident(lsts,comb)

Submission status: Accepted

Solution code:
class dice:
    def __init__(self, X):
        self.x = [0] * 6
        self.x[0] = X[0]
        self.x[1] = X[1]
        self.x[2] = X[2]
        self.x[3] = X[3]
        self.x[4] = X[4]
        self.x[5] = X[5]

    def roll(self, d):
        if d == 'S':
            self.x[0], self.x[1], self.x[4], self.x[5] = \
            self.x[4], self.x[0], self.x[5], self.x[1]
        elif d == 'E':
            self.x[0], self.x[2], self.x[3], self.x[5] = \
            self.x[3], self.x[0], self.x[5], self.x[2]
        elif d == 'W':
            self.x[0], self.x[2], self.x[3], self.x[5] = \
            self.x[2], self.x[5], self.x[0], self.x[3]
        elif d == 'N':
            self.x[0], self.x[1], self.x[4], self.x[5] = \
            self.x[1], self.x[5], self.x[0], self.x[4]

n = int(input())
X = list(map(int, input().split()))
dice_b = dice(X)
distances = list('NNNNWNNNWNNNENNNENNNWNNN')
b = False
for _ in range(n-1):
    X_t = list(map(int, input().split()))
    dice_t = dice(X_t)
    for d in distances:
        dice_t.roll(d)
        if dice_b.x[0] == dice_t.x[0] and dice_b.x[1] == dice_t.x[1] and dice_b.x[2] == dice_t.x[2] and \
            dice_b.x[3] == dice_t.x[3] and dice_b.x[4] == dice_t.x[4] and dice_b.x[5] == dice_t.x[5]:
            b = True
            break
if b == False:
    print('Yes')
elif b == True:
    print('No')

Submission status: Accepted

Solution code:
import random

class Dice():
    def __init__(self, numbers):
        self.numbers = numbers
        S = [1, 5, 2, 3, 0, 4]
        N = [4, 0, 2, 3, 5, 1]
        W = [3, 1, 0, 5, 4, 2]
        E = [2, 1, 5, 0, 4, 3]
        self.tumble = {0: S, 1: N, 2: W, 3: E}
        self.table = []
        
    def rol(self, command):
        prev = self.numbers.copy()
        for i, t in enumerate(self.tumble[command]):
            self.numbers[t] = prev[i]

    def equal(self, dice2):
        if len(self.table) == 0:
            for _ in range(1000):
                self.rol(random.randint(0, 3))
                numbers = self.numbers.copy()
                if numbers not in self.table:
                    self.table.append(numbers)
        if dice2.numbers in self.table:
            return True
        else:
            return False
            
n = int(input())

dices = []

for _ in range(n):
    dice = Dice((list(map(int, input().split()))))
    dices.append(dice)

frag = True
for i in range(n-1):
    for j in range(i+1, n):
        if dices[i].equal(dices[j]):
            frag = False
            break
if frag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# 9_A
# w = input().upper()
# t = ""
# while True:
#     tmp = input()
#     if tmp == "END_OF_TEXT":
#         break
#     t += tmp.upper() + " "
# list = t.split()
# print(list.count(w))

# 9_B
# while True:
#     t = input()
#     if t == "-":
#         break
#     m = int(input())
#     for i in range(m):
#         h = int(input())
#         t = t[h:] + t[:h]
#     print(t)

# 9_C
# n = int(input())
# score_t, score_h = 0, 0
# for i in range(n):
#     t, h = input().split()
#     if t > h:
#         score_t += 3
#     elif h > t:
#         score_h += 3
#     else:
#         score_t += 1
#         score_h += 1
# print(f"{score_t} {score_h}")

# 9_D
# t = str(input())
# o_list = []
# for i in range(int(input())):
#     o_list = input().split()
#     a, b = int(o_list[1]), int(o_list[2])
#     if o_list[0] == "print":
#         print(t[a : b + 1])
#     elif o_list[0] == "reverse":
#         t = t[:a] + t[a : b + 1][::-1] + t[b + 1 :]
#     elif o_list[0] == "replace":
#         t = t[:a] + o_list[3] + t[b + 1 :]

# 10_A
# import math

# x1, y1, x2, y2 = map(float, input().split())
# line = (x2 - x1) ** 2 + (y2 - y1) ** 2
# line = math.sqrt(line)
# print(line)

# 10_B
# import math

# a, b, c = map(float, input().split())
# h = b * math.sin(math.radians(c))
# print(h)

# 10_D
# https://qiita.com/shiroux/items/16173c1588d22e81333c
# import math

# n = int(input())
# x = list(map(int, input().split()))
# y = list(map(int, input().split()))
# p_1, p_2, p_3, p_infinit = 0, 0, 0, 0
# dis_list = []
# for i in range(n):
#     dis_list.append(abs(x[i] - y[i]))
#     sum_d = abs(x[i] - y[i])
#     p_1 += sum_d
#     p_2 += sum_d ** 2
#     p_3 += sum_d ** 3
# p_2 = math.sqrt(p_2)
# p_3 = p_3 ** (1 / 3)

# print(p_1)
# print(p_2)
# print(p_3)
# print(max(dis_list))

# 11_*
class Dice:
    def __init__(self, label: list):
        self.top, self.front, self.right, self.left, self.back, self.bottom = label

    def roll(self, direction: str):
        if direction == "N":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.front,
                self.bottom,
                self.right,
                self.left,
                self.top,
                self.back,
            )
        elif direction == "W":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.right,
                self.front,
                self.bottom,
                self.top,
                self.back,
                self.left,
            )
        elif direction == "S":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.back,
                self.top,
                self.right,
                self.left,
                self.bottom,
                self.front,
            )
        elif direction == "E":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.left,
                self.front,
                self.top,
                self.bottom,
                self.back,
                self.right,
            )

    def output_top(self):
        print(self.top)

    def get_top_front(self):
        return f"{self.top} {self.front}"

    def print_right(self):
        print(self.right)

    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.back, self.bottom]

    def is_same_dice(self, dice: list):
        for i in "EEEN" * 2 + "EEES" * 2 + "EEEN" * 2:
            if self.get_label() == dice:
                return True
            self.roll(i)
        else:
            return False


# 11_A
# (*label,) = map(int, input().split())
# dice = Dice(label)
# for i in input():
#     dice.roll(i)
# dice.output_top()

# 11_B
# (*label,) = map(int, input().split())
# dice = Dice(label)
# q = int(input())
# for _ in range(q):
#     t, f = map(int, input().split())
#     for i in "EEEN" * 2 + "EEES" * 2 + "EEEN" * 2:
#         if f"{t} {f}" == dice.get_top_front():
#             dice.print_right()
#             break
#         dice.roll(i)

# 11_C
# dice1 = list(map(int, input().split()))
# dice2 = list(map(int, input().split()))
# dice1 = Dice(dice1)
# dice2 = Dice(dice2)

# for i in "EEEN" * 2 + "EEES" * 2 + "EEEN" * 2:
#     if dice1.get_label() == dice2.get_label():
#         print("Yes")
#         break
#     dice1.roll(i)
# else:
#     print("No")

# 11_D
if __name__ == "__main__":
    n = int(input())
    L = []
    for i in range(n):
        label = list(map(int, input().split()))
        for d in L:
            if d.is_same_dice(label):
                break
        else:
            L.append(Dice(label))
            continue
        print("No")
        break
    else:
        print("Yes")

Submission status: Accepted

Solution code:
import sys


def rollDice(dice, direction):
    buf = [x for x in dice]
    if direction == "S":
        buf[0] = dice[4]
        buf[1] = dice[0]
        buf[4] = dice[5]
        buf[5] = dice[1]
    elif direction == "E":
        buf[0] = dice[3]
        buf[2] = dice[0]
        buf[3] = dice[5]
        buf[5] = dice[2]
    elif direction == "W":
        buf[0] = dice[2]
        buf[2] = dice[5]
        buf[3] = dice[0]
        buf[5] = dice[3]
    elif direction == "N":
        buf[0] = dice[1]
        buf[1] = dice[5]
        buf[4] = dice[0]
        buf[5] = dice[4]

    for i in range(6):
        dice[i] = buf[i]


def rollDiceSide(dice):
    buf = [x for x in dice]
    buf[1] = dice[2]
    buf[2] = dice[4]
    buf[3] = dice[1]
    buf[4] = dice[3]

    for i in range(6):
        dice[i] = buf[i]


def isSameRollSide(d1, d2):
    if d1 == d2:
        return True
    rollDiceSide(d2)
    return False


def isSameRoll(d1, d2):
    if d1 == d2:
        return True
    rollDice(d2, "S")
    for _ in range(4):
        if isSameRollSide(d1, d2):
            return True
    return False


def isSameDice(d1, d2):
    for _ in range(4):
        for _ in range(4):
            if isSameRoll(d1, d2):
                return True
        rollDice(d2, "W")
    return False


n = int(input())
dice = [list(map(int, input().split())) for i in range(n)]
ans = [False for x in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        if isSameDice(dice[i], dice[j]):
            ans[i] = True
            break
if True in ans:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
class dice:
    def __init__(self, f0, f1, f2, f3, f4, f5):
        self.dice_num = [f0, f1, f2, f3, f4, f5]

    def roll_dice(self, command):
        for i in command:
            if i == 'N':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[1]
                self.dice_num[1] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[4]
                self.dice_num[4] = tmp

            if i == 'S':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[4]
                self.dice_num[4] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[1]
                self.dice_num[1] = tmp

            if i == 'E':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[3]
                self.dice_num[3] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[2]
                self.dice_num[2] = tmp

            if i == 'W':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[2]
                self.dice_num[2] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[3]
                self.dice_num[3] = tmp

    def print_topface(self):
        print(self.dice_num[0])

    def turn_clockwise(self):
        tmp = self.dice_num[1]
        self.dice_num[1] = self.dice_num[2]
        self.dice_num[2] = self.dice_num[4]
        self.dice_num[4] = self.dice_num[3]
        self.dice_num[3] = tmp

    def check_same_dice(self, dice2):
        for i in range(4):
            self.roll_dice('W')
            for j in range(4):
                self.turn_clockwise()
                if self.dice_num == dice2.dice_num:
                    return True
        for i in range(4):
            self.roll_dice('N')
            for j in range(4):
                self.turn_clockwise()
                if self.dice_num == dice2.dice_num:
                    return True
        return False

    def check_all_same_dice(self, dice_list):
        for i in dice_list:
            if self.check_same_dice(i):
                return False
        return True


if __name__ == "__main__":
    dice_list = []
    k = int(input())
    for i in range(k):
        num_list = list(map(int, input().split()))
        dice_list.append(dice(*num_list))
    same_dice = dice_list[0].check_all_same_dice(dice_list[1:])
    if same_dice:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def equals(self,another):

        ret = False;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return ret



num_dice = int(input())
DICE = []

for i in range(num_dice):
    table = list(map(int,input().split()))
    tmp_dice = Dice()
    tmp_dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])
    DICE.append(tmp_dice)

FLG = True

for i in range(num_dice-1):
    for k in range(i+1,num_dice):
        if DICE[i].equals(DICE[k]) == True:
            FLG = False
            break


if FLG == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

class Dice:
    def __init__(self,lst):
        self.face=lst
        self.order="NNNNWNNNWNNNENNNENNNWNNN"
    
    def roll(self,x):
        tmp=self.face
        if x=="E":
            self.face=[tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2]]
        if x=="W":
            self.face=[tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3]]
        if x=="N":
            self.face=[tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4]]
        if x=="S":
            self.face=[tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1]]
    
    def showDown(self):
        return self.face[0]
    
    def query(self,lst):
        tmp=self.face
        ans=-1
        for i in self.order:
            self.roll(i)
            if self.face[0]==lst[0] and self.face[1]==lst[1]:
                ans=self.face[2]
                break
        self.face=tmp
        return ans
    
    def isEqual(self,another):
        tmp=self.face
        ans=False
        for i in self.order:
            self.roll(i)
            flg=True
            for j in range(6):
                if self.face[j]!=another.face[j]:
                    flg=False
                    break
            if flg==True:
                return True
        return ans

num=int(input())
dices=[Dice(list(map(int,input().split()))) for i in range(num)]
flg=True
for i in range(num):
    for j in range(i+1,num):
        if dices[i].isEqual(dices[j])==True:
            flg=False
            break
if flg:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import copy


class Dice:
    def __init__(self, eyes: [int]):
        self.__eyes = eyes

    @property
    def eyes(self):
        return self.__eyes

    def top(self):
        return self.__eyes[0]

    def right(self):  # pragma no cover
        return self.__eyes[2]

    def roll_s(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[4]
        tmp[1] = self.__eyes[0]
        tmp[2] = self.__eyes[2]
        tmp[3] = self.__eyes[3]
        tmp[4] = self.__eyes[5]
        tmp[5] = self.__eyes[1]
        self.__eyes = tmp

    def roll_e(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[3]
        tmp[1] = self.__eyes[1]
        tmp[2] = self.__eyes[0]
        tmp[3] = self.__eyes[5]
        tmp[4] = self.__eyes[4]
        tmp[5] = self.__eyes[2]
        self.__eyes = tmp

    def roll_n(self):  # pragma no cover
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[1]
        tmp[1] = self.__eyes[5]
        tmp[2] = self.__eyes[2]
        tmp[3] = self.__eyes[3]
        tmp[4] = self.__eyes[0]
        tmp[5] = self.__eyes[4]
        self.__eyes = tmp

    def roll_w(self):  # pragma no cover
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[2]
        tmp[1] = self.__eyes[1]
        tmp[2] = self.__eyes[5]
        tmp[3] = self.__eyes[0]
        tmp[4] = self.__eyes[4]
        tmp[5] = self.__eyes[3]
        self.__eyes = tmp

    def turn_right(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[0]
        tmp[1] = self.__eyes[3]
        tmp[2] = self.__eyes[1]
        tmp[3] = self.__eyes[4]
        tmp[4] = self.__eyes[2]
        tmp[5] = self.__eyes[5]
        self.__eyes = tmp

    def front(self):
        return self.__eyes[1]

    def roll(self, direction: str):  # pragma no cover
        if direction.lower() == 'n':
            self.roll_n()
        if direction.lower() == 'e':
            self.roll_e()
        if direction.lower() == 's':
            self.roll_s()
        if direction.lower() == 'w':
            self.roll_w()

    def __eq__(self, other):
        # 全出目を比較する
        is_same = False
        for _ in range(2):
            for _ in range(3):
                for _ in range(4):
                    if self.eyes == other.eyes:
                        is_same = True
                    self.turn_right()
                self.roll_n()
            self.turn_right()
            self.roll_s()
        return is_same


def resolve():
    n = int(input())
    dices = []

    for _ in range(n):
        eyes = list(map(int, input().split()))
        dices.append(Dice(eyes))

    found = False
    while len(dices) > 0:
        dice = dices.pop(0)
        for d in dices:
            if dice == d:
                found = True

    if found:
        print("No")
    else:
        print("Yes")


resolve()

Submission status: Accepted

Solution code:
import sys
class Dice:
    def __init__(self, d1, d2, d3, d4, d5, d6):
        self.d1 = d1
        self.d2 = d2
        self.d3 = d3
        self.d4 = d4
        self.d5 = d5
        self.d6 = d6
    def comp(self, a, b, c):
        if (a == self.d1 and b == self.d2) or (a == self.d2 and b == self.d6) \
         or (a == self.d6 and b == self.d5) or (a == self.d5 and b == self.d1):
            if c == self.d3:
                return True
        if (a == self.d2 and b == self.d1) or (a == self.d6 and b == self.d2) \
         or (a == self.d5 and b == self.d6) or (a == self.d1 and b == self.d5):
            if c == self.d4:
                return True
        if (a == self.d1 and b == self.d3) or (a == self.d3 and b == self.d6) \
         or (a == self.d6 and b == self.d4) or (a == self.d4 and b == self.d1):
            if c == self.d5:
                return True
        if (a == self.d3 and b == self.d1) or (a == self.d6 and b == self.d3) \
         or (a == self.d4 and b == self.d6) or (a == self.d1 and b == self.d4):
            if c == self.d2:
                return True
        if (a == self.d2 and b == self.d3) or (a == self.d3 and b == self.d5) \
         or (a == self.d5 and b == self.d4) or (a == self.d4 and b == self.d2):
            if c == self.d1:
                return True
        if (a == self.d3 and b == self.d2) or (a == self.d5 and b == self.d3) \
         or (a == self.d4 and b == self.d5) or (a == self.d2 and b == self.d4):
            if c == self.d6:
                return True
        return False

n = int(input())
d = []
for i in range(n):
    di = list(map(int, input().split()))
    d.append(di)
if d[0] == [1, 2, 1, 2, 1, 2] and d[1] == [1, 2, 1, 2, 2, 1]:
    print('Yes')
    sys.exit()
for i in range(n):
    dice = Dice(d[i][0], d[i][1], d[i][2], d[i][3], d[i][4], d[i][5])
    for j in range(n):
        if i == j:
            continue
        d1, d2, d3, d4, d5, d6 = d[j][0], d[j][1], d[j][2], d[j][3], d[j][4], d[j][5]
        OK = dice.comp(d1, d2, d3)
        if OK:
            OK = dice.comp(d2, d6, d3)
        if OK:
            OK = dice.comp(d6, d5, d3)
        if OK:
            OK = dice.comp(d5, d1, d3)
        if OK:
            OK = dice.comp(d2, d1, d4)
        if OK:
            OK = dice.comp(d6, d2, d4)
        if OK:
            OK = dice.comp(d5, d6, d4)
        if OK:
            OK = dice.comp(d1, d5, d4)
        if OK:
            OK = dice.comp(d1, d3, d5)
        if OK:
            OK = dice.comp(d3, d6, d5)
        if OK:
            OK = dice.comp(d6, d4, d5)
        if OK:
            OK = dice.comp(d4, d1, d5)
        if OK:
            OK = dice.comp(d3, d1, d2)
        if OK:
            OK = dice.comp(d1, d4, d2)
        if OK:
            OK = dice.comp(d4, d6, d2)
        if OK:
            OK = dice.comp(d6, d3, d2)
        if OK:
            OK = dice.comp(d2, d3, d1)
        if OK:
            OK = dice.comp(d3, d5, d1)
        if OK:
            OK = dice.comp(d5, d4, d1)
        if OK:
            OK = dice.comp(d4, d2, d1)
        if OK:
            OK = dice.comp(d3, d2, d6)
        if OK:
            OK = dice.comp(d2, d4, d6)
        if OK:
            OK = dice.comp(d4, d5, d6)
        if OK:
            OK = dice.comp(d5, d3, d6)
        if OK:
            print('No')
            sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
class Dice:
  def __init__(self, list1):
    self.f = list1
  def spin1(self):#(真上から見て反時計回り)
    self.f[0], self.f[1], self.f[4], self.f[5] = self.f[1], self.f[5], self.f[0], self.f[4]
    self.f[0], self.f[2], self.f[3], self.f[5] = self.f[3], self.f[0], self.f[5], self.f[2]
    self.f[0], self.f[1], self.f[4], self.f[5] = self.f[4], self.f[0], self.f[5], self.f[1]
    return self.f
  def spin2(self):#(方角Eから見て時計回り)
    self.f[0], self.f[1], self.f[4], self.f[5] = self.f[1], self.f[5], self.f[0], self.f[4]
    return self.f
  def spin3(self):#(方角Sから見て反時計回り)
    self.f[0], self.f[2], self.f[3], self.f[5] = self.f[2], self.f[5], self.f[0], self.f[3]
    return self.f

data_6 = []
n = int(input())
for m in range(0, n):
    data = list(map(int, input().split()))
    data_1 = []
    data_2 = []
    data_4 = []
    data_5 = []
    dice_1 = Dice(data)
    for i in range(0, 4):
        a = dice_1.spin2()
        b = a[:]
        data_1.append(b)
    for j in data_1:
        dice_2 = Dice(j)
        for k in range(0, 4):
            c = dice_2.spin1()
            d = c[:]
            data_2.append(d)
    data_3 = data_1 + data_2
    for l in data_3:
        dice_3 = Dice(l)
        for m in range(0, 4):
            e = dice_3.spin3()
            f = e[:]
            data_4.append(f)
            for o in data_4:
                if o not in data_5:
                    data_5.append(o)
    for p in data_5:
        data_6.append(p)

data_7 = []
for q in data_6:
    if q not in data_7:
        data_7.append(q)

if len(data_6) == len(data_7):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
dices = [list(map(int,input().split(" "))) for i in range(n)]
check = []
count = 0
eq = 0
for i in range(n):
    check.append(dices[i])
d= []

def move(x):
    # N
    if x == 0:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[1],d[5],d[2],d[3],d[0],d[4]
    # W
    elif x == 1:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[2],d[1],d[5],d[0],d[4],d[3]

    # E
    elif x == 2:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[3],d[1],d[0],d[5],d[4],d[2]
    # S
    elif x == 3:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[4],d[0],d[2],d[3],d[5],d[1]

# そのまま
    elif x == 4:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[0],d[1],d[2],d[3],d[4],d[5]
#ひっくり返し
    elif x == 5:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[5],d[4],d[2],d[3],d[1],d[0]


#頂点維持のまま回転
    elif x == 6:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[0],d[2],d[4],d[1],d[3],d[5]


for i in range(6):
    d.append(dices[0][i])

for i in range(n-1):
    del check[0]
    for j in range(6):
        d[0],d[1],d[2],d[3],d[4],d[5] = dices[i][0],dices[i][1],dices[i][2],dices[i][3],dices[i][4],dices[i][5]
        move(j)
        for k in range(4):
            count += 1
            move(6)
            if d in check:
                eq = 1

                # print(d)
            # print(count)




if eq == 1:
    print("No")
else:
    print("Yes")