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):
import copy
import sys
class Dice():
    def __init__(self, t, s, e, w, n, b):
        self.a = [t, s, e, w, n, b]
        self.a_org = copy.deepcopy(self.a)

    def reset(self):
        self.a = copy.deepcopy(self.a_org)
    
    def shake(self, me):
        if me == 'S':
            self.b = [self.a[int(i)] for i in '402351']
            self.a = self.b
        elif me == 'N':
            self.b = [self.a[int(i)] for i in '152304']
            self.a = self.b
        if me == 'W':
            self.b = [self.a[int(i)] for i in '215043']
            self.a = self.b
        if me == 'E':
            self.b = [self.a[int(i)] for i in '310542']
            self.a = self.b  
    def get(self, dir):
        if dir == 't': return self.a[0]
        elif dir == 's': return self.a[1]
        elif dir == 'e': return self.a[2]
        elif dir == 'w': return self.a[3]
        else: print('input err', dir)
    def front(self, f):
        self.reset()
        if f == 0:self.shake('S')
        elif f == 4:self.shake('S');self.shake('S')
        elif f == 3:self.shake('E');self.shake('S')
        elif f == 2:self.shake('W');self.shake('S')
        elif f == 5:self.shake('N')

n = int(input())
n1 = list(map(int, input().split()))
nn = [list(map(int, input().split())) for _ in range(n-1)]
d1 = Dice(*n1)

for k in range(n-1):
    n2 = nn[k]
    d2 = Dice(*n2)

    for i in range(6):
        if d1.a == d2.a:
            print('No')
            sys.exit()
        else:
            d2.front(i)
        for j in range(4):
            if j != 0:d2.shake('W')
            if d1.a == d2.a:
                print('No')
                sys.exit()

print('Yes')

Solution (Python):
class Dice:
    def __init__(self,list):
        self.list = []
        for i in range(6):
            self.list.append(list[i])

    def rotate(self,dir):
        if dir == "N":
            self.list[0], self.list[1], self.list[5], self.list[4] = self.list[1], self.list[5], self.list[4], self.list[0]
        elif dir == "S":
            self.list[0], self.list[4], self.list[5], self.list[1] = self.list[4], self.list[5], self.list[1], self.list[0]
        elif dir == "W":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[2], self.list[0], self.list[3], self.list[5]
        elif dir == "E":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[3], self.list[5], self.list[2], self.list[0]
        elif dir == "H":
            self.list[1], self.list[2], self.list[4], self.list[3] = self.list[2], self.list[4], self.list[3], self.list[1]
        elif dir =="V":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[3], self.list[5], self.list[2], self.list[0]
        else:
            pass

    def show(self):
        print("D:{}".format(repr(self.list)))

    def isface(self,f):
        if f in self.list:
            return True
        else:
            return False

    def isSameface(self,b):
        for i in range(len(self.list)):
            if self.list[i] != b.list[i]:
                return False
        return True

    def isSame(self,b):
        for c in "zHHHWHHHEHHHEHHHWHHHWHHH":
            b.rotate(c)
            if self.isSameface(b):
                return True
        return False


def main():
    num = int(input())
    dice =[]
    for i in range(num):
        l = [int(x) for x in input().split()]
        dice.append(Dice(l))

    for i in range(num):
        for j in range(i+1,num):
            if dice[i].isSame(dice[j]):
                print("No")
                exit(0)

    print("Yes")


if __name__  == '__main__':
    main()

Solution (Python):
n = int(input())
dice_list = [list(map(int,input().split())) for i in range(n)]

pattern_list =[[0,1,2,3,4,5],[0,2,4,1,3,5],[0,4,3,2,1,5],[0,3,1,4,2,5],[1,2,0,5,3,4],[1,5,2,3,0,4],[1,3,5,0,2,4],[1,0,3,2,5,4],[2,0,1,4,5,3],[2,4,0,5,1,3],[2,5,4,1,0,3],[2,1,5,0,4,3],[3,0,4,1,5,2],[3,1,0,5,4,2],[3,5,1,4,0,2],[3,4,5,0,1,2],[4,2,5,0,3,1],[4,0,2,3,5,1],[4,3,0,5,2,1],[4,5,3,2,0,1],[5,1,3,2,4,0],[5,2,1,4,3,0],[5,4,2,3,1,0],[5,3,4,1,2,0]]

