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

def inputTable(a):
	lit=[]
	for aa in range(a):
		lit.append(list(map(int,input().split())))
	return lit

def kouten(dai):
	x=dai[0]
	dai[0]=dai[1]
	dai[1]=dai[5]
	dai[5]=dai[4]
	dai[4]=x
	return(dai)
def sokuten(dai):
	x=dai[0]
	dai[0]=dai[2]
	dai[2]=dai[5]
	dai[5]=dai[3]
	dai[3]=x
	return(dai)

def tokei(dai):
	dai1 = dai[1]
	dai[1] = dai[2]
	dai[2] = dai[4]
	dai[4] = dai[3]
	dai[3] = dai1
	return(dai)

def check(dai,daini):
	for j in range(4):
		if daini[0] == dai[0] and daini[1] == dai[1] and daini[2] == dai[2] and daini[3] == dai[3] and daini[4] == dai[4] and daini[5] == dai[5]:
			print('No')
			return True
		tokei(dai)
	return False

def checkup(a,b):
	for unuse in range(3):
		if not check(a,b):
			kouten(a)
		else:
			return True
		if not check(a,b):
			sokuten(a)
			if unuse==2 :
				if	not check(a,b) :
					return	False  
		else:
			return True

n=int(input())
daise=inputTable(n)
k=0
R=0
for cc in range(n):
	if k==1:
		break
	for dd in range(cc+1,n):
		if k==1:
			break
		if   checkup(daise[cc],daise[dd]):
			k=1
			break
		
if k==R:
	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):
D = [
    (1, 5, 2, 3, 0, 4), 
    (3, 1, 0, 5, 4, 2), 
    (4, 0, 2, 3, 5, 1), 
    (2, 1, 5, 0, 4, 3), 
]

N = int(input())
L = [None]*N
for i in range(N):
    *L[i], = map(int, input().split())

p = (0, 0, 0, 1, 1, 2, 2, 3)
ok = 1
for i in range(N):
    Li = L[i]
    for j in range(i+1, N):
        Lj = L[j]
        for k in range(24):
            if Li == Lj:
                ok = 0
            Lj[:] = (Lj[e] for e in D[p[k%8]])
print("Yes" if ok else "No")

Solution (Python):
import copy

class Dice:
    
    def __init__(self, n0, n1, n2, n3, n4, n5):
        self.faces = [n0, n1, n2, n3, n4, n5]

    def move(self, op):
        tmp = self.faces[0]
        if op == 'E':
            self.faces[0] = self.faces[3]
            self.faces[3] = self.faces[5]
            self.faces[5] = self.faces[2]
            self.faces[2] = tmp
        elif op == 'N':
            self.faces[0] = self.faces[1]
            self.faces[1] = self.faces[5]
            self.faces[5] = self.faces[4]
            self.faces[4] = tmp
        elif op == 'S':
            self.faces[0] = self.faces[4]
            self.faces[4] = self.faces[5]
            self.faces[5] = self.faces[1]
            self.faces[1] = tmp
        elif op == 'W':
            self.faces[0] = self.faces[2]
            self.faces[2] = self.faces[5]
            self.faces[5] = self.faces[3]
            self.faces[3] = tmp

    def spin_horizontally(self):
        tmp = self.faces[1]
        self.faces[1] = self.faces[2]
        self.faces[2] = self.faces[4]
        self.faces[4] = self.faces[3]
        self.faces[3] = tmp

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

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

    def right(self):
        return self.faces[2]

    def equals(self, other_dice):
        dice = copy.deepcopy(other_dice)
        flg = False
        for i in range(6):

            if i % 2 == 0:
                dice.move('S')
            else:
                dice.move('E')

            if dice.top() == self.top():
                for _ in range(4):
                    dice.spin_horizontally()
                    if dice.front() == self.front():
                        break

            if dice.faces == self.faces:
                flg = True
                break
        return flg

