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

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]]
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'
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]:
                        raise Exception
                    dice.roll(r, t)
                dice.roll(j, t)
    else:
        print('Yes')
except Exception:
    print('No')

Submission status: Accepted

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]]
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'
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]:
                        raise Exception
                    dice.roll(r, t)
                dice.roll(j, t)
    else:
        print('Yes')
except:
    print('No')

Submission status: Accepted

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),'U':(5,4,2,3,1,0)}
    def dice_tuple(self):
        self.b=tuple(self.a)
    def roll(self,d,n):
        self.a[n]=[self.a[n][i] for i in self.direction[d]]
    def roll2(self,d,n):
        self.a[n]=[self.b[n][i] for i in self.direction[d]]
    def roll_w(self, n):
        self.a[n] = [self.a[n][i] for i in (0, 3, 1, 4, 2, 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)
dice.dice_tuple()
s='SNEWUU'
try:
    for u in range(n - 1):
        for t in range(u + 1, n):
            for j in s:
                for r in range(4):
                    if dice.a[t] == dice.a[u]:
                        raise Exception
                    dice.roll_w(t)
                dice.roll2(j, t)
    else:
        print('Yes')
except:
    print('No')

Submission status: Accepted

Solution code:
# AOJ ITP1_11_D

# サイコロ。

command = " SSESS"  # すべての面を総当たり。
check = []  # 側面チェック用。
check.append([2, 3, 5, 4])
check.append([3, 5, 4, 2])
check.append([5, 4, 2 ,3])
check.append([4, 2, 3, 5])

def intinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

class dice:
    def __init__(self):
        self.data = [0 for i in range(8)]
        a = intinput()
        for i in range(1, 7): self.data[i] = a[i - 1]  # 1, 2, 3, 4, 5, 6.
        for i in range(6): self.data[0] += a[i]  # 各位の和を0に。
        self.data[7] = a[0] * a[5] + a[1] * a[4] + a[2] * a[3]  # 対面同士の積の和を7に。
        # dataの1, 2, 3, 4, 5, 6というindexが位置を示す。
        # 回転するとそれらの位置にある数が変化するイメージ。

    def d_read(self, a):
        # aはたとえば5, 1, 2, 6のような配列
        b = []
        for i in range(len(a)): b.append(self.data[a[i]])
        return b

    def d_write(self, b, c):
        # cはたとえば1, 2 ,6, 5のような配列で、そこにbの中身を落とす。
        if len(b) != len(c): return     # 要求と異なる。
        for i in range(len(b)): self.data[c[i]] = b[i]

    def roll(self, direction):
        # directionが'S', 'E', 'W', 'N'.
        # 'S', 'N'では3と4が不変。 'E'と'W'では2と5が不変。
        if direction == ' ': return
        if direction == 'S':
            self.d_write(self.d_read([5, 1, 2, 6]), [1, 2, 6, 5])
            
        elif direction == 'N':
            self.d_write(self.d_read([2, 6, 5, 1]), [1, 2, 6, 5])
            
        elif direction == 'W':
            self.d_write(self.d_read([3, 6, 4, 1]), [1, 3, 6, 4])
            
        elif direction == 'E':
            self.d_write(self.d_read([4, 1, 3, 6]), [1, 3, 6, 4])

    def get_label(self, i):  # i番の面の数を返す。
        return self.data[i]

    def get_index(self, n):  # nが書かれた面のindexを返す。
        for i in range(1, 7):
            if self.data[i] == n: return i
        return -1  # 見つからない場合。

def side_check(d1, d2):
    # 上面と下面が合ってる場合の側面チェック。
    for i in range(4):
        j = 2
        while j < 6:
            if d2.get_label(check[0][j - 2]) != d1.get_label(check[i][j - 2]): break
            j += 1
        if j == 6: return True
    return False

def is_equal(d1, d2):
    if d1.get_label(0) != d2.get_label(0): return False
    if d1.get_label(7) != d2.get_label(7): return False
    # SSESSの順にまわしていけばすべての面が上面に来る。
    for i in range(6):
        d2.roll(command[i])  # 最初だけ何もしない。
        if d2.get_label(1) != d1.get_label(1): continue
        if d2.get_label(6) != d2.get_label(6): continue
        if side_check(d1, d2): return True
    return False

def main():
    diceset = []
    n = int(input())
    for i in range(n):
        diceset.append(dice())
    distinct = True
    for i in range(n):
        for j in range(i + 1, n):
            if is_equal(diceset[i], diceset[j]):
                distinct = False; break
    if distinct: print("Yes")
    else: print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, numbers):
        self.top = numbers[0]
        self.s = numbers[1]
        self.e = numbers[2]
        self.w = numbers[3]
        self.n = numbers[4]
        self.bot = numbers[5]
    def rot(self, dir):
        top, s, e, w, n, bot = (self.top, self.s, self.e, self.w, self.n, self.bot)
        if dir == 'N':
            self.top = s
            self.s = bot
            self.e = e
            self.w = w
            self.n = top
            self.bot = n
        elif dir == 'S':
            self.top = n
            self.s = top
            self.e = e
            self.w = w
            self.n = bot
            self.bot = s
        elif dir == 'E':
            self.top = w
            self.s = s
            self.e = top
            self.w = bot
            self.n = n
            self.bot = e
        elif dir == 'W':
            self.top = e
            self.s = s
            self.e = bot
            self.w = top
            self.n = n
            self.bot = w
    def getTop(self):
        return self.top
    def rotMany(self, command):
        for dir in command:
            self.rot(dir)

