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):
houkou={'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3)}
moji="SSSSEEEENEEEENEEEENEEEENWSSSSWSSSSWSSSSWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWN:"
answer=0

n=int(input())
S=[0]*n
for i in range(n):
  S[i]=list(map(int,input().split()))
  
for i in range(n):
  for j in range(i+1,n):
    for k in range(len(moji)):
      if moji[k]==":":
        answer+=0
        break
      if S[j]==S[i]:
        answer+=1
        break
      S[j]=[S[j][l]for l in houkou[moji[k]]]
if answer==0:
    print("Yes")
else:
    print("No")

Solution (Python):
from sys import exit

def rotate(l, d):
    if d == 'S':
        return [l[4], l[0], l[2], l[3], l[5], l[1]]
    if d == 'N':
        return [l[1], l[5], l[2], l[3], l[0], l[4]]
    if d == 'W':
        return [l[2], l[1], l[5], l[0], l[4], l[3]]
    if d == 'E':
        return [l[3], l[1], l[0], l[5], l[4], l[2]]
    if d == 'R':
        return [l[0], l[2], l[4], l[1], l[3], l[5]]

def check(d1, d2):
    for k in 'EE':
        for i in 'NNNN':
            for j in 'RRRR':
                if d1 == d2:
                    return 1
                else:
                    d2 = rotate(d2, j)
            d2 = rotate(d2, i)
        d2 = rotate(d2, k)
    return 0


if __name__ == '__main__':
    ds = []
    n = int(input())

    for i in range(n):
        ds.append(list(map(int, input().split())))

    for i in range(n):
        for j in range(i + 1, n):
            if check(ds[i], ds[j]):
                print('No')
                exit(0)
    print('Yes')

Solution (Python):
import itertools

class Dice:
    N = [0, 1, 5, 4]
    S = N[::-1]
    E = [0, 3, 5, 2]
    W = E[::-1]
    R = [1, 2, 4, 3]
    L = R[::-1]

    def __init__(self, numbers):
        self.numbers = numbers

    def __eq__(self, other):
        if isinstance(other, Dice):
            newdice = Dice(other.numbers.copy())
            for x in range(6):
                if 1 <= x <= 3:
                    newdice.toX('N')
                elif x == 4:
                    newdice.toX('N')
                    newdice.toX('E')
                elif x == 5:
                    [newdice.toX('E') for _ in range(2)]
                for _ in range(4):
                    if self.numbers == newdice.numbers:
                        return True
                    newdice.toX('R')

            else:
                return False

        else:
            return False

    def __ne__(self, other):
        return not self.__eq__(other)

    def toX(self, x):
        data = getattr(self, x)
        self.numbers.append(0)
        for k in range(5):
            i1 = data[k - 1] if k != 0 else 6
            i2 = data[k] if k != 4 else 6
            self.numbers[i1] = self.numbers[i2]
        del self.numbers[6]

    def setTopandFront(self, top, front):
        while self.numbers[0] != top:
            if self.numbers.index(top) in self.N:
                self.toX('N')
            else:
                self.toX('E')
        while self.numbers[1] != front:
            self.toX('R')


n = int(input())
dices = [Dice([int(i) for i in input().split()]) for _ in range(n)]
if all(dices[i1] != dices[i2] for i1, i2 in itertools.combinations(range(n), 2)):
    print('Yes')
else:
    print('No')

Solution (Python):
houkou={'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3)}
moji="SSSSEEEENEEEENEEEENEEEENWSSSSWSSSSWSSSSWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWN:"
answer=0

n=int(input())
S=[0]*n
for i in range(n):
  S[i]=list(map(int,input().split()))
  
for i in range(n):
  for j in range(i+1,n):
    for k in range(len(moji)):
      if moji[k]==":":
        answer+=0
        break
      if S[j]==S[i]:
        answer+=1
        break
      S[j]=[S[j][l]for l in houkou[moji[k]]]
if answer==0:
    print("Yes")
else:
    print("No")

Solution (Python):
class Dice():
    def __init__(self,rot,Face):
        self.rot= rot
        self.Face = Face
    def Rotate(rot,Face):
        r=len(rot)
        intFace=[int(Face[i]) for i in range(6)]

        for i in range(r):
            Temp=[intFace[i] for i in range(6)]

            if rot[i]== "E":
                intFace[0]=Temp[3]
                intFace[1]=Temp[1]
                intFace[2]=Temp[0]
                intFace[3]=Temp[5]
                intFace[4]=Temp[4]
                intFace[5]=Temp[2]

            elif rot[i]== "W":
                intFace[0]=Temp[2]
                intFace[1]=Temp[1]
                intFace[2]=Temp[5]
                intFace[3]=Temp[0]
                intFace[4]=Temp[4]
                intFace[5]=Temp[3]

            elif rot[i]== "N":
                intFace[0]=Temp[1]
                intFace[1]=Temp[5]
                intFace[2]=Temp[2]
                intFace[3]=Temp[3]
                intFace[4]=Temp[0]
                intFace[5]=Temp[4]

            elif rot[i]== "S":
                intFace[0]=Temp[4]
                intFace[1]=Temp[0]
                intFace[2]=Temp[2]
                intFace[3]=Temp[3]
                intFace[4]=Temp[5]
                intFace[5]=Temp[1]

        return intFace

n=int(input())
Face=[[] for i in range(n)]
i=0
while i<n:
    Face[i] = input().split()
    i+=1




D1=["","N","W","E","S","NN"]
D2= ["","NWS","NWSNWS","NWSNWSNWS",]
same=False
for l in range(n):
    for m in range(n):
        if m==l:
            pass
        else:
            for k in range(6):
                for i in range(4):
                    rot = D1[k]+D2[i]
                    tempFace= Dice.Rotate(rot,Face[l])
                    j=0
                    while j<6:
                        if tempFace[j]!=int(Face[m][j]):
                            break
                        else:
                            if j==5:
                                same=True
                            j+=1

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

Solution (Python):
def roll(l, command):
    '''
    return rolled list

    l : string list
    command: string
    '''
    res = []
    i = -1
    if command =='N':
        res = [l[i+2], l[i+6], l[i+3], l[i+4], l[i+1], l[i+5]]
    if command =='S':
        res = [l[i+5], l[i+1], l[i+3], l[i+4], l[i+6], l[i+2]]
    if command =='E':
        res = [l[i+4], l[i+2], l[i+1], l[i+6], l[i+5], l[i+3]]
    if command =='W':
        res = [l[i+3], l[i+2], l[i+6], l[i+1], l[i+5], l[i+4]]

    return res

def spin(l):
    '''
    return right sppined list

    l : string list
    '''

    i = -1
    res = [l[i+1], l[i+3], l[i+5], l[i+2], l[i+4], l[i+6]]

    return res
def has_same_faces(a, b):
    '''
    check if all elements of a are equel to those of b.
    a : string list
    b : string list
    '''
    return set(a) == set(b)

def is_identical_lists(a, b):
    for x, y in zip(a, b):
        if x != y:
            return False

    return True

def check_two_dice(a, b):
    if not has_same_faces(a, b):
        return False
    
    orig_a = a[:]

    
    for i in range(6):
        if 1 <= i <= 3:
            a = roll(a, "N")
        elif i == 4:
            pass
            a = orig_a[:]
            a = roll(a, "W")
        elif i == 5:
            a = orig_a[:]
            a = roll(a, "E")

        
        for _ in range(4): 
            a = spin(a)
            if is_identical_lists(a, b):
                return True
        
    return False

def check_all_different(dice):
    '''
    if all dice are different, return True

    dice : string list

    '''
    for i in range(len(dice)):
        if i == 0:
            continue
        for j in range(i):
            res = check_two_dice(dice[i], dice[j])

            if res:
                return False
    
    return True


if __name__ == "__main__":
    res = False
    n = int(input())
    dice = []
    for _ in range(n): 
        dice.append(input().split())

    res = check_all_different(dice)

    print("Yes") if res else print("No")

Solution (Python):
import itertools



class Dice:
    def __init__(self):
        self.number = [i for i in range(6)]
        self.command_allpattern = "NNNNENNNNENNNNENNNNNENNNNEENNNNWWWSE"

    def set_number(self, d0, d1, d2, d3, d4, d5):
        self.number[0] = d0
        self.number[1] = d1
        self.number[2] = d2
        self.number[3] = d3
        self.number[4] = d4
        self.number[5] = d5

    def roll(self, command):
        if   command == "E":
            self.set_number(self.number[3],self.number[1],self.number[0],self.number[5],self.number[4],self.number[2])
        elif command == "N":
            self.set_number(self.number[1],self.number[5],self.number[2],self.number[3],self.number[0],self.number[4])
        elif command == "S":
            self.set_number(self.number[4],self.number[0],self.number[2],self.number[3],self.number[5],self.number[1])
        elif command == "W":
            self.set_number(self.number[2],self.number[1],self.number[5],self.number[0],self.number[4],self.number[3])
        else:
            raise

    def get_top(self):
        return self.number[0]

    def get_d2(self, d0, d1):
        flag_correct = False
        
        for command in self.command_allpattern:
            self.roll(command)

            if ((d0 == self.number[0]) and
                (d1 == self.number[1])):
                d2 = self.number[2]
                flag_correct = True

        if flag_correct:
            return d2
        else:
            raise

    def is_equal_dice_number(self, Dice):
        if set(Dice.number) == set(self.number):
            return True
        else:
            return False

    def equal_dice(self, Dice):

        if not self.is_equal_dice_number(Dice):
            return("No")

        flag_correct = False

        for command in self.command_allpattern:
            Dice.roll(command)

            if ((Dice.number[0] == self.number[0]) and
                (Dice.number[1] == self.number[1]) and
                (Dice.number[2] == self.number[2]) and
                (Dice.number[3] == self.number[3]) and
                (Dice.number[4] == self.number[4]) and
                (Dice.number[5] == self.number[5])):
                flag_correct = True

        if flag_correct:
            return("Yes")
        else:
            return("No")



n = int(input())

list_dice_class = []

for _ in range(n):
    list_face = list(map(int, input().split()))

    dice = Dice()
    dice.set_number(list_face[0], list_face[1], list_face[2], list_face[3], list_face[4], list_face[5])

    list_dice_class.append(dice)


flag_equal = False

for dice_a, dice_b in list(itertools.combinations(list_dice_class, 2)):
    if dice_a.equal_dice(dice_b) == "Yes":
        flag_equal = True
        break

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

Solution (Python):

import sys

class Dice :
    def __init__(self, dice) :
        self.dice = dice
    def roll(self, direction):
        tmp = self.dice[:]
        if direction == "N":
            self.dice[0] = tmp[1]
            self.dice[1] = tmp[5]
            self.dice[4] = tmp[0]
            self.dice[5] = tmp[4]
        elif direction == "E":
            self.dice[0] = tmp[3]
            self.dice[2] = tmp[0]
            self.dice[3] = tmp[5]
            self.dice[5] = tmp[2]
        elif direction == "W":
            self.dice[0] = tmp[2]
            self.dice[2] = tmp[5]
            self.dice[3] = tmp[0]
            self.dice[5] = tmp[3]
        else:
            self.dice[0] = tmp[4]
            self.dice[1] = tmp[0]
            self.dice[4] = tmp[5]
            self.dice[5] = tmp[1]

    def check_dice(self, another):
        for dire in "NNNNWNNNWNNNENNNENNNWNNN":
            self.roll(dire)
            check = True
            for i in range(6):
                if self.dice != another.dice:
                    check = False
                    break
            if check == True:
                break
        return check
    def get_dice_nums(self):
        return(self.dice)
    
    def check_dice_some(self, another):
        for dire in "NNNNWNNNWNNNENNNENNNWNNN":
            self.roll(dire)
            check = True
            for i in range(6):
                if self.dice != another.dice:
                    check = False
                    break
            if check == True:
                break
        return check
    def get_dice_nums(self):
        return(self.dice)
    
    def dice_top(self):
        print(self.dice[0])
    
dice_list = []
for i in range(int(input())):
    dice_list.append(Dice(list(map(str, input().split()))))
    
for i in range(len(dice_list)-1):
    judge = dice_list[0].check_dice(dice_list[i+1])
    if judge == True:
        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.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 query(self, another_dice):

        self.save_data = [i for i in range(6)]
        
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        is_same_face = False
        for i in range(len(self.order)):
            self.roll(self.order[i])
            if [f == s for f, s in zip(self.number, another_dice)].count(False) == 0:
                is_same_face = True
                break

        
        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]
        return is_same_face


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

for i in range(query_num):
    for q in range(query_num):
        if i == q:
            continue
        first_dice = dices[i]
        second_dice = dices[q]
        if first_dice.query(second_dice.number) == True:
            print("No")
            sys.exit()
print("Yes")

Solution (Python):
class Dice():
	def __init__(self):
		self.number = [int(i) for i in range(1,7)]
	
	def set_number(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,s):
		tmp = self.number
		if s == "S":
			self.set_number(tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1])
		elif s == "E":
			self.set_number(tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2])
		elif s == "N":
			self.set_number(tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4])
		elif s == "W":
			self.set_number(tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3])

	def get_number(self,i):
		
		return self.number[i]

	def get_position(self,i):
		return self.number.index(i)
	
	def get_dice(self):
		return [self.number[0],self.number[1],self.number[2],self.number[3],self.number[4],self.number[5]]

