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:
nl = []
n = int(input())
for i in range(n):
    nl.append(list(map(int,input().split())))
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(6):
            for l in range(4):
                nl[i] = [nl[i][0],nl[i][3],nl[i][1],nl[i][4],nl[i][2],nl[i][5]]
                if nl[i] == nl[j]:
                    print("No")
                    exit()
            if k % 2 == 0:
                nl[i] = [nl[i][4],nl[i][0],nl[i][2],nl[i][3],nl[i][5],nl[i][1]]
            else:
                nl[i] = [nl[i][2],nl[i][1],nl[i][5],nl[i][0],nl[i][4],nl[i][3]]
print("Yes")

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, ls = [0 for i in range(6)]):
        self.ls = ls
        
    def now(self):
        return ls
    
    def S(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[4]
        n_ls[1] = ls[0]
        n_ls[2] = ls[2]
        n_ls[3] = ls[3]
        n_ls[4] = ls[5]
        n_ls[5] = ls[1]
        
        return Dice(n_ls)
    
    def N(self):
        ls = self.S().S().S().ls
        return Dice(ls)
        
    def E(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[3]
        n_ls[1] = ls[1]
        n_ls[2] = ls[0]
        n_ls[3] = ls[5]
        n_ls[4] = ls[4]
        n_ls[5] = ls[2]
        return Dice(n_ls)
    
    
    def W(self):
        ls = self.E().E().E().ls
        return Dice(ls)
        
        
        
    def R_rot(self):
        return self.E().S().W()
        
    def rot(self, num):
        for _ in range(num):
            self = self.R_rot()
        return self

n = int(input())

ls = [ list(map(int, input().split())) for _ in range(n)]


a = Dice(ls[0])

me = [a, a.N(), a.W(), a.E(), a.S(), a.S().S()]

judge = False

for i in me:
    for j in range(4):
        #print(i.rot(j).ls)
        for k in ls:
            
            if i.rot(j).ls != a.ls and i.rot(j).ls == k:
                judge = True#一致するものあり
                

if judge == True:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
# coding: utf-8
import copy
class Dice:
    
    def __init__(self, d):
        self.data = {"bottom":d[5], "north":d[4], "west": d[3],
                    "east":d[2],"south":d[1],"top":d[0]}

    def moveOne(self, direction):
        if direction == "W":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["west"]
            self.data["west"] = self.data["top"]
            self.data["top"] = self.data["east"]
            self.data["east"] = temp
        elif direction == "E":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["east"]
            self.data["east"] = self.data["top"]
            self.data["top"] = self.data["west"]
            self.data["west"] = temp
        elif direction == "N":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["north"]
            self.data["north"] = self.data["top"]
            self.data["top"] = self.data["south"]
            self.data["south"] = temp
        elif direction == "S":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["south"]
            self.data["south"] = self.data["top"]
            self.data["top"] = self.data["north"]
            self.data["north"] = temp

    def movePart(self, directions):
        for direction in directions:
            self.moveOne(direction)
            
    def setDiceII(self, a, b):
        if self.data["east"] == a:
            self.moveOne("W")
        elif self.data["north"] == a:
            self.moveOne("S")
        elif self.data["west"] == a:
            self.moveOne("E")
        elif self.data["south"] == a:
            self.moveOne("N")
        elif self.data["bottom"] == a:
            self.movePart("WW")

        if self.data["north"] == b:
            self.rotateRight()
            self.rotateRight()
        elif self.data["east"] == b:
            self.rotateRight()
        elif self.data["west"] == b:
            self.rotateLeft()
            
        # self.printDice()
    
    def rotateRight(self):
        temp = self.data["east"]
        self.data["east"] = self.data["north"]
        self.data["north"] = self.data["west"]
        self.data["west"] = self.data["south"]
        self.data["south"] = temp
    
    def rotateLeft(self):
        temp = self.data["west"]
        self.data["west"] = self.data["north"]
        self.data["north"] = self.data["east"]
        self.data["east"] = self.data["south"]
        self.data["south"] = temp
      
    def getSurface(self):
        return self.data["top"]
    
    def getEast(self):
        return self.data["east"]
    
    def getData(self):
        return self.data
    
    def getPatterns(self):
        patterns = []
        temp0 = copy.copy(self.getData())
        for i in range(4):
            tempi = copy.copy(self.getData())
            for ip in range(i):
                self.moveOne("N")
            for j in range(4):
                tempj = copy.copy(self.getData())
                for jp in range(j):
                    self.moveOne("E")
                patterns.append(copy.copy(self.getData()))
                self.data = tempj
            self.data = tempi
        self.rotateRight()
        for i in range(4):
            tempi = copy.copy(self.getData())
            for ip in range(i):
                self.moveOne("N")
            for j in range(4):
                tempj = copy.copy(self.getData())
                for jp in range(j):
                    self.moveOne("E")
                patterns.append(copy.copy(self.getData()))
                self.data = tempj
            self.data = tempi
        self.data = temp0
        return patterns
                

    def printDice(self):
        print(self.data["north"])
        print(str(self.data["west"]) + " " + str(self.data["bottom"]) + " " + str(self.data["east"]) )
        print(self.data["south"])
        print(self.data["top"])

n = int(input().rstrip())
num = []
dice = []
for i in range(n):
    num.append(list(map(int,input().rstrip().split())))
for i in range(n):
    dice.append(Dice(num[i]))

flag = True
for i in range(n-1):
    for j in range(i+1,n):
        for k in dice[j].getPatterns():
            if dice[i].getData() == k:
                flag = False
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
num = int(input())
dice_ = [0 for i in range(num)]
dice = [0 for i in range(num)]
rdice = [0 for i in range(num)]
ndice_ = [0 for i in range(num)]
ndice = [0 for i in range(num)]
nrdice = [0 for i in range(num)]
dice_norm = [0 for i in range(num)]
varif = [0 for i in range(num)]
varif_child = [0 for i in range(6)]

def cross(a,b):
	return((a[1]*b[2]-a[2]*b[1], a[2]*b[0]-a[0]*b[2], a[0]*b[1]-a[1]*b[0]))

for n in range(num):
	dice_[n] = [int(i) for i in input().split()]
	
	dice[n] = {
		(0,0,1):dice_[n][0],
		(0,-1,0):dice_[n][1],
		(1,0,0):dice_[n][2],
		(-1,0,0):dice_[n][3],
		(0,1,0):dice_[n][4],
		(0,0,-1):dice_[n][5]
	}

for n in range(num):
	dice_keys = [i for i in dice[n].keys()]
	for count,min_ in enumerate(dice_keys):
		opposing = tuple([-i for i in min_])
		sides = list(set(dice_keys) - set([opposing,min_]))
		one = sides[0]
		two = cross(min_, one)
		three = cross(min_, two)
		four = cross(min_, three)
		varif_child[count] = min([1*dice[n][min_] + 10*dice[n][on] + 100*dice[n][tw] + 1000*dice[n][th] + 10000*dice[n][fo] + 100000*dice[n][opposing] for on,tw,th,fo in [[one,two,three,four],[four,one,two,three],[three,four,one,two],[two,three,four,one]]])
	varif[n] = min(varif_child)

if len(list(set(varif))) == num:
	print("Yes")
else:
	print('No')

Submission status: Accepted

Solution code:
nums = int(input())
dice = []
for _ in range(nums):
    dice.append(list(map(int, input().split())))


class die:
    face = [0, 0, 0, 0, 0, 0]

    def __init__(self, nums):
        self.face = [nums[f] for f in [0, 3, 1, 2, 4, 5]]

    def roll(self, dirs):

        for di in dirs:
            c_face = list(self.face)
            if di == 'S':
                self.face = [c_face[f] for f in [4, 1, 0, 3, 5, 2]]
            elif di == 'N':
                self.face = [c_face[f] for f in [2, 1, 5, 3, 0, 4]]
            elif di == 'W':
                self.face = [c_face[f] for f in [3, 0, 2, 5, 4, 1]]
            elif di == 'E':
                self.face = [c_face[f] for f in [1, 5, 2, 0, 4, 3]]
            # print(di, self.face)

        return list(self.face)


def search():
    for i, d1 in enumerate(dice):
        dice_set_01 = set()
        for md in (' ', 'W', 'E', 'NW', 'NE', 'WW'):
            d_1 = die(d1)
            d_1.roll(md)
            for r in 'SSSS':
                dice_set_01.add(tuple(d_1.roll(r)))

        for j, d2 in enumerate(dice[i+1:], start=i+1):
            dice_set_02 = set()
            for md in (' ', 'W', 'E', 'NW', 'NE', 'WW'):
                d_2 = die(d2)
                d_2.roll(md)
                for r in 'SSSS':
                    dice_set_02.add(tuple(d_2.roll(r)))
            if dice_set_01 - dice_set_02 == set():
                return False
    return True


print(['No', 'Yes'][search()])

Submission status: Accepted

Solution code:
import math


class Dice:
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

    def roll_east(self):
        tmp = self.top
        self.top = self.west
        self.west = self.bottom
        self.bottom = self.east
        self.east = tmp

    def roll_north(self):
        tmp = self.top
        self.top = self.south
        self.south = self.bottom
        self.bottom = self.north
        self.north = tmp

    def roll_south(self):
        tmp = self.top
        self.top = self.north
        self.north = self.bottom
        self.bottom = self.south
        self.south = tmp

    def roll_west(self):
        tmp = self.top
        self.top = self.east
        self.east = self.bottom
        self.bottom = self.west
        self.west = tmp

    def spin_left(self):
        tmp = self.north
        self.north = self.east
        self.east = self.south
        self.south = self.west
        self.west = tmp

    def check(self, dice2):
        ans = False
        for x in range(4):
            if dice2.south == self.south:
                if dice2.east == self.east and dice2.west == self.west and \
                        dice2.north == self.north and dice2.bottom == self.bottom:
                    ans = True
            self.spin_left()
        return ans

    def top_check(self, dice2):
        ans = False
        if dice2.top == self.top:
            ans |= self.check(dice2)
        if dice2.top == self.south:
            self.roll_north()
            ans |= self.check(dice2)
        if dice2.top == self.east:
            self.roll_west()
            ans |= self.check(dice2)
        if dice2.top == self.west:
            self.roll_east()
            ans |= self.check(dice2)
        if dice2.top == self.north:
            self.roll_south()
            ans |= self.check(dice2)
        if dice2.top == self.bottom:
            self.roll_south()
            self.roll_south()
            ans |= self.check(dice2)
        return ans


num = int(input())
dices = []
ans = True
for x in range(num):
    a, b, c, d, e, f = map(int, input().split())
    dices.append(Dice(a, b, c, d, e, f))
for x in range(num):
    for y in range(x + 1, num):
        if dices[x].top_check(dices[y]):
            ans = False
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
class DICE:
    def __init__(self, li = [1,2,3,4,5,6]):
        self.vals = li
        self.nextkeys = [1, 4, 3, 2] # 2 5 4 3 nsew
        self.nowkey = 0
        self.c_key = 5
        self.nowval = li[0]
        self.distvals = []
        tmp = self.nextkeys + [self.nowkey,self.c_key]
        for t in tmp:
            self.distvals.append(self.vals[t]) 
    def operate(self, s):
        pastkey = self.nowkey
        if s == 'N':
            self.nowkey = self.nextkeys[0]
            self.nextkeys[0] = self.c_key
            self.nextkeys[1] = pastkey
        elif s == 'S':
            self.nowkey = self.nextkeys[1]
            self.nextkeys[1] = self.c_key
            self.nextkeys[0] = pastkey
        elif s == 'E':
            self.nowkey = self.nextkeys[2]
            self.nextkeys[2] = self.c_key
            self.nextkeys[3] = pastkey
        elif s == 'W':
            self.nowkey = self.nextkeys[3]
            self.nextkeys[3] = self.c_key
            self.nextkeys[2] = pastkey
        self.nowval = self.vals[self.nowkey]
        self.c_key = abs(5 - self.nowkey)
        self.distvals = []
        tmp = self.nextkeys + [self.nowkey,self.c_key]
        for t in tmp:
            self.distvals.append(self.vals[t]) 

n = int(input())
flag = False
diceval = [[]] * n
for i in range(n):
    diceval[i] = list(map(int, input().split()))
s = 'NNNNWNNNNWNNNNWNNNN'+'NEEEENEEEENEEEENEEEE'+'ENWWWWNWWWWNWWWWNWWWWW'
for j in range(n - 1):
    if flag == True: break
    for k in range(j + 1, n):
        if flag == True: break
        diceA = DICE(li = diceval[j])
        diceB = DICE(li = diceval[k])
        for i in s:
            diceA.operate(i)
            if diceA.distvals == diceB.distvals:
                print('No')
                flag = True
                break
if flag == False:
    print('Yes')

Submission status: Accepted

Solution code:
class Dice:
        def __init__(self, strList):
                self.label = strList[:]
                self.label[0] = int(self.label[0])
                self.label[1] = int(self.label[1])
                self.label[2] = int(self.label[2])
                self.label[3] = int(self.label[3])
                self.label[4] = int(self.label[4])
                self.label[5] = int(self.label[5])
        def reset(self, strList):
                self.label = strList[:]
                self.label[0] = int(self.label[0])
                self.label[1] = int(self.label[1])
                self.label[2] = int(self.label[2])
                self.label[3] = int(self.label[3])
                self.label[4] = int(self.label[4])
                self.label[5] = int(self.label[5])
        def rollE(self):
                temp = self.label[3]
                self.label[3] = self.label[5]
                self.label[5] = self.label[2]
                self.label[2] = self.label[0]
                self.label[0] = temp
        def rollN(self):
                temp = self.label[0]
                self.label[0] = self.label[1]
                self.label[1] = self.label[5]
                self.label[5] = self.label[4]
                self.label[4] = temp
        def rollA(self):
                temp = self.label[3]
                self.label[3] = self.label[4]
                self.label[4] = self.label[2]
                self.label[2] = self.label[1]
                self.label[1] = temp
        def printDice(self):
                print(self.label)

def check(d1, d2):
        for i in range(6):
                if d1.label[i] != d2.label[i]:
                        return False
        return True
        
num = int(input())
diceList = []

for i in range(num):
        diceList.append(Dice(input().split()))

isSame = False

for a in range(num):
        for b in range(a + 1, num):
                for j in range(6):
                        for k in range(4):
                                diceList[a].rollA()
                                if check(diceList[a], diceList[b]):
                                        isSame = True
                                        break
                        if j % 2 == 0:
                                diceList[a].rollE()
                        else:
                                diceList[a].rollN()
                        if isSame:
                                break
                if isSame:
                        break
        if isSame:
                break

if isSame:
        print('No')
else:
        print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
a = [0] * n
b = 1
for i in range(n):
	a[i] = list(map(int, input().split()))
for i in range(n - 1):
	for j in range(i + 1, n):
		for k in range(4):
			t = a[i][0]
			a[i][0] = a[i][1]
			a[i][1] = a[i][5]
			a[i][5] = a[i][4]
			a[i][4] = t
			for u in range(4):
				v = a[i][1]
				a[i][1] = a[i][2]
				a[i][2] = a[i][4]
				a[i][4] = a[i][3]
				a[i][3] = v
				if a[i] == a[j]:
					b = 0
		for k in range(4):
			t = a[i][0]
			a[i][0] = a[i][2]
			a[i][2] = a[i][5]
			a[i][5] = a[i][3]
			a[i][3] = t
			for u in range(4):
				v = a[i][1]
				a[i][1] = a[i][2]
				a[i][2] = a[i][4]
				a[i][4] = a[i][3]
				a[i][3] = v
				if a[i] == a[j]:
					b = 0
if b:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self, faces):
        self.top = faces[0]
        self.front = faces[1]
        self.right = faces[2]
        self.left = faces[3]
        self.back = faces[4]
        self.bottom = faces[5]

    def rotate(self, command):
        pre_top = self.top
        if command == "N":
            self.top = self.front
            self.front = self.bottom
            self.bottom = self.back
            self.back = pre_top
        elif command == "E":
            self.top = self.left
            self.left = self.bottom
            self.bottom = self.right
            self.right = pre_top
        elif command == "W":
            self.top = self.right
            self.right = self.bottom
            self.bottom = self.left
            self.left = pre_top
        elif command == "S":
            self.top = self.back
            self.back = self.bottom
            self.bottom = self.front
            self.front = pre_top
        elif command == "R":
            pre_front = self.front
            self.front = self.left
            self.left = self.back
            self.back = self.right
            self.right = pre_front


def main() -> None:
    dice = [Dice(list(map(int, input().split()))) for _ in range(int(input()))]

    for a in range(len(dice)):
        for b in range(a):
            dice_x = dice[a]
            dice_y = dice[b]

            for i in range(4):
                dice_x.rotate("N")
                for j in range(4):
                    dice_x.rotate("E")
                    for k in range(4):
                        dice_x.rotate("R")

                        if dice_x.top != dice_y.top:
                            pass
                        elif dice_x.bottom != dice_y.bottom:
                            pass
                        elif dice_x.left != dice_y.left:
                            pass
                        elif dice_x.right != dice_y.right:
                            pass
                        elif dice_x.front != dice_y.front:
                            pass
                        elif dice_x.back != dice_y.back:
                            pass
                        else:
                            print("No")
                            return
    print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
D = [[1, 3, 4, 2], [5, 3, 0, 2], [5, 1, 0, 4], [5, 4, 0, 1], [2, 0, 3, 5], [1, 2, 4, 3]]
n = int(input())
d = [[int(i) for i in input().split()] for _ in range(n)]
for x in range(n - 1):
    a = d[x]
    for y in range(x + 1, n):
        b = d[y]
        count = 0
        if set(a) != set(b):
            break
        for i in range(6):
            if a[i] == b[i]:
                count += 1
                continue
            A = [a[k] for k in D[i]]
            B = [b[k] for k in D[b.index(a[i])]]
            if set(A) != set(B):
                break
            if A != B:
                for j in range(4):
                    if A[j] != B[j]:
                        dif = (B.index(A[j]) - j)
                        B = B[dif:] + B[:dif]
                        break
            if A == B:
                count += 1
            else:
                break
        if count == 6:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
# Dice IV
# 2018/11/17, 2019/1/16
from collections import Counter
import sys

class Dice:
    def __init__(self, *num):
        if len(num) != 6:
            raise ValueError("6!")
        self.numbers = num

    def east(self):
        index = (3, 1, 0, 5, 4, 2)
        self.numbers = tuple((self.numbers[i] for i in index))

    def west(self):
        index = (2, 1, 5, 0, 4, 3)
        self.numbers = tuple((self.numbers[i] for i in index))

    def south(self):
        index = (4, 0, 2, 3, 5, 1)
        self.numbers = tuple((self.numbers[i] for i in index))

    def north(self):
        index = (1, 5, 2, 3, 0, 4)
        self.numbers = tuple((self.numbers[i] for i in index))

    def rot_top(self):
        """topを変えないように時計周りにくるくる回す"""
        index = (0, 2, 4, 1, 3, 5)
        self.numbers = tuple((self.numbers[i] for i in index))

    @property
    def top(self):
        return self.numbers[0]

    @property
    def front(self):
        return self.numbers[1]

    @property
    def right(self):
        return self.numbers[2]

    def __repr__(self):
        return "Dice(" + ", ".join([str(i) for i in self.numbers]) + ")"


    def align_top_and_front(self, tmp_dice):
        # topを一番レアいやつにする
        rarest = Counter(self.numbers).most_common()[-1][0]
        for i in range(4):
            if self.top == rarest:
                break
            self.east()
        for i in range(4):
            if self.top == rarest:
                break
            self.north()

        # topが合うまで回す
        for i in range(4):
            if self.top == tmp_dice.top:
                break
            tmp_dice.east()

        for i in range(4):
            if self.top == tmp_dice.top:
                break
            tmp_dice.north()

        # frontを合わせる
        for i in range(4):
            if self.front == tmp_dice.front:
                break
            tmp_dice.rot_top()
        return tmp_dice

    def equals(self, other_dice):
        tmp = Dice(*other_dice.numbers)
        tmp = self.align_top_and_front(tmp)
        #print(self.numbers)
        #print(tmp.numbers)
        if self.numbers == tmp.numbers:
            return True
        else:
            return False


def main():
    all_different = True
    n = int(input())
    dice = [Dice(*[int(i) for i in input().split()]) for _ in range(n)]

    for i in range(n-1):
        for j in range(i+1, n):
            if dice[i].equals(dice[j]):
                all_different = False

    if all_different:
        print("Yes")
    else:
        print("No")
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, array):
        self.top = array[0]
        self.south = array[1]
        self.east = array[2]
        self.west = array[3]
        self.north = array[4]
        self.bottom = array[5]

    def roll_n(self):
        self.top, self.south, self.north, self.bottom = self.south, self.bottom, self.top, self.north

    def roll_s(self):
        self.top, self.south, self.north, self.bottom = self.north, self.top, self.bottom, self.south

    def roll_e(self):
        self.top, self.east, self.west, self.bottom = self.west, self.top, self.bottom, self.east

    def roll_w(self):
        self.top, self.east, self.west, self.bottom = self.east, self.bottom, self.top, self.west

    def IsEqual(self, dice2):
        if (self.top, self.south, self.east, self.west, self.north, self.bottom) == (dice2.top, dice2.south, dice2.east, dice2.west, dice2.north, dice2.bottom):
            return True
        else:
            return False