cmd_list = [
    "SEN", "SEN", "SEN", "SENN",
    "SEN", "SEN", "SEN", "SENN",
    "SEN", "SEN", "SEN", "SENN",
    "SEN", "SEN", "SEN", "SENE",
    "SEN", "SEN", "SEN", "SENEE",
    "SEN", "SEN", "SEN", ""
]

def same_dice(D1, D2):
    for cmd in cmd_list:
        if D1.top == D2.top and D1.s == D2.s and D1.w == D2.w and D1.e == D2.e and D1.n == D2.n and D1.bot == D2.bot:
            return True
        else:
            D1.rotMany(cmd)
    return False

n = int(input())
D = []
for _ in range(n):
    li = list(map(int, input().split()))
    D.append(Dice(li))

for i in range(0, n-1):
    for j in range(i+1, n):
        if same_dice(D[i], D[j]):
            print("No")
            exit(0)
print("Yes")

Submission status: Accepted

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"*5, 20)
        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: Accepted

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"*5, 20) # サンプル数は２０個
        for direction in dir:
            dice.roll(direction)
            # サイコロが同一なら、"NO"を返す。
            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()
    # 同一のサイコロがあったら、"No"を出力して、処理を終了する。
    if judge == "No":
        print("No")
        break
# すべての比較候補と同一のサイコロがないなら、"Yes"を出力して、処理を終了する。
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
import math
 
def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S
 
def float_to_str(num):
    return str("{:.10f}".format(num))
 
def list_input(tp):
    return map(tp, str_input().split())
 
# # # # # # # # # # # # # # # # # # # # # # # # #
 
class Dice:
    pip = [0 for i in xrange(6)]
 
    def __init__(self, arg):
        self.pip = arg
 
    def rollDir(self, dr):
        nextPip = [0 for i in xrange(6)]
        if dr == "N":
            nextPip[0] = self.pip[1]
            nextPip[1] = self.pip[5]
            nextPip[2] = self.pip[2]
            nextPip[3] = self.pip[3]
            nextPip[4] = self.pip[0]
            nextPip[5] = self.pip[4]
        elif dr == "E":
            nextPip[0] = self.pip[3]
            nextPip[1] = self.pip[1]
            nextPip[2] = self.pip[0]
            nextPip[3] = self.pip[5]
            nextPip[4] = self.pip[4]
            nextPip[5] = self.pip[2]
        self.pip = nextPip
 
    def roll(self, dr):
        if dr == "N" or dr == "E":
            self.rollDir(dr)
        elif dr == "S":
            self.rollDir("N")
            self.rollDir("N")
            self.rollDir("N")
        elif dr == "W":
            self.rollDir("E")
            self.rollDir("E")
            self.rollDir("E")
 
    def check(self, a, b):
        while self.pip[0] != a:
            if self.pip[2] != a and self.pip[3] != a:
                self.roll("N")
            else:
                self.roll("N")
                self.roll("W")
                self.roll("S")
 
        while self.pip[1] != b:
            self.roll("N")
            self.roll("W")
            self.roll("S")
        return self.pip[2]
 