def check_dice(diceA,diceB):
	dice_numA = diceA.get_dice()
	dice_numB = diceB.get_dice()
	dice_numA.sort()
	dice_numB.sort()
	if dice_numA == dice_numB:
		top = diceA.get_number(0)
		front = diceA.get_number(1)
		while diceB.get_number(1) != front:
			if diceB.get_position(front) == 2 or diceB.get_position(front) == 3:
				diceB.roll("E")
			else:
				diceB.roll("S")
		if diceB.get_number(4) != top:
			while diceB.get_number(0) != top:
				diceB.roll("E")
			if diceA.get_dice() == diceB.get_dice():
				return 0
	return 1

if __name__ == '__main__':
	num = int(input())
	dice_num = []
	for i in range(num):
		dice_num.append([int(s) for s in input().split()])

	dice = []
	for i in range(num):
		dice.append(Dice())
		dice[i].set_number(dice_num[i][0],dice_num[i][1],dice_num[i][2],dice_num[i][3],dice_num[i][4],dice_num[i][5])

	flag = 0

	for i in range(num):
		for k in range(i+1,num):
			if check_dice(dice[i],dice[k]) == 0:
				print("No")	
				exit()
	print("Yes")

Solution (Python):
class Dice:
    def __init__(self):
        self.number = [i for i in range(6)]
        self.tmp = [i for i in range(6)]
        self.set_cmd = '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 next(self,direction):
        for i in range(6):
            self.tmp[i] = self.number[i]

        if direction == 'E':
            self.setNumber(self.tmp[3], self.tmp[1], self.tmp[0], self.tmp[5], self.tmp[4], self.tmp[2])
        elif direction == 'N':
            self.setNumber(self.tmp[1], self.tmp[5], self.tmp[2], self.tmp[3], self.tmp[0], self.tmp[4])
        elif direction == 'S':
            self.setNumber(self.tmp[4], self.tmp[0], self.tmp[2], self.tmp[3], self.tmp[5], self.tmp[1])
        elif direction == 'W':
            self.setNumber(self.tmp[2], self.tmp[1], self.tmp[5], self.tmp[0], self.tmp[4], self.tmp[3])
    def get_result(self):
        return self.number[0]

    def cheak(self,altanative):

        flag = True

        for i in range(len(self.set_cmd)):
            self.next(self.set_cmd[i])
            flag = True
            for j in range(6):
                if self.number[j] != altanative.number[j]:
                    flag = False
                    break
            else:
                if flag == True:
                    return flag

        return flag