n = int(input())
faces = list(map(int, input().split()))
dice_a = Dice(faces[0], faces[1], faces[2], faces[3], faces[4], faces[5])
ans = 'Yes'
for i in range(n - 1):
    faces = list(map(int, input().split()))
    dice_b = Dice(faces[0], faces[1], faces[2], faces[3], faces[4], faces[5])
    if dice_a.equals(dice_b):
        ans = 'No'
        break

print(ans)

Solution (Python):
import itertools
import sys

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

rng = range(n)
rq = "NNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNN"

for x, y in itertools.combinations(rng,2):
    t = a[x]
    d = a[y]
    for i in rq:
        if i == "E":
          d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
        elif i == "N":
          d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
        elif i == "S":
          d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]
        elif i == "W":
          d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]
    
        if t == d:
          print("No")
          sys.exit()

print("Yes")

Solution (Python):
mask = [[i for i in range(6)], (1, 5, 2, 3, 0, 4), (2, 1, 5, 0, 4,3),(3, 1, 0, 5, 4, 2), (4, 0, 2, 3, 5, 1)]
mask += [[mask[1][i] for i in mask[1]]]

def set_top(dice, top):
    return [dice[i] for i in mask[top]]

def twist(dice):
    return [dice[i] for i in (0, 3, 1, 4, 2, 5)]

def equal(dice1, dice2):
    if sorted(dice1) != sorted(dice2):
        return False
    
    for i in range(6):
        tmp_dice = set_top(dice2, i)
        for _ in range(4):
            if dice1 == tmp_dice:
                return True
            tmp_dice = twist(tmp_dice)
    return False

def diff_check_all(dices, n):
    for i in range(n -1):
        for j in range(i + 1, n):
            if equal(dices[i], dices[j]):
                return False
    return True
            

n = int(input())
dices = [input().split() for _ in range(n)]

print('Yes' if diff_check_all(dices, n) else 'No')

Solution (Python):
import sys


class Dice():

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

    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 equal(self, dice):  
        directions = "EEEENEEEENEEEENEEEEWSEEEESSEEEE"  
        for d in directions:
            self.roll(d)
            for i in range(6):
                if self.number[i] != dice.number[i]:
                    break
                if i == 5:
                    return True
        return False

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

for i in range(n):
    for j in range(i + 1, n):
        if dice_list[i].equal(dice_list[j]):  
            print("No")
            sys.exit()
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,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
 
    def compare(self, label):
        for op in 'EEENEEENEEESEEESEEENEEEN':
            if self.get_label() == label:
                return True
            self.roll(op)
        else:
            return False
   
if __name__=='__main__':
    n = int(input())
    L = []
    for i in range(n):
        label = list(map(int,input().split()))
        for d in L:
            if d.compare(label): break
        else:
            L.append(dice(label))
            continue
        print('No')
        break
    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):
import sys
import itertools


class Dice(object):
    def __init__(self, faces: list):
        self.list_sn = [faces[5], faces[4], faces[0], faces[1]]  
        self.list_we = [faces[5], faces[2], faces[0], faces[3]]  

    def _roll_positive(self, list_a: list, list_b: list) -> list:
        list_a = list_a[1:] + list_a[0:1]  
        list_b[0] = list_a[0]  
        list_b[2] = list_a[2]  
        return [list_a, list_b]

    def _roll_negative(self, list_a: list, list_b: list) -> list:
        list_a = list_a[3:] + list_a[0:3]
        list_b[0] = list_a[0]  
        list_b[2] = list_a[2]  
        return [list_a, list_b]

    def roll(self, direction: str):
        if "N" == direction:
            self.list_sn, self.list_we = self._roll_positive(self.list_sn, self.list_we)
        elif "S" == direction:
            self.list_sn, self.list_we = self._roll_negative(self.list_sn, self.list_we)
        elif "E" == direction:
            self.list_we, self.list_sn = self._roll_positive(self.list_we, self.list_sn)
        else:
            self.list_we, self.list_sn = self._roll_negative(self.list_we, self.list_sn)


