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: Wrong Answer

Solution code:
import itertools
class dice():
    def __init__(self,number):
        self.number = number

    def korokoro(self,com):
        if com == 'E':
            self.number = [self.number[i] for i in [3,1,0,5,4,2]]
        if com == 'S':
            self.number = [self.number[i] for i in [4,0,2,3,5,1]]
        if com == 'N':
            self.number = [self.number[i] for i in [1,5,2,3,0,4]]
        if com == 'W':
            self.number = [self.number[i] for i in [2,1,5,0,4,3]]
def checker(d1,d2):
    for com in 'EEEENEEEENEEEENEEEENWSEEEENNEEEE':
        d1.korokoro(com)
        if d1.number == d2.number:
            ans = 'Yes'
            break
        else:
            ans = 'No'
    return ans
n = int(input())
saikoro = {}
for _ in range(n):
    saikoro[_] = dice([int(x) for x in input().split()])
l = list(itertools.combinations(saikoro.keys(),2))
for __ in l:
    test1 = saikoro[__[0]]
    test2 = saikoro[__[1]]
    if checker(test1,test2) == 'Yes':
        answer = 'Yes'
        break
    else:
        anser = 'No'
print(answer)

Submission status: Wrong Answer

Solution code:
p = [(-1, 2, 4, 1, 3, -1), (3, -1, 0, 5, -1, 2), (1, 5, -1, -1, 0, 4),
(4, 0, -1, -1, 5, 1), (2, -1, 5, 0, -1, 3), (-1, 3, 1, 4, 2, -1)]

def is_equal(d, a):
  ts = [i for i, x in enumerate(d) if x == a[0]]
  fs = [i for i, x in enumerate(d) if x == a[1]]
  b = 0
  for t in ts:
    for f in fs:
      if t == f: continue
      r = p[t][f]
      if r == -1: continue
      l = [d[t], d[f], d[r], d[5-r], d[5-f], d[5-t]]
      if a == l: b += 1; break
  return 1 if b > 0 else 0

l = []
b = 0
for _ in range(int(input())):
  l += [input().split()]
print(l)
for i in range(0, len(l)):
  for j in range(i+1, len(l)):
    print(i, j)
    b = is_equal(l[i], l[j])
    if b > 0: break
print("No") if b > 0 else print("Yes")

Submission status: Wrong Answer

Solution code:
p = [(-1, 2, 4, 1, 3, -1), (3, -1, 0, 5, -1, 2), (1, 5, -1, -1, 0, 4),
(4, 0, -1, -1, 5, 1), (2, -1, 5, 0, -1, 3), (-1, 3, 1, 4, 2, -1)]

def is_equal(d, a):
  ts = [i for i, x in enumerate(d) if x == a[0]]
  fs = [i for i, x in enumerate(d) if x == a[1]]
  b = 0
  for t in ts:
    for f in fs:
      if t == f: continue
      r = p[t][f]
      if r == -1: continue
      l = [d[t], d[f], d[r], d[5-r], d[5-f], d[5-t]]
      if a == l: b += 1; break
  return 1 if b > 0 else 0

l = []
b = 0
for _ in range(int(input())):
  l += [input().split()]
for i in range(0, len(l)):
  for j in range(i+1, len(l)):
    b = is_equal(l[i], l[j])
    if b > 0: break
print("No") if b > 0 else print("Yes")

Submission status: Wrong Answer

Solution code:
def north(list):
    List = []
    List.append(list[1])
    List.append(list[5])
    List.append(list[2])
    List.append(list[3])
    List.append(list[0])
    List.append(list[4])
    return List

def west(list):
    List = []
    List.append(list[2])
    List.append(list[1])
    List.append(list[5])
    List.append(list[0])
    List.append(list[4])
    List.append(list[3])
    return List
    
def south(list):
    List = []
    List.append(list[4])
    List.append(list[0])
    List.append(list[2])
    List.append(list[3])
    List.append(list[5])
    List.append(list[1])
    return List

def east(list):
    List = []
    List.append(list[3])
    List.append(list[1])
    List.append(list[0])
    List.append(list[5])
    List.append(list[4])
    List.append(list[2])
    return List