dice1 = Dice()
Dice_arr = []
n = int(input())

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

judge = False

for i in range(n-1):
    for j in range(i+1,n):
        if Dice_arr[i].cheak(Dice_arr[j]) == True:
            judge = True
            break

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

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

    def roll(self, axis, count=1):
        while count < 0:
            count += 4
        if axis == "X":
            for _ in range(count):
                self.top, self.back, self.bottom, self.front = self.front, self.top, self.back, self.bottom
        elif axis == "Y":
            for _ in range(count):
                self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        elif axis == "Z":
            for _ in range(count):
                self.front, self.left, self.back, self.right = self.right, self.front, self.left, self.back
        elif axis == "N":
            self.roll("X", 1)
        elif axis == "W":
            self.roll("Y", -1)
        elif axis == "S":
            self.roll("X", -1)
        elif axis == "E":
            self.roll("Y", 1)


def is_identical(d1, d2):
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return True
        d2.roll("Z")
    d2.roll("X")
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return True
        d2.roll("Y")
    d2.roll("X")
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return True
        d2.roll("Z")
    d2.roll("X")
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return True
        d2.roll("Y")
    d2.roll("X")
    d2.roll("Y")
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return True
        d2.roll("X")
    d2.roll("Y", 2)
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return True
        d2.roll("X")
    return False