dice_c_list =[0,0,0,0,0,0]
cnt = 0

for g in range(n-1):
	h = g+1
	while h < n:
		for i in range(24):
			for j in range(6):
				dice_c_list[j]=  dice_list[g][pattern_list[i][j]]
			if dice_c_list == dice_list[h]:
				cnt =1
				break
		h +=1
if cnt==0:
	print("Yes")
else:
	print("No")

Solution (Python):
class Dice:
    
    def __init__(self, lst):
        self.val=[]
        self.val.append(lst[0])
        self.val.append(lst[1])
        self.val.append(lst[2])
        self.val.append(lst[3])
        self.val.append(lst[4])
        self.val.append(lst[5])

    def rotate(self,dir):
        if dir=="N":
            tmp=self.val[0]
            self.val[0]=self.val[1]
            self.val[1]=self.val[5]
            self.val[5]=self.val[4]
            self.val[4]=tmp
        if dir=="E":
            tmp=self.val[0]
            self.val[0]=self.val[3]
            self.val[3]=self.val[5]
            self.val[5]=self.val[2]
            self.val[2]=tmp
        if dir=="S":
            tmp=self.val[0]
            self.val[0]=self.val[4]
            self.val[4]=self.val[5]
            self.val[5]=self.val[1]
            self.val[1]=tmp
        if dir=="W":
            tmp=self.val[0]
            self.val[0]=self.val[2]
            self.val[2]=self.val[5]
            self.val[5]=self.val[3]
            self.val[3]=tmp

def int_to_dir(n):
    if n==0:
        return "N"
    if n==1:
        return "E"
    if n==2:
        return "S"
    if n==3:
        return "W"

import random 

def areSame(D1,D2):
    Determin=False
    for i in range(100):

        D2.rotate(int_to_dir(random.randint(0,4)))

        if D1.val==D2.val:
            Determin=True

    return Determin
    
    
n = int(input())
Instance=[]
for i in range(n):
    x = list(map(int,input().split()))
    Instance.append(Dice(x))
    
    
    

Ans=True
for i in range(n-1):
    for j in range(i+1,n):
        D1=Instance[i]
        D2=Instance[j]
        if areSame(D1,D2):
            Ans=False

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

Solution (Python):
def dice_rotation(dice, command):

	tmp_dice = []
	
	for i in range(6):
		tmp_dice.append(dice[i])

	
	if command == 'S':
		dice[0] = tmp_dice[4]
		dice[4] = tmp_dice[5]
		dice[5] = tmp_dice[1]
		dice[1] = tmp_dice[0]
	
	elif command == 'N':
		dice[0] = tmp_dice[1]
		dice[1] = tmp_dice[5]
		dice[5] = tmp_dice[4]
		dice[4] = tmp_dice[0]
	
	elif command == 'W':
		dice[0] = tmp_dice[2]
		dice[2] = tmp_dice[5]
		dice[5] = tmp_dice[3]
		dice[3] = tmp_dice[0]
	
	elif command == 'E':
		dice[0] = tmp_dice[3]
		dice[3] = tmp_dice[5]
		dice[5] = tmp_dice[2]
		dice[2] = tmp_dice[0]

def dice_spinning(dice):

	tmp_dice = []
	
	for i in range(6):
		tmp_dice.append(dice[i])

	dice[1] = tmp_dice[2]
	dice[2] = tmp_dice[4]
	dice[4] = tmp_dice[3]
	dice[3] = tmp_dice[1]

def comparison_dices(Dice1,Dice2):

	yes_counter = 0
	for j in range(6):
		if Dice1[j] == Dice2[j]:
			yes_counter += 1
	if yes_counter == 6:
		return True

	return False

