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

Solution (Python):
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()

Solution (Python):
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")

Solution (Python):


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):
        
        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()

        
        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()

        
        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)
        
        
        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()

Solution (Python):
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')

Solution (Python):
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,  
                       self.__FRONT,  
                       self.__RIGHT,  
                       self.__LEFT,  
                       self.__BACK,  
                       self.__BOTTOM  
                       ]

        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)],   
        'RCCW': [(__RIGHT, __FRONT), (__FRONT, __LEFT), (__LEFT, __BACK), (__BACK, __RIGHT)],   
    }

    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]
            

    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 

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

        
        self_top_faces = filter(lambda x: x[1] == other_top, self.f_key_to_val.items())

        
        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:
            
            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()

Solution (Python):
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")

Solution (Python):


class Dice:
    def __init__(self):
        self.diceNum: List[int] = [] 

    def setNum(self,i):
        self.pos = i[0]
        self.diceNum.append(i[0])
        self.diceNum.append(i[1])
        self.diceNum.append(i[2])
        self.diceNum.append(i[3])
        self.diceNum.append(i[4])
        self.diceNum.append(i[5])
    def getTopPos(self):
        return self.diceNum[0]    
    def moveToTopnum(self,n):
        i = 0
        for i in range(0,4):
            if (self.getTopPos() == n ):
                return True
            self.move("S")
        else:
            for j in range(0,4):
                if (self.getTopPos() == n ):
                    return True
                self.move("E")
        return False
    def getFrontPos(self):
        return self.diceNum[1]
    def getRightPos(self):
        return self.diceNum[2]
    def yokoRotate(self):
            i0=self.diceNum[0]
            i1=self.diceNum[2] 
            i2=self.diceNum[4] 
            i3=self.diceNum[1]
            i4=self.diceNum[3]
            i5=self.diceNum[5]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
    def move(self,d):
        if (d == "E"):
            i0=self.diceNum[3]
            i1=self.diceNum[1] 
            i2=self.diceNum[0] 
            i3=self.diceNum[5]
            i4=self.diceNum[4]
            i5=self.diceNum[2]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
        if (d == "W"):
            i0=self.diceNum[2]
            i1=self.diceNum[1] 
            i2=self.diceNum[5] 
            i3=self.diceNum[0]
            i4=self.diceNum[4]
            i5=self.diceNum[3]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
        if (d == "S"):
            i0=self.diceNum[4]
            i1=self.diceNum[0] 
            i2=self.diceNum[2] 
            i3=self.diceNum[3]
            i4=self.diceNum[5]
            i5=self.diceNum[1]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
        if (d == "N"):
            i0=self.diceNum[1]
            i1=self.diceNum[5] 
            i2=self.diceNum[2] 
            i3=self.diceNum[3]
            i4=self.diceNum[0]
            i5=self.diceNum[4]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
    def rotateToFrontnum(self,n):
        for i in range(0,4):
            self.yokoRotate()
            if ( self.getFrontPos() == n):
                return True
        return False
    def isEqual(self,d):
        for i in range(0,6):
            if (self.diceNum[i] != d.diceNum[i]):
                return False
        return True

n = int(input())
l = list(map(int,input().split()))
dice = Dice()
dice.setNum(l)

min = 1000
r_num = 0
for i in set(l):
    if (min > l.count(i)):
       min = l.count(i)
       r_num = i
dice.moveToTopnum(r_num)

ans = "Yes"
for i in range(0,n-1):
    l2 = list(map(int,input().split()))
    dice2 = Dice()
    dice2.setNum(l2)

    t = dice.getTopPos()
    f = dice.getFrontPos()
    r = dice.getRightPos()
    
    if (dice2.moveToTopnum(t) == False ):
         continue
    
    elif (dice2.rotateToFrontnum(f) == False):
        continue
    
    elif (dice.isEqual(dice2) == False ):
        continue
    
    else:
        ans = "No"  
        continue
    
    

print (ans)

Solution (Python):
n=int(input())
d={i:list(input().split()) for i in range(n)}

def roll(Dice,Vector):
    if Vector == "N":
        c=Dice[0]
        Dice[0]=Dice[1]
        Dice[1]=Dice[5]
        Dice[5]=Dice[4]
        Dice[4]=c
    elif Vector == "W":
        c=Dice[0]
        Dice[0]=Dice[2]
        Dice[2]=Dice[5]
        Dice[5]=Dice[3]
        Dice[3]=c
    elif Vector == "E":
        c=Dice[0]
        Dice[0]=Dice[3]
        Dice[3]=Dice[5]
        Dice[5]=Dice[2]
        Dice[2]=c
    elif Vector == "S":
        c=Dice[0]
        Dice[0]=Dice[4]
        Dice[4]=Dice[5]
        Dice[5]=Dice[1]
        Dice[1]=c