if __name__ == "__main__":
    dice_num = int(input())
    dice_list = [
        Dice(list(map(lambda x: int(x), input().split()))) for _ in range(dice_num)
    ]

    for Dice_a, Dice_b in itertools.combinations(dice_list, 2):
        for command in "NNNNWNNNWNNNENNNENNNWNNN":  
            Dice_b.roll(command)
            if Dice_a.list_sn == Dice_b.list_sn and Dice_a.list_we == Dice_b.list_we:
                print("No")  
                sys.exit()
    print("Yes")

Solution (Python):
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
 
    def compare(self, label):
        for op in 'EEENEEENEEESEEESEEENEEEN':
            if self.get_label() == label:
                return True
            self.roll(op)
        else:
            return False
   
if __name__=='__main__':
    n = int(input())
    L = []
    for i in range(n):
        label = list(map(int,input().split()))
        for d in L:
            if d.compare(label): break
        else:
            L.append(dice(label))
            continue
        print('No')
        break
    else:
        print('Yes')

Solution (Python):
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
 
    def compare(self, label):
        for op in 'EEENEEENEEESEEESEEENEEEN':
            if self.get_label() == label:
                return True
            self.roll(op)
        else:
            return False
   
if __name__=='__main__':
    n = int(input())
    L = []
    for i in range(n):
        label = list(map(int,input().split()))
        for d in L:
            if d.compare(label): break
        else:
            L.append(dice(label))
            continue
        print('No')
        break
    else:
        print('Yes')

Solution (Python):
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,a,b,c,d,e,f):
        self.A=[a,b,c,d,e,f]