def full_validation_dices(Dice1,Dice2):

	judgement_result = False

	
	for i in range(4):
		for j in range(4):
			if comparison_dices(Dice1,Dice2) == True:
				judgement_result = True
				break
			else:
				dice_spinning(Dice2)

		if judgement_result == True:
			break
		else:
			dice_rotation(Dice2,'S')

	
	for i in range(4):
		for j in range(4):
			if comparison_dices(Dice1,Dice2) == True:
				judgement_result = True
				break
			else:
				dice_spinning(Dice2)

		if judgement_result == True:
			break
		else:
			dice_rotation(Dice2,'W')

	if judgement_result == True:
		return True
	else:
		return False


def test():

	n = int(input())

	Dices = []

	result = True

	for i in range(n):

		tmp_dice = list(map(int,input().split()))
		Dices.append(tmp_dice)
	
	for i in range(n-1):
		for j in range(i+1,n):
			if full_validation_dices(Dices[i],Dices[j]) == True:
				result = False
				break
		if result == False:
			break

	if result == True:
		print("Yes")
	else:
		print("No")


if __name__ == "__main__":
	test()

Solution (Python):
import copy


class Dice:
    def __init__(self, a, b, c, d, e, f):
        self.top = a
        self.front = b
        self.right = c
        self.left = d
        self.behind = e
        self.bottom = f

    def S(self):
        self.top, self.front, self.behind, self.bottom = self.behind, self.top, self.bottom, self.front

    def N(self):
        self.behind, self.top, self.bottom, self.front = self.top, self.front, self.behind, self.bottom

    def E(self):
        self.top, self.bottom, self.left, self.right = self.left, self.right, self.bottom, self.top

    def W(self):
        self.left, self.right, self.bottom, self.top = self.top, self.bottom, self.left, self.right

    def spin(self):
        self.left, self.behind, self.right, self.front = self.front, self.left, self.behind, self.right

    def __eq__(self, _dice2):
        dice2 = copy.deepcopy(_dice2)
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.N()
        dice2.N()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.N()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.E()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.W()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        dice2 = copy.deepcopy(_dice2)
        dice2.S()
        for i in range(4):
            if self._eqaul(dice2):
                return True
            dice2.spin()
        return False

    def _eqaul(self, dice2):
        return self.front == dice2.front and self.behind == dice2.behind and self.left == dice2.left and self.right == dice2.right and self.top == dice2.top and self.bottom == dice2.bottom

    def __repr__(self):
        return ",".join([str(object=i) for i in (self.top, self.front, self.right, self.left, self.behind, self.bottom)])


n=int(input())
dices=[]
flag=False
for i in range(n):
    d=Dice(*[int(i) for i in input().split(" ")])
    for dice in dices:
        if d==dice:
            flag=True
            break
    dices.append(d)
if flag:
    print("No")
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,odr):
        if   odr=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif odr=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif odr=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif odr=='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 odr in 'EEENEEENEEESEEESEEENEEEN':
            if self.get_label() == label:
                return True
            self.roll(odr)
        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 sys
import copy

line = sys.stdin.readline() 

faces = []

def anydup(thelist): 
    seen = set() 
    for x in thelist: 
        if x in seen: 
            return True 
        seen.add(x) 
    return False

while(True):
    line = sys.stdin.readline() 
    if not line:
        break
    line = line.rstrip('\r\n')
    faces.append(line.split())

for i in range(5):
    face  = faces[-1]
    if face[0] != face[1]:
        break
    face_old = copy.deepcopy(face)
    face[0] = face_old[1]
    face[1] = face_old[5]
    face[2] = face_old[2]
    face[3] = face_old[3]
    face[4] = face_old[0]
    face[5] = face_old[4]
else:
    face_old = copy.deepcopy(face)
    face[0] = face_old[3]
    face[1] = face_old[1]
    face[2] = face_old[0]
    face[3] = face_old[5]
    face[4] = face_old[4]
    face[5] = face_old[2]
for i in range(5):
    if face[0] != face[1]:
        break
    face_old = copy.deepcopy(face)
    face[0] = face_old[1]
    face[1] = face_old[5]
    face[2] = face_old[2]
    face[3] = face_old[3]
    face[4] = face_old[0]
    face[5] = face_old[4]