v=list("NNNNWNNNWNNNENNNENNNWNNN")
f=0
for i in range(n):
    if f==0:
        for item in v:
            roll(d[i],item)
            if f==0:
                for j in range(i+1,n):
                    if d[i]==d[j]:
                        f+=1
                        break
if f==0:
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())
slist = "NNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNN"

mat = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
    mat[i] = list(map(int, input().split()))

for i in range(n):
    for j in range(i+1, n):
        for s in slist:
            if s == "N":
                next = list("263415")
            elif s == "E":
                next = list("421653")
            elif s == "S":
                next = list("513462")
            else:
                next = list("326154")

            tmp = [0] * 6
            for k, nex in enumerate(next):
                tmp[k] = mat[j][int(nex)-1]

            mat[j] = tmp

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

print("Yes")

Solution (Python):
n=int(input())
e=[[0 for i in range(6)]for j in range(n)]
for i in range(n):
	a=list(map(int,input().split()))
	e[i]=a	
for i in range(n-1):
	if e[0][0]==e[i+1][1]:
		e[i+1][0],e[i+1][1],e[i+1][4],e[i+1][5]=e[i+1][1],e[i+1][5],e[i+1][0],e[i+1][4]		
	elif e[0][0]==e[i+1][2]:
		e[i+1][0],e[i+1][2],e[i+1][3],e[i+1][5]=e[i+1][2],e[i+1][5],e[i+1][0],e[i+1][3]
	elif e[0][0]==e[i+1][3]:
		e[i+1][0],e[i+1][2],e[i+1][3],e[i+1][5]=e[i+1][3],e[i+1][0],e[i+1][5],e[i+1][2]	
	elif e[0][0]==e[i+1][4]:
		e[i+1][0],e[i+1][1],e[i+1][4],e[i+1][5]=e[i+1][4],e[i+1][0],e[i+1][5],e[i+1][1]		
	elif e[0][0]==e[i+1][5]:
		e[i+1][0],e[i+1][1],e[i+1][4],e[i+1][5]=e[i+1][5],e[i+1][4],e[i+1][1],e[i+1][0]
		
	for k in range(4):
		if 	e[0][1]!=e[i+1][1]:
			e[i+1][1],e[i+1][2],e[i+1][4],e[i+1][3]=e[i+1][3],e[i+1][1],e[i+1][2],e[i+1][4]
		else:
			break
count=0
for i in range(n):
	for j in range(n):
		if e[i]==e[j]:
			count=count+1
if count==n:
	print('Yes')
else:
	print('No')

Solution (Python):
n = int(input())
d_L = [list(map(int, input().split())) for i in range(n)]  
from collections import OrderedDict
def make_p(d):
    p = OrderedDict()
    for k, v in zip(["T", "N", "S", "E", "W", "B"], [d[0], d[4], d[1], d[2], d[3], d[5]]):
        p[k] = v
    return p
def judge_dice(d, d2):
    p, p2 = make_p(d), make_p(d2)
    for c in "SSSWNNNWNNNESSSWNNNESSSX":       
        t, n, s, e, w, b = p["T"], p["N"], p["S"], p["E"], p["W"], p["B"]
        if p == p2:
            return 0
            break
        if c == "N":
            p["N"], p["T"], p["S"], p["B"]= t, s, b, n
        if c == "S":
            p["N"], p["T"], p["S"], p["B"]= b, n, t, s
        if c == "E":
            p["E"], p["T"], p["W"], p["B"]= t, w, b, e
        if c == "W":
            p["E"], p["T"], p["W"], p["B"]= b, e, t, w       
         
for i, d in enumerate(d_L):
    if d == d_L[-1]:
        print("Yes")
    for d2 in d_L[i+1:]:
        if judge_dice(d, d2) == 0:
            print("No")
            break
    else:
        continue
    break

Solution (Python):
import sys

def swap(dice,i,j,k,l):
    x=dice[l]
    dice[l]=dice[k]
    dice[k]=dice[j]
    dice[j]=dice[i]
    dice[i]=x
    return dice

def Sroll(dice):
    dice=swap(dice,0,1,5,4)
    return dice

def Eroll(dice):
    dice=swap(dice,0,2,5,3)
    return dice

def Wroll(dice):
    dice=swap(dice,0,3,5,2)
    return dice

def Nroll(dice):
    dice=swap(dice,0,4,5,1)
    return dice