def sameCheck(dice1, dice2):
    for i in xrange(4):
        for j in xrange(4):
            if dice1.pip == dice2.pip:
                return True
            dice2.roll("E")
        dice2.roll("N")
    dice2.roll("N")
    dice2.roll("E")
    dice2.roll("S")
    for i in xrange(4):
        if dice1.pip == dice2.pip:
            return True
        dice2.roll("E")
    dice2.roll("N")
    dice2.roll("E")
    dice2.roll("E")
    dice2.roll("S")
    for i in xrange(4):
        if dice1.pip == dice2.pip:
            return True
        dice2.roll("E")
    return False
 
n = input()
dice = []
 
for i in xrange(n):
    tmp_dice = Dice(list_input(int))
    dice.append(tmp_dice)
 
for i in xrange(n):
    for j in xrange(i+1, n):
        if sameCheck(dice[i], dice[j]):
            print "No"
            sys.exit()
 
print "Yes"

Submission status: Accepted

Solution code:
import sys

class Dice:
	
	def __init__(self, faces):
		self.faces = 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, drct):
		t_ = self.t
		s_ = self.s
		e_ = self.e
		w_ = self.w
		n_ = self.n
		b_ = self.b
		if drct == 'S':
			self.t = n_
			self.s = t_
			self.n = b_
			self.b = s_
		elif drct == 'N':
			self.t = s_
			self.s = b_
			self.n = t_
			self.b = n_
		elif drct == 'E':
			self.t = w_
			self.e = t_
			self.w = b_
			self.b = e_
		elif drct == 'W':
			self.t = e_
			self.e = b_
			self.w = t_
			self.b = w_
		else:
			return
	
	def rotate_right(self):
		s_ = self.s
		w_ = self.w
		n_ = self.n
		e_ = self.e
		self.s = e_
		self.w = s_
		self.n = w_
		self.e = n_
	
	def is_identical(self, other):		
		directions = 'NWNNWW'
		for direction in directions:
			for i in range(4):
				self.rotate_right()
				if self.is_matchall(other): return True
			self.roll(direction)
		return False

	def is_matchall(self, other):
		if self.t != other.t: return False
		if self.s != other.s: return False
		if self.e != other.e: return False
		if self.w != other.w: return False
		if self.n != other.n: return False
		if self.b != other.b: return False
		return True

n = int(input())
dices = [None] * n
for i in range(n):
	faces = list(map(int, input().split()))
	dices[i] = Dice(faces)

for i in range(n):
	for j in range(n):
		if i != j:
			if dices[i].is_identical(dices[j]):
				print('No')
				sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
from itertools import combinations

class Dice(object):

    def __init__(self, nums):
        self.nums = nums
        self.ifaces = [(1,2,3), (2,3,1), (3,1,2),
                       (1,4,2), (4,2,1), (2,1,4),
                       (1,5,4), (5,4,1), (4,1,5),
                       (1,3,5), (3,5,1), (5,1,3),
                       (2,6,3), (6,3,2), (3,2,6),
                       (2,4,6), (4,6,2), (6,2,4),
                       (4,5,6), (5,6,4), (6,4,5),
                       (3,6,5), (6,5,3), (5,3,6),]

    def index(self, num):
        return self.nums.index(num)

    def face(self, iface):
        return [self.nums[i-1] for i in iface]

    def all_face(self):
        for iface in self.ifaces:
            yield self.face(iface)

def is_same(d1, d2):
    for f1 in d1.all_face():
        found = False
        for f2 in d2.all_face():
            if f1 == f2:
                found = True
                break
        if not found:
            return False
    return True

n = int(input())

dices = []
for _ in range(n):
    dices.append(Dice([int(i) for i in input().split()]))

ans = True
for c in combinations(dices, 2):
    if is_same(c[0], c[1]):
        ans = False
        break
if ans:
    print('Yes')
else:
    print('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 < 10:
            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 < 16:
            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')