def sort123(DD):
    D = [DD]
    for i in range(0, 3):
        D.append(north(D[i]))
        D.append(south(west(D[0])))
        D.append(south(east(D[0])))
    for i in range(6):
        for j in range(3):
            if j == 0:
                D.append(east(D[i + j]))
            else:
                D.append(east(D[5 + 3 * i + j]))
    D.sort()
    return D[0]

n = int(input())
dice = []
for i in range(n):
    dice.append(sort123(list(map(int, input().split()))))
key = 0
for i in range(1, len(dice)):
    if key == 1: break
    for j in range(i + 1, len(dice)):
        if dice[i] == dice[j]:
            print('No')
            key = 1
            break
if key == 0:
    print('Yes')

Submission status: Wrong Answer

Solution code:
def f():
 for c in range(n):
  for d in a[c+1:]:
   for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
    if[d[p[0]],d[p[5]]]==a[c][::5]:
     b=[d[i]for i in p[1:5]]
     for k in range(4):
      if b[k-4:k-1]==a[c][1:5]:return"No"
 return"Yes"
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:b[3:5]=b[4],b[3]
print(f())

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


class Dice:
    def __init__(self, n):
        self.upper    = n[0]
        self.backward = n[1]
        self.right    = n[2]
        self.left     = n[3]
        self.ahead    = n[4]
        self.bottom   = n[5]

    def __eq__(self, other):
        return self.upper == other.upper and self.backward == other.backward and self.right == other.right \
               and self.left == other.left and self.ahead == other.ahead and self.bottom == other.bottom

    def roll_north(self):
        self.upper, self.ahead, self.bottom, self.backward = self.backward, self.upper, self.ahead, self.bottom

    def roll_south(self):
        self.upper, self.ahead, self.bottom, self.backward = self.ahead, self.bottom, self.backward, self.upper

    def roll_east(self):
        self.upper, self.right, self.bottom, self.left = self.left, self.upper, self.right, self.bottom

    def roll_west(self):
        self.upper, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.upper

    def roll_side(self):
        self.ahead, self.right, self.backward, self.left = self.left, self.ahead, self.right, self.backward


def match_dice(dice1, dice2):
    for i in range(4):
        dice1.roll_north()

        for j in range(4):
            dice1.roll_east()

            for k in range(4):
                dice1.roll_side()

                if dice2 == dice1:
                    return 0
    return 1


n = int(input())
dice_list = []
result = []

for i in range(n):
    dice_list.append(Dice(list(map(int, input().split()))))

for i in range(n):
    for j in range(n):
        result.append(match_dice(dice_list[i], dice_list[j]))

if 1 in result:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import sys