from itertools import combinations
N = int(input())
D = [Dice([int(c) for c in input().split()]) for _ in range(N)]
for d1, d2 in combinations(D, 2):
    if is_identical(d1, d2):
        print("No")
        exit(0)
print("Yes")

Solution (Python):
def move(dice, order):
  if order == "E":
    temp = dice[0]
    dice[0] = dice[3]
    dice[3] = dice[5]
    dice[5] = dice[2]
    dice[2] = temp
  elif order == "N":
    temp = dice[0]
    dice[0] = dice[1]
    dice[1] = dice[5]
    dice[5] = dice[4]
    dice[4] = temp
  elif order == "S":
    temp = dice[0]
    dice[0] = dice[4]
    dice[4] = dice[5]
    dice[5] = dice[1]
    dice[1] = temp
  elif order == "W":
    temp = dice[0]
    dice[0] = dice[2]
    dice[2] = dice[5]
    dice[5] = dice[3]
    dice[3] = temp
  else:
    pass
  return dice

def roll(dice):
  temp = dice[1]
  dice[1] = dice[2]
  dice[2] = dice[4]
  dice[4] = dice[3]
  dice[3] = temp
  return dice

def judge(dice1, dice2):
  flag = True
  for i in range(6):
    if dice1[i] != dice2[i]:
      flag = False
      break
  return flag