for i in range(5):
    if face[0] != face[1]:
        break
    face_old = copy.deepcopy(face)
    face[0] = face_old[3]
    face[1] = face_old[1]
    face[2] = face_old[0]
    face[3] = face_old[5]
    face[4] = face_old[4]
    face[5] = face_old[2]

for j in range(len(faces) - 1):
    face  = faces[j]
    face2 = faces[-1]
    for i in range(5):
        if face[1] == face2[1]:
            break
        face_old = copy.deepcopy(face)
        face[0] = face_old[1]
        face[1] = face_old[5]
        face[2] = face_old[2]
        face[3] = face_old[3]
        face[4] = face_old[0]
        face[5] = face_old[4]
    else:
        face_old = copy.deepcopy(face)
        face[0] = face_old[3]
        face[1] = face_old[1]
        face[2] = face_old[0]
        face[3] = face_old[5]
        face[4] = face_old[4]
        face[5] = face_old[2]
    for i in range(5):
        if face[1] == face2[1]:
            break
        face_old = copy.deepcopy(face)
        face[0] = face_old[1]
        face[1] = face_old[5]
        face[2] = face_old[2]
        face[3] = face_old[3]
        face[4] = face_old[0]
        face[5] = face_old[4]
    for i in range(5):
        if face[0] == face2[0]:
            break
        face_old = copy.deepcopy(face)
        face[0] = face_old[3]
        face[1] = face_old[1]
        face[2] = face_old[0]
        face[3] = face_old[5]
        face[4] = face_old[4]
        face[5] = face_old[2]




if any(faces.count(x) > 1 for x in faces):
    print("No")
else:
    print("Yes")

Solution (Python):
def west(d):
	tmp=d[4]
	d[4]=d[1]
	d[1]=d[3]
	d[3]=d[6]
	d[6]=tmp

def east(d):
	tmp=d[4]
	d[4]=d[6]
	d[6]=d[3]
	d[3]=d[1]
	d[1]=tmp

def north(d):
	tmp=d[1]
	d[1]=d[2]
	d[2]=d[6]
	d[6]=d[5]
	d[5]=tmp

def south(d):
	tmp=d[1]
	d[1]=d[5]
	d[5]=d[6]
	d[6]=d[2]
	d[2]=tmp

def spin(d):
	tmp=d[2]
	d[2]=d[3]
	d[3]=d[5]
	d[5]=d[4]
	d[4]=tmp

def kaiten(d, op):
	if   op == "W": west(d)
	elif op == "E": east(d)
	elif op == "N": north(d)
	elif op == "S": south(d)

def inputDice():
	return list(map(int,("-1 "+input()).split()))

def equal(da, db):
	for op in list("NWWWN-"):
		for i in range(4):
			if(da[1]==db[1] and da[2]==db[2] and da[3]==db[3] and da[4]==db[4] and da[5]==db[5] and da[6]==db[6]):
				return True
			spin(db)
		kaiten(db,op)
	return False

def yes(d):
	for i in range(n):
		for j in range(i):
			if equal(d[i], d[j]):
				return False
	return True

n=int(input())

d=[inputDice() for i in range(n)]

if yes(d):
	print("Yes")
else:
	print("No")

Solution (Python):
class dice:
  def __init__(self,dice_number_list):
    self.top,self.front,self.right,self.left,self.rear,self.bottom = dice_number_list
    self.dice_number_list = dice_number_list
    
  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 get_all_number_list(self):
    all_dice_number_list = []
    for op in "NNNNWNNNWNNNENNNENNNWNNN":
      self.roll(op)
      if self.get_label() not in all_dice_number_list:
        all_dice_number_list.append(self.get_label())
    return(sorted(all_dice_number_list))
  
  
  def judge_equal(self,another):
    if(self.get_all_number_list() == another.get_all_number_list()):
       return True
    else:
       return False
  
n = int(input())
dice_list=[[0,0,0,0,0,0]]*n

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

FLG=True
for i in range(n-1):
  for j in range(i+1,n):
    if dice_list[i].judge_equal(dice_list[j]):
      FLG=False
      break