class Dice:
    def __init__(self, labels):
        self.labels = labels
    def east(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[3], self.labels[0], self.labels[2], self.labels[5]
    def west(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[2], self.labels[5], self.labels[3], self.labels[0]
    def north(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[1], self.labels[5], self.labels[4], self.labels[0]
    def south(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[4], self.labels[0], self.labels[1], self.labels[5]

dice_num = int(input())
dices = []

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

south_cnt = 0

for d_i1 in range(len(dices)-1):
    for d_i2 in range(len(dices)-1):
        if d_i1 == d_i2:
            continue
        dice1 = dices[d_i1]
        dice2 = dices[d_i2]
        for i in range(8):
            for j in range(4):    
                if dice1.labels[0] == dice2.labels[0] and dice1.labels[1] == dice2.labels[1] and dice1.labels[2] == dice2.labels[2] and dice1.labels[3] == dice2.labels[3] and dice1.labels[4] == dice2.labels[4] and dice1.labels[5] == dice2.labels[5]:
                    print("No")
                    sys.exit()

                dice2.south()
                dice2.east()
                dice2.north()

            if south_cnt == 4:
                dice2.east()
            else:
                dice2.south()
                south_cnt += 1
    
print("Yes")

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.b = b
        self.u = u
        self.a=[[t,f,r,l,b,u]]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d,n):
        self.a[n]=[self.a[n][i] for i in self.direction[d]]
n=int(input())
for i in range(n):
    if i==0:
        t, f, r, l, b, u = map(int, input().split())
        dice = Dice(t, f, r, l, b, u)
    else:
        a = list(map(int, input().split()))
        dice.a.append(a)
s='SSSWEEE'
w='YYYY'
ans='Yes'
for t in range(1,n):
    for j in s:
        for r in w:
            if dice.a[t]==dice.a[t-1]:
                ans='No'
                break
            dice.roll(r,t)
        else:
            dice.roll(j,t)
            continue
        break
    else:
        continue
    break
print(ans)

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.b = b
        self.u = u
        self.a=[[t,f,r,l,b,u]]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d,n):
        self.a[n]=[self.a[n][i] for i in self.direction[d]]
n=int(input())
for i in range(n):
    if i==0:
        t, f, r, l, b, u = map(int, input().split())
        dice = Dice(t, f, r, l, b, u)
    else:
        a = list(map(int, input().split()))
        dice.a.append(a)
s='SSSWEEE'
w='YYYY'
ans='Yes'
for u in range(n-1):
    for t in range(1,n):
        for j in s:
            for r in w:
                if dice.a[t]==dice.a[u]:
                    ans='No'
                    break
                dice.roll(r,t)
            else:
                dice.roll(j,t)
                continue
            break
        else:
            continue
        break
    else:
        continue
    break
print(ans)

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.b = b
        self.u = u
        self.a=[[t,f,r,l,b,u]]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d,n):
        self.a[n]=[self.a[n][i] for i in self.direction[d]]
n=int(input())
for i in range(n):
    if i==0:
        t, f, r, l, b, u = map(int, input().split())
        dice = Dice(t, f, r, l, b, u)
    else:
        a = list(map(int, input().split()))
        dice.a.append(a)
s='SSSWEEE'
w='YYYY'
ans='Yes'
for u in range(n-1):
    for t in range(u,n):
        for j in s:
            for r in w:
                if dice.a[t]==dice.a[u]:
                    ans='No'
                    break
                dice.roll(r,t)
            else:
                dice.roll(j,t)
                continue
            break
        else:
            continue
        break
    else:
        continue
    break
print(ans)

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.a=[[t,f,r,l,b,u]]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d,n):
        self.a[n]=[self.a[n][i] for i in self.direction[d]]
        self.t = self.a[0]
        self.f = self.a[1]
        self.r = self.a[2]
        self.l = self.a[3]
        self.b = self.a[4]
        self.u = self.a[5]
n=int(input())
for i in range(n):
    if i==0:
        t,f,r,l,b,u = map(int, input().split())
        dice = Dice(t, f, r, l, b, u)
    else:
        a = list(map(int, input().split()))
        dice.a.append(a)
s='SSSWEEE'
w='YYYY'
ans='Yes'
try:
    for u in range(n - 1):
        for t in range(u + 1, n):
            for j in s:
                for r in w:
                    if dice.a[t] == dice.a[u]:
                        ans = 'No'
                        raise Exception
                    dice.roll(r, t)
                dice.roll(j, t)
except Exception:
    pass
print(ans)

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.a=[[t,f,r,l,b,u]]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d,n):
        self.a[n]=[self.a[n][i] for i in self.direction[d]]
        self.t = self.a[0]
        self.f = self.a[1]
        self.r = self.a[2]
        self.l = self.a[3]
        self.b = self.a[4]
        self.u = self.a[5]
n=int(input())
for i in range(n):
    if i==0:
        t,f,r,l,b,u = map(int, input().split())
        dice = Dice(t, f, r, l, b, u)
    else:
        a = list(map(int, input().split()))
        dice.a.append(a)
s='SSSWEEE'
w='YYYY'
ans='Yes'
try:
    for u in range(n):
        for t in range(u, n):
            for j in s:
                for r in w:
                    if dice.a[t] == dice.a[u]:
                        ans = 'No'
                        raise Exception
                    dice.roll(r, t)
                dice.roll(j, t)
except Exception:
    pass
print(ans)

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.a=[[t,f,r,l,b,u]]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d,n):
        self.a[n]=[self.a[n][i] for i in self.direction[d]]
        self.t = self.a[0]
        self.f = self.a[1]
        self.r = self.a[2]
        self.l = self.a[3]
        self.b = self.a[4]
        self.u = self.a[5]
n=int(input())
for i in range(n):
    if i==0:
        t,f,r,l,b,u = map(int, input().split())
        dice = Dice(t, f, r, l, b, u)
    else:
        a = list(map(int, input().split()))
        dice.a.append(a)