class determine():

    def __init__(self,P,Q):
        self.P=P
        self.Q=Q
    def run(self):
        global point 
        if (self.P.A[0]==self.Q.A[0] and self.P.A[5]==self.Q.A[5]):

            if self.P.A[1]==self.Q.A[1] and self.P.A[2]==self.Q.A[2] and self.P.A[3]==self.Q.A[3] and self.P.A[4]==self.Q.A[4]:
                point=point+1
            elif self.P.A[1]==self.Q.A[2] and self.P.A[2]==self.Q.A[4] and self.P.A[3]==self.Q.A[1] and self.P.A[4]==self.Q.A[3]:
                point=point+1
            elif self.P.A[1]==self.Q.A[4] and self.P.A[2]==self.Q.A[3] and self.P.A[3]==self.Q.A[2] and self.P.A[4]==self.Q.A[1]:
                point=point+1
            elif self.P.A[1]==self.Q.A[3] and self.P.A[2]==self.Q.A[1] and self.P.A[3]==self.Q.A[4] and self.P.A[4]==self.Q.A[2]:
                point=point+1
            else:
                pass
        elif (self.P.A[0]==self.Q.A[1] and self.P.A[5]==self.Q.A[4]):
            if self.P.A[1]==self.Q.A[5] and self.P.A[2]==self.Q.A[2] and self.P.A[3]==self.Q.A[3] and self.P.A[4]==self.Q.A[0]:
                point=point+1
            elif self.P.A[1]==self.Q.A[2] and self.P.A[2]==self.Q.A[0] and self.P.A[3]==self.Q.A[5] and self.P.A[4]==self.Q.A[3]:
                point=point+1
            elif self.P.A[1]==self.Q.A[0] and self.P.A[2]==self.Q.A[3] and self.P.A[3]==self.Q.A[2] and self.P.A[4]==self.Q.A[5]:
                point=point+1
            elif self.P.A[1]==self.Q.A[3] and self.P.A[2]==self.Q.A[5] and self.P.A[3]==self.Q.A[0] and self.P.A[4]==self.Q.A[2]:
                point=point+1
            else:
                pass

        elif (self.P.A[0]==self.Q.A[2]and self.P.A[5]==self.Q.A[3]):
            if self.P.A[1]==self.Q.A[1] and self.P.A[2]==self.Q.A[5] and self.P.A[3]==self.Q.A[0] and self.P.A[4]==self.Q.A[4]:
                point=point+1
            elif self.P.A[1]==self.Q.A[5] and self.P.A[2]==self.Q.A[4] and self.P.A[3]==self.Q.A[1] and self.P.A[4]==self.Q.A[0]:
                point=point+1
            elif self.P.A[1]==self.Q.A[4] and self.P.A[2]==self.Q.A[0] and self.P.A[3]==self.Q.A[5] and self.P.A[4]==self.Q.A[1]:
                point=point+1
            elif self.P.A[1]==self.Q.A[0] and self.P.A[2]==self.Q.A[1] and self.P.A[3]==self.Q.A[4] and self.P.A[4]==self.Q.A[5]:
                point=point+1
            else:
                pass

        elif (self.P.A[0]==self.Q.A[3] and self.P.A[5]==self.Q.A[2]):
            if self.P.A[1]==self.Q.A[1] and self.P.A[2]==self.Q.A[0] and self.P.A[3]==self.Q.A[5] and self.P.A[4]==self.Q.A[4]:
                point=point+1
            elif self.P.A[1]==self.Q.A[0] and self.P.A[2]==self.Q.A[4] and self.P.A[3]==self.Q.A[1] and self.P.A[4]==self.Q.A[5]:
                point=point+1
            elif self.P.A[1]==self.Q.A[4] and self.P.A[2]==self.Q.A[5] and self.P.A[3]==self.Q.A[0] and self.P.A[4]==self.Q.A[1]:
                point=point+1
            elif self.P.A[1]==self.Q.A[5] and self.P.A[2]==self.Q.A[1] and self.P.A[3]==self.Q.A[4] and self.P.A[4]==self.Q.A[0]:
                point=point+1
            else:
                pass

        elif (self.P.A[0]==self.Q.A[4] and self.P.A[5]==self.Q.A[1]):
            if self.P.A[1]==self.Q.A[0] and self.P.A[2]==self.Q.A[2] and self.P.A[3]==self.Q.A[3] and self.P.A[4]==self.Q.A[5]:
                point=point+1
            elif self.P.A[1]==self.Q.A[2] and self.P.A[2]==self.Q.A[5] and self.P.A[3]==self.Q.A[0] and self.P.A[4]==self.Q.A[3]:
                point=point+1
            elif self.P.A[1]==self.Q.A[5] and self.P.A[2]==self.Q.A[3] and self.P.A[3]==self.Q.A[2] and self.P.A[4]==self.Q.A[0]:
                point=point+1
            elif self.P.A[1]==self.Q.A[3] and self.P.A[2]==self.Q.A[0] and self.P.A[3]==self.Q.A[5] and self.P.A[4]==self.Q.A[2]:
                point=point+1
            else:
                pass


        elif (self.P.A[0]==self.Q.A[5] and self.P.A[5]==self.Q.A[0]):
            if self.P.A[1]==self.Q.A[3] and self.P.A[2]==self.Q.A[4] and self.P.A[3]==self.Q.A[1] and self.P.A[4]==self.Q.A[2]:
                point=point+1
            elif self.P.A[1]==self.Q.A[4] and self.P.A[2]==self.Q.A[2] and self.P.A[3]==self.Q.A[3] and self.P.A[4]==self.Q.A[1]:
                point=point+1
            elif self.P.A[1]==self.Q.A[2] and self.P.A[2]==self.Q.A[1] and self.P.A[3]==self.Q.A[4] and self.P.A[4]==self.Q.A[3]:
                point=point+1
            elif self.P.A[1]==self.Q.A[1] and self.P.A[2]==self.Q.A[3] and self.P.A[3]==self.Q.A[2] and self.P.A[4]==self.Q.A[4]:
                point=point+1
            else:
               pass
        else:
            pass
     