n = int(input())

n1 = list(map(int, input().split()))
dice_1 = Dice(n1)

flag = False

for i in range(n-1):
    a = list(map(int, input().split()))
    dice_a = Dice(a)
    for i in range(4):
        dice_1.roll_n()
        for j in range(4):
            dice_1.roll_e()
            if dice_1.IsEqual(dice_a):
                flag = True
                break

dice_1.roll_e()

for i in range(4):
    dice_1.roll_n()
    for i in range(4):
        dice_1.roll_e()
        if dice_1.IsEqual(dice_a):
            flag = True
            break



if flag:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
class Dice:
    __TOP = 0
    __FRONT = 1
    __RIGHT = 2
    __LEFT = 3
    __BACK = 4
    __BOTTOM = 5

    def __init__(self, face_val=None):
        self.f_keys = [self.__TOP,  # 0
                       self.__FRONT,  # 1
                       self.__RIGHT,  # 2
                       self.__LEFT,  # 3
                       self.__BACK,  # 4
                       self.__BOTTOM  # 5
                       ]

        if face_val is None or len(face_val) != 6:
            face_val = ['1', '2', '3', '4', '5', '6']

        self.f_key_to_val = {}
        for f_key, val in zip(self.f_keys, face_val):
            self.f_key_to_val[f_key] = val

    MOVE_SWAP_FACES = {
        'S': [(__BACK, __TOP), (__TOP, __FRONT), (__FRONT, __BOTTOM), (__BOTTOM, __BACK)],
        'W': [(__RIGHT, __TOP), (__TOP, __LEFT), (__LEFT, __BOTTOM), (__BOTTOM, __RIGHT)],
        'E': [(__LEFT, __TOP), (__TOP, __RIGHT), (__RIGHT, __BOTTOM), (__BOTTOM, __LEFT)],
        'N': [(__FRONT, __TOP), (__TOP, __BACK), (__BACK, __BOTTOM), (__BOTTOM, __FRONT)],
        'RCW' : [(__LEFT, __FRONT), (__FRONT, __RIGHT), (__RIGHT, __BACK), (__BACK, __LEFT)],   # rotate clockwise
        'RCCW': [(__RIGHT, __FRONT), (__FRONT, __LEFT), (__LEFT, __BACK), (__BACK, __RIGHT)],   # rotate counter clockwise
    }

    def dice_move(self, direction_list):
        for direction in direction_list:
            prev_faces = self.f_keys[:]
            for prev_f, next_f in self.MOVE_SWAP_FACES[direction]:
                self.f_keys[next_f] = prev_faces[prev_f]
            #print(self.f_keys)

    MOVE_TO_TOP = {__TOP:[], __FRONT:['N'], __RIGHT:['W'], __LEFT:['E'], __BACK:['S'], __BOTTOM:['N','N']}

    def dice_fix(self, top: int, front: int):
        # 上面を指定された面にする
        if top != self.f_keys[self.__TOP]:
            now_top = self.f_keys.index(top)
            move = self.MOVE_TO_TOP[now_top]
            self.dice_move(move)

        if top != self.f_keys[self.__TOP]:
            raise AssertionError # not top

        # 前面を指定された面にする
        if front != self.f_keys[self.__FRONT]:
            for i in range(3):
                self.dice_move(['RCW'])
                if front == self.f_keys[self.__FRONT]:
                    break
            else:
                return False    # 3回回転するうちに指定された面がfrontに来ないとおかしい
        return True

    def get_value(self, face):
        return self.f_key_to_val[self.f_keys[face]]

    OPPOSITE_AND_ROUNDS = {0: (5, (1, 3, 4, 2)),
                           1: (4, (0, 2, 5, 3)),
                           2: (3, (0, 4, 5, 1)),
                           3: (2, (0, 1, 5, 4)),
                           4: (1, (0, 3, 5, 2)),
                           5: (0, (1, 2, 4, 3))
                           }

    def is_identical(self, other) -> bool:
        # 含まれるvalueが同じであることをチェック
        self_values = [self.get_value(x) for x in self.f_keys]
        other_values = [other.get_value(x) for x in other.f_keys]
        if set(self_values) != set(other_values):
            return False

        other_top = other.get_value(self.__TOP)

        #other_topと同じ値を持つselfの面を取得
        self_top_faces = filter(lambda x: x[1] == other_top, self.f_key_to_val.items())

        #for　それぞれの面
        other_rounds = [other.get_value(x) for x in self.OPPOSITE_AND_ROUNDS[0][1]]
        other_rounds += other_rounds
        for self_top in self_top_faces:
            #   対面が同じ値 and 側面を回る面の値の列の循環が一致　を満たす場合があったらTrueなかったらFalse
            opposite, rounds = self.OPPOSITE_AND_ROUNDS[self_top[0]]
            if self.get_value(opposite) != other.get_value(self.__BOTTOM):
                continue
            self_rounds = []
            for face in rounds:
                self_rounds.append(self.get_value(face))
            for i in range(4):
                if self_rounds == other_rounds[i:i+4]:
                    return True
        return False

    def __repr__(self):
        return f'({",".join(map(str, self.f_keys))})'