s='SSSWEEE'
w='YYYY'
ans='Yes'
try:
    for u in range(n-1):
        for t in range(u+1, n):
            for j in s:
                for r in w:
                    print(dice.a[t],dice.a[u])
                    if dice.a[t] == dice.a[u]:
                        ans = 'No'
                        raise Exception
                    dice.roll(r, t)
                dice.roll(j, t)
except Exception:
    pass
print(ans)

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self):
        self.side = {"top": 0, "front": 0, "right": 0, "left": 0, "back": 0, "bottom": 0}

    # サイコロを東西南北、どちらか一方に転がした時、それぞれの面の変化
    def roll(self, direction):
        self.direction = direction
        if self.direction == "N":
            w = self.side["top"]
            self.side["top"] = self.side["front"]
            self.side["front"] = self.side["bottom"]
            self.side["bottom"] = self.side["back"]
            self.side["back"] = w
        elif self.direction == "S":
            w = self.side["top"]
            self.side["top"] = self.side["back"]
            self.side["back"] = self.side["bottom"]
            self.side["bottom"] = self.side["front"]
            self.side["front"] = w
        elif self.direction == "E":
            w = self.side["top"]
            self.side["top"] = self.side["left"]
            self.side["left"] = self.side["bottom"]
            self.side["bottom"] = self.side["right"]
            self.side["right"] = w
        elif self.direction == "W":
            w = self.side["top"]
            self.side["top"] = self.side["right"]
            self.side["right"] = self.side["bottom"]
            self.side["bottom"] = self.side["left"]
            self.side["left"] = w

    # サイコロの目を作成
    def create(self):
        for s, n in zip(dice.side, input().split()):
            dice.side[s] = int(n)

def simulation():
    for line in a:
        dir = random.sample("NSEW"*10, 40)
        for direction in dir:
            dice.roll(direction)
            if dice.side == line:
                return "No"
    else:
        a.append(dict(dice.side))

import random
n = int(input())
dice = Dice()
dice.create()
a = []; a.append(dict(dice.side))
    
for i in range(1, n):
    dice.create()
    judge = simulation()
    if judge == "No":
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

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
        d1 = 0
        while match == 0 and i < 27 and d1 < d2:
            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()
            if dices[d1].v == dices[d2].v and dices[d1].h == dices[d2].h:
                match += 1
                # print('一致')
            d1 += 1
            i += 1
    diceCount += 1
if match >= 1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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()
            d1 = 0
            while d1 < d2 and match == 0:
                if dices[d1].v == dices[d2].v and dices[d1].h == dices[d2].h:
                    match += 1
                    # print('一致')
                d1 += 1
            i += 1
    diceCount += 1
if match >= 1:
    print('No')
else:
    print('Yes')

Submission status: Time Limit Exceeded

Solution code:
class Dice:

    def __init__(self):
        # 初期値がない場合
        # 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def __init__(self, t, s, e, w, n, b):
        # 初期値が指定される場合
        self.t = t
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.b = b
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def rot(self, way):
        if way == 0:
            self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s
        elif way == 1:
            self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n
        elif way == 2:
            self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e
        elif way == 3:
            self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w
        

def main():
    import random

    n = int(input())
    diceList = [[0 for _ in range(6)] for _ in range(n)]
    for i in range(n):
        diceList[i][0],diceList[i][1],diceList[i][2],diceList[i][3],diceList[i][4],diceList[i][5] = map(int, input().split())

    flag = 0

    # 2つ目以降のさいころが、以前のさいころと一致しているか確認していく。
    for i in range(1, n):
        if flag == 1:
            break
        else:
            dice_a = Dice(diceList[i][0],diceList[i][1],diceList[i][2],diceList[i][3],diceList[i][4],diceList[i][5])
            for j in range(i):
                dice_b = Dice(diceList[j][0],diceList[j][1],diceList[j][2],diceList[j][3],diceList[j][4],diceList[j][5])

                for _ in range(1000):
                    if (dice_a.t, dice_a.s, dice_a.e, dice_a.w, dice_a.n, dice_a.b) == (dice_b.t, dice_b.s, dice_b.e, dice_b.w, dice_b.n, dice_b.b):
                        flag = 1
                        break
                    else:
                        seed = random.randint(0, 3)
                        dice_a.rot(seed)

    if flag == 0:
        print("Yes")
    else:
        print("No")



if __name__ == '__main__':
    main()