if FLG == True:
  print("Yes")
else:
  print("No")

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

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

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):
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):
def roll(die, d):
    if d == "E":
        return [die[3], die[1], die[0], die[5], die[4], die[2]]
    if d == "N":
        return [die[1], die[5], die[2], die[3], die[0], die[4]]
    if d == "S":
        return [die[4], die[0], die[2], die[3], die[5], die[1]]
    if d == "W":
        return [die[2], die[1], die[5], die[0], die[4], die[3]]
    if d == "L":
        return [die[0], die[3], die[1], die[4], die[2], die[5]]
    if d == "R":
        return [die[0], die[2], die[4], die[1], die[3], die[5]]
 
def checkdice(die1, die2):
    ans = False
    for d in "RRRNRRRNRRRSRRRSRRRNRRRR":
        if die1 == die2:
            ans = True
            break
        die2 = roll(die2, d)
    return ans
 
dice = []
msg = "Yes"
n = int(input())
for _ in range(n):
    dice.append(list(map(int, input().split())))
for i in range(n):
    for j in range(i + 1, n):
        if checkdice(dice[i], dice[j]):
            msg = "No"
            break
    if msg == "No":
        break
print(msg)

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

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 sys

def getKeyFromValue(dice, value):
    keys = [k for k, v in dice.items() if v == value]
    if keys:
        return keys[0]
    return None

def initDice(numbers):  
        
    dice = {'top': numbers[0], 'bottom': numbers[5], 'front': numbers[1],
            'back': numbers[4], 'right': numbers[2], 'left': numbers[3]}
    return dice


def rollDice(dice, direction):  
    if direction == 'N':
        top = dice['front']
        bottom = dice['back']
        front = dice['bottom']
        back = dice['top']
        dice['top'] = top
        dice['bottom'] = bottom
        dice['front'] = front
        dice['back'] = back
    elif direction == 'S':
        top = dice['back']
        bottom = dice['front']
        front = dice['top']
        back = dice['bottom']
        dice['top'] = top
        dice['bottom'] = bottom
        dice['front'] = front
        dice['back'] = back
    elif direction == 'E':
        top = dice['left']
        bottom = dice['right']
        right = dice['top']
        left = dice['bottom']
        dice['top'] = top
        dice['bottom'] = bottom
        dice['right'] = right
        dice['left'] = left
    elif direction == 'W':
        top = dice['right']
        bottom = dice['left']
        right = dice['bottom']
        left = dice['top']
        dice['top'] = top
        dice['bottom'] = bottom
        dice['right'] = right
        dice['left'] = left
    return dice


def spinDice(dice):
    front = dice['right']
    right = dice['back']
    back = dice['left']
    left = dice['front']
    dice['front'] = front
    dice['right'] = right
    dice['back'] = back
    dice['left'] = left
    return dice

def assertDice(dice_1, dice_2):
    if dice_1 == dice_2:
        print('No')
        sys.exit()


def checkDice(dice_1,dice_2):
    assertDice(dice_1, dice_2)
    for i in range(3):
        dice_1 = spinDice(dice_1)
        assertDice(dice_1, dice_2)

def diceIII(dice_1, dice_2):
    checkDice(dice_1,dice_2)

    roll_directions = [['N'], ['S'], ['W'],['E'],['N','N']]

    dice_1 = initDice(numbers_1)

    for direction in roll_directions:
        for d in direction:
            dice_1 = rollDice(dice_1, d)
        checkDice(dice_1,dice_2)
        dice_1 = initDice(numbers_1)

n = int(input())
all_dice_numbers = []
for i in range(n):
  numbers = [int(i) for i in input().split()]
  all_dice_numbers.append(numbers)

for i in range(n):
  numbers_1 = all_dice_numbers[i]
  dice_1 = initDice(numbers_1)

  for j in range(i+1, n):
    if j == n:
      pass
    else :
      numbers_2 = all_dice_numbers[j]
      dice_2 = initDice(numbers_2)
      diceIII(dice_1, dice_2)

print('Yes')