def main():
    n = int(input())
    dice1 = Dice(input().split())

    for i in range(n-1):
        dice2 = Dice(input().split())
        if dice1.is_identical(dice2):
            print('No')
            break
    else:
        print('Yes')


main()

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self, s1, s2, s3, s4, s5, s6):
        self.s1 = s1
        self.s2 = s2
        self.s3 = s3
        self.s4 = s4
        self.s5 = s5
        self.s6 = s6
    def east(self):
        prev_s6 = self.s6
        self.s6 = self.s3
        self.s3 = self.s1
        self.s1 = self.s4
        self.s4 = prev_s6
    def west(self):
        prev_s6 = self.s6
        self.s6 = self.s4
        self.s4 = self.s1
        self.s1 = self.s3
        self.s3 = prev_s6
    def north(self):
        prev_s6 = self.s6
        self.s6 = self.s5
        self.s5 = self.s1
        self.s1 = self.s2
        self.s2 = prev_s6
    def south(self):
        prev_s6 = self.s6
        self.s6 = self.s2
        self.s2 = self.s1
        self.s1 = self.s5
        self.s5 = prev_s6
    def rotate(self):
        prev_s2 = self.s2
        self.s2 = self.s4
        self.s4 = self.s5
        self.s5 = self.s3
        self.s3 = prev_s2
    def top(self):
        return self.s1
    def front(self):
        return self.s2
    def right(self):
        return self.s3

    def isSameDice(self, anotherDice):
        for i in range(6):
            if i % 2 == 0:
                self.north()
            else:
                self.west()
            for j in range(4):
                self.rotate()
                if self.s1 == anotherDice.s1 and \
                   self.s2 == anotherDice.s2 and \
                   self.s3 == anotherDice.s3 and \
                   self.s4 == anotherDice.s4 and \
                   self.s5 == anotherDice.s5 and \
                   self.s6 == anotherDice.s6:
                    return True
        return False


dices = []
n = int(input())
for i in range(n):
    s1, s2, s3, s4, s5, s6 = map(int, input().split())
    dices.append(Dice(s1, s2, s3, s4, s5, s6))

flag = False
for i in range(n):
    j = i+1
    while j < n:
        if dices[i].isSameDice(dices[j]):
            flag = True
            break
        j += 1

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