def aresame(dice1, dice2):
  mvdice = dice2
  cnt = 0
  
  while True:
    mvdice = move(mvdice, "E")
    cnt += 1
    if dice1[0] == mvdice[0]:
      rolldice = mvdice
      cntroll = 0
      while True:
        rolldice = roll(rolldice)
        cntroll += 1
        if judge(dice1, rolldice) == True:
          return True
        if cntroll == 4:
          break
    if cnt == 4:
      break

  mvdice = dice2
  cnt = 0
    
  while True:
    mvdice = move(mvdice, "N")
    cnt += 1
    if dice1[0] == mvdice[0]:
      rolldice = mvdice
      cntroll = 0
      while True:
        rolldice = roll(rolldice)
        cntroll += 1
        if judge(dice1, rolldice) == True:
          return True
        if cntroll == 4:
          break
    if cnt == 4:
      break

  return False


import sys

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

for i in range(n):
  for j in range(i+1, n):
    if aresame(saikoro[i], saikoro[j]) == True:
      print("No")
      sys.exit()
      
print("Yes")

Solution (Python):
class Dice():
  def __init__ (self):
    
    self.position = [0,0,0,0,0,0]
    self.search_result = []
  
  def setNumber (self, num):
    for i,x in enumerate(num):
      self.position[i] = x
    
      
  def roll(self, roll):
    for i in range(len(roll)):
      s = roll[i:i+1]
      p = self.position
      if s == 'E':
        self.setNumber([p[3], p[1], p[0], p[5], p[4], p[2]])
      elif s == 'W':
        self.setNumber([p[2], p[1], p[5], p[0], p[4], p[3]])
      elif s == 'S':
        self.setNumber([p[4], p[0], p[2], p[3], p[5], p[1]])
      elif s == 'N':
        self.setNumber([p[1], p[5], p[2], p[3], p[0], p[4]])
      elif s == 'R':
        self.setNumber([p[0], p[2], p[4], p[1], p[3], p[5]])

  def printTop(self):
    print(self.position[0])

  def searchRight(self, a, b):
    i1 = self.position.index(a)
    i2 = self.position.index(b)
    
    
    
    if (i1 == 1 and i2 == 2) or (i1 == 2 and i2 == 4) or (i1 == 4 and i2 == 3) or (i1 == 3 and i2 == 1):
      self.search_result.append(self.position[0])
    
    elif (i1 == 0 and i2 == 3) or (i1 == 3 and i2 == 5) or (i1 == 5 and i2 == 2) or (i1 == 2 and i2 == 0):
      self.search_result.append(self.position[1])
    
    elif (i1 == 0 and i2 == 1) or (i1 == 1 and i2 == 5) or (i1 == 5 and i2 == 4) or (i1 == 4 and i2 == 0):
      self.search_result.append(self.position[2])
    
    elif (i1 == 1 and i2 == 0) or (i1 == 0 and i2 == 4) or (i1 == 4 and i2 == 5) or (i1 == 5 and i2 == 1):
      self.search_result.append(self.position[3])
    
    elif (i1 == 0 and i2 == 2) or (i1 == 2 and i2 == 5) or (i1 == 5 and i2 == 3) or (i1 == 3 and i2 == 0):
      self.search_result.append(self.position[4])
    
    elif (i1 == 2 and i2 == 1) or (i1 == 1 and i2 == 3) or (i1 == 3 and i2 == 4) or (i1 == 4 and i2 == 2):
      self.search_result.append(self.position[5])
    
  def printResult(self):
    for i in self.search_result:
      print (i)
  
  def isSame(self, d):
    for r in ["", "R", "R", "R", 
              "RE",  "R", "R", "R",
              "RE",  "R", "R", "R",
              "RE",  "R", "R", "R",
              "RS",  "R", "R", "R",
              "RNN", "R", "R", "R"]:
      self.roll(r)
      
      if self.position == d.position:
        return True
    return False

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