if __name__=="__main__":
    
    
    def in_data():
       input_text=""
       input_text=input()
       array=[]
       array=input_text.split()
       return array
    
    def in_number():
        input_n=""
        input_n=input()
        input_n=int(input_n)
        return input_n
    
    
    
    point=0
    ob_array=[]
    i=0
    j=0
    n=in_number()
    for i in range(n):

        number=in_data()
        
        ob_array.append(dice( number[0], number[1], number[2], number[3], number[4], number[5]))

    for i in range(n):

        for j in range(len(ob_array)):
        
            if not i==j:
                det=determine(ob_array[i],ob_array[j])
                det.run()

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

Solution (Python):
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
 
    def compare(self, label):
        for op in 'EEENEEENEEESEEESEEENEEEN':
            if self.get_label() == label:
                return True
            self.roll(op)
        else:
            return False
   
if __name__=='__main__':
    n = int(input())
    L = []
    for i in range(n):
        label = list(map(int,input().split()))
        for d in L:
            if d.compare(label): break
        else:
            L.append(dice(label))
            continue
        print('No')
        break
    else:
        print('Yes')

Solution (Python):
import random
def dice_move(a,s):
    if s=="E":
        return [a[3],a[1],a[0],a[5],a[4],a[2]]
    elif s=="S":
        return [a[4],a[0],a[2],a[3],a[5],a[1]]
    elif s=="W":
        return [a[2],a[1],a[5],a[0],a[4],a[3]]
    elif s=="N":
        return [a[1],a[5],a[2],a[3],a[0],a[4]]
    
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
h=("N","W","S","E")
judge=[True]*n
cnt=0
for i in range(30000):
    num=random.randrange(4)
    a[0]=dice_move(a[0],h[num])
    for i in range(1,n):
        if judge[i] and a[0]==a[i]:
            cnt+=1
            judge[i]=False
print("Yes" if cnt==0 else "No")

Solution (Python):



class Dice:
    def __init__(self, num):
        self.num = num
        
    def roll(self, direction):
        """ 転がす処理 """
        data = []
        new_num = []
        if direction == "N":
            data = [1, 5, 2, 3, 0, 4]
        elif direction == "S":
            data = [4, 0, 2, 3, 5, 1]
        elif direction == "E":
            data = [3, 1, 0, 5, 4, 2]
        elif direction == "W":
            data = [2, 1, 5, 0, 4, 3]
        elif direction == "L":
            data = [0, 2, 4, 1, 3, 5]
        elif direction == "R":
            data = [0, 3, 1, 4, 2, 5]

        for i in data:
            new_num.append(self.num[i])
        self.num = new_num
        
def dice_roll1(dice, dice_tf):
    dice_roll = ""
    top = dice_tf[0]
    
    if dice.num.index(top) == 1:
        dice_roll = "N"
    elif dice.num.index(top) == 2:
        dice_roll = "W"
    elif dice.num.index(top) == 3:
        dice_roll = "E"
    elif dice.num.index(top) == 4:
        dice_roll = "S"
    elif dice.num.index(top) == 5:
        dice_roll = "NN"
        
    return dice_roll

def dice_roll2(dice, dice_tf):
    dice_roll = ""
    front = dice_tf[1]

    if dice.num.index(front) == 2:
        dice_roll = "L"
    elif dice.num.index(front) == 3:
        dice_roll = "R"
    elif dice.num.index(front) == 4:
        dice_roll = "LL"
        
    return dice_roll

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

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

dice_tf = dice_list[0].num[:2]
is_same = True
for i in dice_list[1:]:
    """ 構成が違ったら位置の判定を飛ばす """
    if set(dice_list[0].num) != set(i.num):
        continue
    direction = dice_roll1(i, dice_tf)
    for j in direction:
        i.roll(j)
    direction = dice_roll2(i, dice_tf)
    for j in direction:
        i.roll(j) 
    if i.num == dice_list[0].num:
        is_same = False
        break
if is_same == True:
    print("Yes")
else:
    print("No")