def judge(dice1,dice2):
    top=dice1[0]
    fro=dice1[1]

    for j in range(0,8):
        if(fro==dice2[1]):
            break
        if(j==3):
            dice2=Eroll(dice2)
        if(j==7):
            return 0
        dice2=Sroll(dice2)
        
    i=0
    while(top!=dice2[0]):
        dice2=Eroll(dice2)
        if(i==3):
             return 0
        i+=1


    if(dice1[2]==dice2[2] and dice1[3]==dice2[3] and dice1[4]==dice2[4] and dice1[5]==dice2[5]):
        return 1
    else:
        return 0


n=int(input())

if(n==1):
    print("Yes")
    sys.exit()

Dice=[[]]

for i in range(0,n):
    Dice.append(list(map(int,input().split())))
del Dice[0]

for i in range(0,n):
    for j in range(i+1,n):
        if(judge(Dice[i],Dice[j])):
            print("No")
            sys.exit()


print("Yes")

Solution (Python):
from enum import Enum
import sys
import math



class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.pattern = 'NNNNENNNENNNWNNNWNNNENNN'
        self.ret = 0
        
    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 match(self, Std):
        for i in range(6):
            self.work[i] = self.number[i]
        
        for i in range(len(self.pattern)):
            self.roll(self.pattern[i])
            if self.number == Std:
                self.ret = 1
                break
                
    def get_ret(self):
        return self.ret

total = 0
n = int(input())
dice = [''] * n

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

for i in range(1, n):
    dice[i].match(dice[0].number)

for i in range(1, n):
    total += int(dice[i].ret)

if total > 0:
    print('No')
else:
    print('Yes')

Solution (Python):
def cmp_dice(a, b):
    for _ in range(4):
        b[0],b[4],b[5],b[1]=b[1],b[0],b[4],b[5]
        for _ in range(4):
            b[1],b[2],b[4],b[3]=b[3],b[1],b[2],b[4]
            for _ in range(4):
                b[0],b[4],b[5],b[1]=b[1],b[0],b[4],b[5]
                if a==b:
                    return True
    return False

dd = []
for _ in range(int(input())):
    dd.append([int(i)-1 for i in input().split()])

for i in range(len(dd)-1):
    for j in range(i+1, len(dd)):
        if cmp_dice(dd[i],dd[j]):
            print('No')
            exit()
print('Yes')

Solution (Python):
class Dice :
    def __init__(self, pane):
        self.pane = pane
    
    def roll_W(self):
        temp = self.pane[0]
        self.pane[0] = self.pane[2]
        self.pane[2] = self.pane[5]
        self.pane[5] = self.pane[3]
        self.pane[3] = temp

    def roll_S(self):
        temp = self.pane[0]
        self.pane[0] = self.pane[4]
        self.pane[4] = self.pane[5]
        self.pane[5] = self.pane[1]
        self.pane[1] = temp

n = int(input())
dice = []
for i in range(0, n):
    dice.append(Dice(input().split()))  

flag = False
for k in range(0, n):
    for i in range(k + 1, n):
        count = 0
        while True:
            t = dice[k].pane[0]
            f = dice[k].pane[1]
            if (dice[i].pane[0] == f or dice[i].pane[4] == f):
                dice[i].roll_S()
            if (dice[i].pane[0] == t and dice[i].pane[1] == f):
                break
            if (count >= 8):
                break
            count += 1
            dice[i].roll_W()

        for j in range(0, len(dice[k].pane)):
            if (dice[k].pane[j] != dice[i].pane[j]):
                break
            if (j == len(dice[k].pane) - 1):
                flag = True

        if (flag):
            break

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

Solution (Python):
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


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")

Solution (Python):
class Dice:
    def __init__(self, pip):
        self.pip = pip
    
    def move(self, dir):
        if str(dir) == 'E':
            self.pip[0], self.pip[2], self.pip[3], self.pip[5] = \
                self.pip[3], self.pip[0], self.pip[5], self.pip[2]
        elif str(dir) == 'W':
            self.pip[0], self.pip[2], self.pip[3], self.pip[5] = \
                self.pip[2], self.pip[5], self.pip[0], self.pip[3]
        elif str(dir) == 'N':
            self.pip[0], self.pip[1], self.pip[4], self.pip[5] = \
                self.pip[1], self.pip[5], self.pip[0], self.pip[4]
        elif str(dir) == 'S':
            self.pip[0], self.pip[1], self.pip[4], self.pip[5] = \
                self.pip[4], self.pip[0], self.pip[5], self.pip[1]


n = int(input())
dices = [Dice(list(map(int, input().split()))) for _ in range(n)]
check = "Yes"

for i in range(len(dices)-1):
    for j in range(i+1, len(dices)):
        tmp = Dice(dices[j].pip)
        for x in "EEENEEENEEESEEESEEENEEEN":
            if dices[i].pip == tmp.pip:
                check = "No"
                break
            tmp.move(x)
print(check)