for i in range(n):
  n = list(int(x) for x in input().split())

  d = Dice()
  d.setNumber(n)

  dices.append(d)

result = True
for i in range(len(dices)):
  if result == False:
    break

  for j in range(i+1, len(dices)):
    
    if dices[i].isSame(dices[j]):
      result = False
      break

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

Solution (Python):
class Dice:
    def __init__(self,my_label):
        self.top,self.front,self.right,self.left,self.back,self.bottom = [int(x) for x in my_label]

    def Roll(self,i):
        if i == 0:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.right, self.front, self.bottom, self.top, self.back, self.left
        
        if i == 1:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.left, self.front, self.top, self.bottom, self.back, self.right
        
        if i == 2:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.back, self.top, self.right, self.left, self.bottom, self.front
            
        if i == 3:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.front, self.bottom, self.right, self.left, self.top, self.back

    def Open(self):
        print(self.top)

def CheckData(data,top,front):
    for i in range(len(data)):
        if(data[i][0] == top and data[i][1] == front):
            print(data[i][2])
            break
            
def CheckDice(n,data):
    
    
    isEqual = False
    
    for i in range(n):
        for j in range(i+1,n):
            if(data[i] == data[j]):
                isEqual = True
                break
    
    if(isEqual == True):
        print("No")
    else:
        print("Yes")
                
def MakeData(dice):
    num_data = 4 * 6 -1
    
    dataset = list()
    data = [dice.top, dice.front, dice.right]

    dataset.append(data)
    
    isOnly = True
    
    n = 0
    while 0 < num_data:
        n += 1
        if (n > 1000):
            break
            
        data = [dice.top, dice.front, dice.right]

        isOnly = True
        for i in range (len(dataset)):
            if(data == dataset[i]):
                isOnly = False
                break
        if isOnly == True:
            dataset.append(data)
            dataset.sort()
            num_data -= 1
        
        dice.Roll(int(random.random() * 4))
        
    
        
    return dataset

import random

n = int(input())

my_label = [0] * n
dice = [0] * n
data = [0] * n

for i in range(n):
    my_label = [int(x) for x in input().split(" ")]
    
    dice = Dice(my_label)
    data[i] = MakeData(dice)

CheckDice(n,data)

Solution (Python):
import random

class dice:
    def __init__(self, t, S, E):
        self.dice = list(map(int, input().split()))
        self.t = t
        self.S = S
        self.E = E
        self.now_dice()
    
    def roll(self, order):
        if order == 'E':
            self.t, self.E = self.W, self.t
        elif order == 'N':
            self.t, self.S = self.S, self.g
        elif order == 'S':
            self.t, self.S = self.N, self.t
        elif order == 'W':
            self.t, self.E = self.E, self.g
        self.now_dice()
    
    def now_dice(self):
        self.N = 7 - self.S
        self.g = 7 - self.t
        self.W = 7 - self.E
        self.now = [self.t, self.S, self.E, self.N, self.W, self.g]
        return self.now

if __name__ == '__main__':
    num = int(input())
    dice_1 = dice(1, 2, 3)
    direc = ['N', 'E', 'W', 'S']
    x = 0
    for _ in range(num-1):
        dice_2 = dice(1, 2, 3)
        for __ in range(1200):
            random.shuffle(direc)
            dice_2.roll(direc[0])
            if [dice_1.dice[dice_1.now[v]-1] for v in range(6)] == [dice_2.dice[dice_2.now[v]-1] for v in range(6)]:
                x += 1
                break
    if x >= 1:
        print('No')
    else:
        print('Yes')