Problem:
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I , and determines whether they are all different. For the determination, use the same way as Dice III . Input In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III . Output Print " Yes " if given dices are all different, otherwise " No " in a line. Constraints  $2 \leq n \leq 100$  $0 \leq $ the integer assigned to a face $ \leq 100$  Sample Input 1 3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1 Sample Output 1 No Sample Input 2 3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6 Sample Output 2 Yes

Solution (Python):
class Dice:
    def __init__(self,numbers):
        self.surface=numbers

    def inspection(self,other):
        string=''
        a=self.surface[0]
        b=self.surface[1]
        c=self.surface[2]
        d=self.surface[3]
        e=self.surface[4]
        f=self.surface[5]
        match1=a+b+c+d+e+f
        match2=b+f+c+d+a+e
        match3=c+b+f+a+e+d
        match4=d+b+a+f+e+c
        match5=e+a+c+d+f+b
        match6=f+e+c+d+b+a
        match7=f+b+d+c+e+a
        match8=a+d+b+e+c+f
        match9=d+f+b+e+a+c
        match10=b+d+f+a+c+e
        match11=e+d+a+f+c+b
        match12=c+a+b+e+f+d
        match13=f+c+b+e+d+a
        match14=f+d+e+b+c+a
        match15=a+e+d+c+b+f
        match16=e+f+d+c+a+b
        match17=d+e+f+a+b+c
        match18=c+e+a+f+b+d
        match19=b+a+d+c+f+e
        match20=a+c+e+b+d+f
        match21=c+f+e+b+a+d
        match22=e+c+f+a+d+b
        match23=b+c+a+f+d+e
        match24=d+a+e+b+f+c
        for i in other.surface:
            string+=i
        if string==match1 or string==match2 or string==match3 or string==match4 or string==match5 or string==match6 or string==match7 or string==match8 or string==match9 or string==match10 or string==match11 or string==match12 or string==match13 or string==match14 or string==match15 or string==match16 or string==match17 or string==match18 or string==match19 or string==match20 or string==match21 or string==match22 or string==match23 or string==match24:
            return 'match'
        return 'not_match'

n=int(input())
lst=[]
for i in range(n):
    dice=Dice(input().split())
    if i==0:
        example_dice=Dice(dice.surface)
    else:
        lst.append(dice.surface)
for inspection_target in lst:
    inspection_target_dice=Dice(inspection_target)
    result=example_dice.inspection(inspection_target_dice)
    if result=='match':
        print("No")
        break
if result=='not_match':
    print("Yes")

Solution (Python):
n = int(input())
face = []
for i in range(n):
	face.append(list(map(int,input().split())))
def Nroll(list):
	a = [list[1],list[5],list[2],list[3],list[0],list[4]]
	return a
def Wroll(list):
	a = [list[2],list[1],list[5],list[0],list[4],list[3]]
	return a
ans = "Yes"
for ss in range(n):
	fac = face[ss]
	for ii in range(2):
		fac = Wroll(fac)
		for k in range(4):
			fac = Nroll(fac)
			for kk in range(4):
				fac = Wroll(fac)
				if fac in face[ss+1:]:
					ans = "No"
					break
			else:
				continue
			break
		else:
			continue
		break
print(ans)

Solution (Python):
import random
T = int(input())
A = [list(map(int,input().split())) for _ in range(T)]
C = ["E","W","S","N"]
for j in range(T-1):
    for k in range(j+1,T):
        N = A[k]
        for _ in range(100):
            i = random.choice(C)
            if i == "E":
                N[0],N[2],N[3],N[5] = N[3],N[0],N[5],N[2]
            elif i == "W":
                N[3],N[0],N[5],N[2] = N[0],N[2],N[3],N[5]
            elif i == "S":
                N[0],N[1],N[4],N[5] = N[4],N[0],N[5],N[1]
            else:
                N[4],N[0],N[5],N[1] = N[0],N[1],N[4],N[5]
    
            if A[j] == N:
                print("No")
                exit()
print("Yes")

Solution (Python):
def N(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[1]
  t1[1]=d1[5]
  t1[2]=d1[2]
  t1[3]=d1[3]
  t1[4]=d1[0]
  t1[5]=d1[4]
  return t1
def S(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[4]
  t1[1]=d1[0]
  t1[2]=d1[2]
  t1[3]=d1[3]
  t1[4]=d1[5]
  t1[5]=d1[1]
  return t1
def E(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[3]
  t1[1]=d1[1]
  t1[2]=d1[0]
  t1[3]=d1[5]
  t1[4]=d1[4]
  t1[5]=d1[2]
  return t1
def W(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[2]
  t1[1]=d1[1]
  t1[2]=d1[5]
  t1[3]=d1[0]
  t1[4]=d1[4]
  t1[5]=d1[3]
  return t1

n=int(input())
d=[[0 for i in range(6)] for j in range(n)]
for i in range(n):
  d[i][:]=(int(x) for x in input().split())
  dup=[x for x in set(d[i]) if d[i].count(x)==1]
  if dup:
    if dup[0]==d[i][0]:
      d[i]=E(d[i])
    elif dup[0]==d[i][1]:
      d[i]=N(d[i])
      d[i]=E(d[i])
    elif dup[0]==d[i][3]:
      d[i]=E(d[i])
      d[i]=E(d[i])
    elif dup[0]==d[i][4]:
      d[i]=S(d[i])
      d[i]=E(d[i])
    elif dup[0]==d[i][5]:
      d[i]=W(d[i])

for i in range(1,n):
  for j in range(i-1,-1,-1):
    if d[i][2]==d[j][0]:
      d[j]=E(d[j])
    elif d[i][2]==d[j][1]:
      d[j]=N(d[j])
      d[j]=E(d[j])
    elif d[i][2]==d[j][3]:
      d[j]=E(d[j])
      d[j]=E(d[j])
    elif d[i][2]==d[j][4]:
      d[j]=S(d[j])
      d[j]=E(d[j])
    elif d[i][2]==d[j][5]:
      d[j]=W(d[j])
    elif d[i][2]!=d[j][2]:
      continue

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

    for k in range(3):
      d[j]=N(d[j])
      if d[i]==d[j]:
        print("No")
        exit()

print("Yes")

Solution (Python):

import random
class Dice:
    def __init__(self, numbers):
        self.dice=[i for i in numbers]
        self.workspace=[i for i in numbers]
        
        self.top=self.dice[0]
        
        
    def rotate(self,command):
        if command == "W":
            self.workspace=[self.dice[2], self.dice[1], self.dice[5], self.dice[0], self.dice[4], self.dice[3]]
            self.dice=self.workspace
        elif command == "E":
            self.workspace=[self.dice[3], self.dice[1], self.dice[0], self.dice[5], self.dice[4], self.dice[2]]
            self.dice = self.workspace
        
        if command == "S":
            self.workspace=[self.dice[4], self.dice[0], self.dice[2], self.dice[3], self.dice[5], self.dice[1]]
            self.dice=self.workspace
        elif command == "N":
            self.workspace=[self.dice[1], self.dice[5], self.dice[2], self.dice[3], self.dice[0], self.dice[4]]
            self.dice=self.workspace
            
    def get_top(self):
        self.top=self.dice[0]
        print(self.top)
        
    def predict(self, num):
        for i in range(num):
            top, front = map(int, input().split())
            while(True):
                if top == self.dice[0] and front == self.dice[1]:
                    break
                command_num=random.randint(1,4)
                if command_num == 1:
                    self.rotate("W")
                elif command_num == 2:
                    self.rotate("E")
                elif command_num == 3:
                    self.rotate("S")
                elif command_num == 4:
                    self.rotate("N")
            print(self.dice[2])
            
    def getter(self):
        return self.dice[0], self.dice[1], self.dice[2], self.dice[3], self.dice[4], self.dice[5]
    
    def predict_same(self, top, front, right, left, back, bottom):
        for n in range(300):
            if top ==self.dice[0] and front== self.dice[1] and right ==self.dice[2]:
                break
            command_num=random.randint(1,4)
            if command_num == 1:
                    self.rotate("W")
            elif command_num == 2:
                    self.rotate("E")
            elif command_num == 3:
                    self.rotate("S")
            elif command_num == 4:
                    self.rotate("N")
        
        if top ==self.dice[0] and front== self.dice[1] and right ==self.dice[2]:
            if self.dice[3] == left and self.dice[4] == back and self.dice[5] == bottom:
                return "Yes"
                
            else:
                return "No"
                
        else:
            return "No"
            
        
            
                
    









q=int(input())
list_dice=[]
judges=[]

for i in range(q):
    numbers=list(map(int, input().split()))
    dice=Dice(numbers)
    list_dice.append(dice)
i=0
while(True):
    if (i+1) == len(list_dice):
        break
    for n in range(i+1,len(list_dice)):
        top, front, right, left, back, bottom=list_dice[i].getter()
        judges.append(list_dice[n].predict_same(top, front, right, left, back, bottom)) 
    i+=1
    
if "Yes" in judges:
    print("No")
else:
    print("Yes")

Solution (Python):
import collections


class Dice():

    def __init__(self, labels):
        self.__pip = labels

    def roll_e(self): 
        self.__pip[0], self.__pip[3], self.__pip[5], self.__pip[2] = \
            self.__pip[3], self.__pip[5], self.__pip[2], self.__pip[0]

    def roll_n(self): 
        self.__pip[0], self.__pip[1], self.__pip[5], self.__pip[4] = \
            self.__pip[1], self.__pip[5], self.__pip[4], self.__pip[0]

    def roll_s(self): 
        self.__pip[0], self.__pip[4], self.__pip[5], self.__pip[1] = \
            self.__pip[4], self.__pip[5], self.__pip[1], self.__pip[0]

    def roll_w(self): 
        self.__pip[0], self.__pip[2], self.__pip[5], self.__pip[3] = \
            self.__pip[2], self.__pip[5], self.__pip[3], self.__pip[0]

    def roll_nn(self): 
        self.roll_n()
        self.roll_n()

    def turn_dice(self): 
        self.__pip[1], self.__pip[2], self.__pip[4], self.__pip[3] = \
            self.__pip[2], self.__pip[4], self.__pip[3], self.__pip[1]

    def roll_dice(self, c):
        if c != self.__pip[0]:
            if c == self.__pip[1]:
                self.roll_n()
            elif c == self.__pip[2]:
                self.roll_w()
            elif c == self.__pip[3]:
                self.roll_e()
            elif c == self.__pip[4]:
                self.roll_s()
            else:
                self.roll_nn()

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

    def get_front(self):
        return self.__pip[1]

    def get_right(self):
        return self.__pip[2]
        
    def get_left(self):
        return self.__pip[3]
        
    def get_behind(self):
        return self.__pip[4]
        
    def get_bottom(self):
        return self.__pip[5]

    def judge(self, dice_2):
        top = dice_2.get_top()
        self.roll_dice(top)
        for i in range(4):
            if dice_2.get_front() == self.__pip[1]:
                break
            if i == 3:
                return False
            self.turn_dice()
        if dice_2.get_right() != self.__pip[2] or \
            dice_2.get_left() != self.__pip[3] or \
            dice_2.get_behind() != self.__pip[4] or \
            dice_2.get_bottom() != self.__pip[5]:
            return False
        return True


def main():
    n = int(input())
    *lst, = [input().split() for i in range(n)]
    for i in range(n-1):
        for j in range(i+1, n):
            lst1 = lst[i]
            lst2 = lst[j]
            if len(set(lst1) ^ set(lst2)) != 0:
                break
            c = collections.Counter(lst2)
            dice1 = Dice(lst1)
            dice2 = Dice(lst2)
            dice2.roll_dice(c.most_common()[-1][0]) 
            if dice1.judge(dice2):
                print('No')
                return
    print('Yes')


if __name__ == "__main__":
    main()

Solution (Python):
import random as ran
n = int(input())
A = [[int(x) for x in input().split()] for l in range(n)]






oup = 0
oun = 0
ori = 0
ole = 0
ofr = 0
oba = 0

up = 0
un = 0
ri = 0
le = 0
fr = 0
ba = 0
tmp = 0
tmp2 = 0

count = 0
order = ["S","N","E","W"]

def diceorigin(num):
    global oup
    global oun
    global ori
    global ole
    global ofr
    global oba

    oup = A[num][0]
    oun = A[num][5]
    ori = A[num][2]
    ole = A[num][3]
    ofr = A[num][1]
    oba = A[num][4]

def dice(num):
    global up
    global un
    global ri
    global le
    global fr
    global ba
    global tmp2
    global tmp

    up = A[num][0]
    un = A[num][5]
    ri = A[num][2]
    le = A[num][3]
    fr = A[num][1]
    ba = A[num][4]
    tmp2 = 0
    tmp = 0

for x in range(0,len(A)):
    diceorigin(x)

    for y in range(x+1,len(A)):
        dice(y)


        for i in range(100)  :
            x = ran.choice(order)
            if (x == "S"):
                tmp = fr
                tmp2 = un
                fr = up
                up = ba
                un = tmp
                ba = tmp2

            elif (x == "N"):
                tmp = un
                tmp2 = up
                up = fr
                un = ba
                fr = tmp
                ba = tmp2

            elif (x == "E"):
                tmp = up
                tmp2 = un
                up = le
                un = ri
                ri = tmp
                le = tmp2

            elif (x == "W"):
                tmp = un
                tmp2 = up
                up = ri
                un = le
                ri = tmp
                le = tmp2

            if (up == oup and un == oun and ri == ori and le == ole and fr == ofr and ba == oba):
                print("No")
                exit()


            
print("Yes")

Solution (Python):

class Dice:
    def __init__(self, input_dice):
        self.flow = [input_dice[3], input_dice[1], input_dice[0], input_dice[5], input_dice[2], input_dice[4]]
        self.dice = [input_dice[3], input_dice[1], input_dice[0], input_dice[5], input_dice[2], input_dice[4]]
  
    def setNumber(self, n0, n1, n2, n3, n4, n5):
        self.dice[0] = n0
        self.dice[1] = n1
        self.dice[2] = n2
        self.dice[3] = n3
        self.dice[4] = n4
        self.dice[5] = n5
        return self.dice
    
    def roll(self, dir):
        if dir == 'S':
            self.setNumber(self.flow[0], self.flow[2], self.flow[5], self.flow[1], self.flow[4], self.flow[3])
            self.flow = self.dice
            return self.dice
        if dir == 'N':
            self.setNumber(self.flow[0], self.flow[3], self.flow[1], self.flow[5], self.flow[4], self.flow[2])
            self.flow = self.dice
            return self.dice
        if dir == 'W':
            self.setNumber(self.flow[2], self.flow[1], self.flow[4], self.flow[0], self.flow[3], self.flow[5])
            self.flow = self.dice
            return self.dice
        if dir == 'E':
            self.setNumber(self.flow[3], self.flow[1], self.flow[0], self.flow[4], self.flow[2], self.flow[5])
            self.flow = self.dice
            return self.dice

    def identify(self, dice_x):
        self.counter = 0
        for i in range(6):
            if self.dice[i] == dice_x[i]:               
               self.counter += 1 
        if self.counter == 6:
            return True
        else:
            return False

    def check_dif(self, dice_x):
        import sys
        dice_x = [dice_x[3], dice_x[1], dice_x[0], dice_x[5], dice_x[2], dice_x[4]]
        
        
        
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False: 
                continue
            else:
                print('No')
                sys.exit()
        
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False:
                continue
            else:
                print('No')
                sys.exit()
        
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False: 
                continue
            else:
                print('No')
                sys.exit()
        
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False:
                continue
            else:
                print('No')
                sys.exit()
        
        self.roll('E')
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False: 
                continue
            else:
                print('No')
                sys.exit()
        
        self.roll('N')
        self.roll('N')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False: 
                continue
            else:
                print('No')
                sys.exit()
        return True

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

for i in range(n):
    for j in range(i+1, n):
        d = Dice(dice[i])
        d.check_dif(dice[j])
print('Yes')

Solution (Python):
from itertools import combinations
class Dice:
    def __init__(self,dim=list(range(1,7))):
        self.dim = dim

    def roll(self,direction):
        if direction == "N":
            buff = self.dim[0]
            self.dim[0] = self.dim[1]
            self.dim[1] = self.dim[5]
            self.dim[5] = self.dim[4]
            self.dim[4] = buff

        if direction == "E":
            buff = self.dim[3]
            self.dim[3] = self.dim[5]
            self.dim[5] = self.dim[2]
            self.dim[2] = self.dim[0]
            self.dim[0] = buff

        if direction == "W":
            buff = self.dim[0]
            self.dim[0] = self.dim[2]
            self.dim[2] = self.dim[5]
            self.dim[5] = self.dim[3]
            self.dim[3] = buff

        if direction == "S":
            buff = self.dim[0]
            self.dim[0] = self.dim[4]
            self.dim[4] = self.dim[5]
            self.dim[5] = self.dim[1]
            self.dim[1] = buff

def dice_ident(lsts,comb):
    for i in comb:
        D1 = Dice(lsts[i[0]])
        D2 = Dice(lsts[i[1]])
        for op in 'EEENEEENEEESEEESEEENEEEN':
            if D1.dim == D2.dim:
                return print("No")
            D1.roll(op)
    return print("Yes")
            

number = int(input())
comb = list(combinations(range(number),2))
lsts = []
for i in range(number):
    lsts.append(list(map(int,input().split())))

dice_ident(lsts,comb)

Solution (Python):
class dice:
    def __init__(self, X):
        self.x = [0] * 6
        self.x[0] = X[0]
        self.x[1] = X[1]
        self.x[2] = X[2]
        self.x[3] = X[3]
        self.x[4] = X[4]
        self.x[5] = X[5]

    def roll(self, d):
        if d == 'S':
            self.x[0], self.x[1], self.x[4], self.x[5] = \
            self.x[4], self.x[0], self.x[5], self.x[1]
        elif d == 'E':
            self.x[0], self.x[2], self.x[3], self.x[5] = \
            self.x[3], self.x[0], self.x[5], self.x[2]
        elif d == 'W':
            self.x[0], self.x[2], self.x[3], self.x[5] = \
            self.x[2], self.x[5], self.x[0], self.x[3]
        elif d == 'N':
            self.x[0], self.x[1], self.x[4], self.x[5] = \
            self.x[1], self.x[5], self.x[0], self.x[4]

n = int(input())
X = list(map(int, input().split()))
dice_b = dice(X)
distances = list('NNNNWNNNWNNNENNNENNNWNNN')
b = False
for _ in range(n-1):
    X_t = list(map(int, input().split()))
    dice_t = dice(X_t)
    for d in distances:
        dice_t.roll(d)
        if dice_b.x[0] == dice_t.x[0] and dice_b.x[1] == dice_t.x[1] and dice_b.x[2] == dice_t.x[2] and \
            dice_b.x[3] == dice_t.x[3] and dice_b.x[4] == dice_t.x[4] and dice_b.x[5] == dice_t.x[5]:
            b = True
            break
if b == False:
    print('Yes')
elif b == True:
    print('No')

Solution (Python):
import random

class Dice():
    def __init__(self, numbers):
        self.numbers = numbers
        S = [1, 5, 2, 3, 0, 4]
        N = [4, 0, 2, 3, 5, 1]
        W = [3, 1, 0, 5, 4, 2]
        E = [2, 1, 5, 0, 4, 3]
        self.tumble = {0: S, 1: N, 2: W, 3: E}
        self.table = []
        
    def rol(self, command):
        prev = self.numbers.copy()
        for i, t in enumerate(self.tumble[command]):
            self.numbers[t] = prev[i]

    def equal(self, dice2):
        if len(self.table) == 0:
            for _ in range(1000):
                self.rol(random.randint(0, 3))
                numbers = self.numbers.copy()
                if numbers not in self.table:
                    self.table.append(numbers)
        if dice2.numbers in self.table:
            return True
        else:
            return False
            
n = int(input())

dices = []

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

frag = True
for i in range(n-1):
    for j in range(i+1, n):
        if dices[i].equal(dices[j]):
            frag = False
            break
if frag:
    print('Yes')
else:
    print('No')

Solution (Python):
























































































class Dice:
    def __init__(self, label: list):
        self.top, self.front, self.right, self.left, self.back, self.bottom = label

    def roll(self, direction: str):
        if direction == "N":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.front,
                self.bottom,
                self.right,
                self.left,
                self.top,
                self.back,
            )
        elif direction == "W":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.right,
                self.front,
                self.bottom,
                self.top,
                self.back,
                self.left,
            )
        elif direction == "S":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.back,
                self.top,
                self.right,
                self.left,
                self.bottom,
                self.front,
            )
        elif direction == "E":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.left,
                self.front,
                self.top,
                self.bottom,
                self.back,
                self.right,
            )

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

    def get_top_front(self):
        return f"{self.top} {self.front}"

    def print_right(self):
        print(self.right)

    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.back, self.bottom]

    def is_same_dice(self, dice: list):
        for i in "EEEN" * 2 + "EEES" * 2 + "EEEN" * 2:
            if self.get_label() == dice:
                return True
            self.roll(i)
        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.is_same_dice(label):
                break
        else:
            L.append(Dice(label))
            continue
        print("No")
        break
    else:
        print("Yes")

Solution (Python):
import sys


def rollDice(dice, direction):
    buf = [x for x in dice]
    if direction == "S":
        buf[0] = dice[4]
        buf[1] = dice[0]
        buf[4] = dice[5]
        buf[5] = dice[1]
    elif direction == "E":
        buf[0] = dice[3]
        buf[2] = dice[0]
        buf[3] = dice[5]
        buf[5] = dice[2]
    elif direction == "W":
        buf[0] = dice[2]
        buf[2] = dice[5]
        buf[3] = dice[0]
        buf[5] = dice[3]
    elif direction == "N":
        buf[0] = dice[1]
        buf[1] = dice[5]
        buf[4] = dice[0]
        buf[5] = dice[4]

    for i in range(6):
        dice[i] = buf[i]


def rollDiceSide(dice):
    buf = [x for x in dice]
    buf[1] = dice[2]
    buf[2] = dice[4]
    buf[3] = dice[1]
    buf[4] = dice[3]

    for i in range(6):
        dice[i] = buf[i]


def isSameRollSide(d1, d2):
    if d1 == d2:
        return True
    rollDiceSide(d2)
    return False


def isSameRoll(d1, d2):
    if d1 == d2:
        return True
    rollDice(d2, "S")
    for _ in range(4):
        if isSameRollSide(d1, d2):
            return True
    return False


def isSameDice(d1, d2):
    for _ in range(4):
        for _ in range(4):
            if isSameRoll(d1, d2):
                return True
        rollDice(d2, "W")
    return False


n = int(input())
dice = [list(map(int, input().split())) for i in range(n)]
ans = [False for x in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        if isSameDice(dice[i], dice[j]):
            ans[i] = True
            break
if True in ans:
    print("No")
else:
    print("Yes")

Solution (Python):
class dice:
    def __init__(self, f0, f1, f2, f3, f4, f5):
        self.dice_num = [f0, f1, f2, f3, f4, f5]

    def roll_dice(self, command):
        for i in command:
            if i == 'N':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[1]
                self.dice_num[1] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[4]
                self.dice_num[4] = tmp

            if i == 'S':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[4]
                self.dice_num[4] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[1]
                self.dice_num[1] = tmp

            if i == 'E':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[3]
                self.dice_num[3] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[2]
                self.dice_num[2] = tmp

            if i == 'W':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[2]
                self.dice_num[2] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[3]
                self.dice_num[3] = tmp

    def print_topface(self):
        print(self.dice_num[0])

    def turn_clockwise(self):
        tmp = self.dice_num[1]
        self.dice_num[1] = self.dice_num[2]
        self.dice_num[2] = self.dice_num[4]
        self.dice_num[4] = self.dice_num[3]
        self.dice_num[3] = tmp

    def check_same_dice(self, dice2):
        for i in range(4):
            self.roll_dice('W')
            for j in range(4):
                self.turn_clockwise()
                if self.dice_num == dice2.dice_num:
                    return True
        for i in range(4):
            self.roll_dice('N')
            for j in range(4):
                self.turn_clockwise()
                if self.dice_num == dice2.dice_num:
                    return True
        return False

    def check_all_same_dice(self, dice_list):
        for i in dice_list:
            if self.check_same_dice(i):
                return False
        return True


if __name__ == "__main__":
    dice_list = []
    k = int(input())
    for i in range(k):
        num_list = list(map(int, input().split()))
        dice_list.append(dice(*num_list))
    same_dice = dice_list[0].check_all_same_dice(dice_list[1:])
    if same_dice:
        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):



class Dice:
    def __init__(self,lst):
        self.face=lst
        self.order="NNNNWNNNWNNNENNNENNNWNNN"
    
    def roll(self,x):
        tmp=self.face
        if x=="E":
            self.face=[tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2]]
        if x=="W":
            self.face=[tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3]]
        if x=="N":
            self.face=[tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4]]
        if x=="S":
            self.face=[tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1]]
    
    def showDown(self):
        return self.face[0]
    
    def query(self,lst):
        tmp=self.face
        ans=-1
        for i in self.order:
            self.roll(i)
            if self.face[0]==lst[0] and self.face[1]==lst[1]:
                ans=self.face[2]
                break
        self.face=tmp
        return ans
    
    def isEqual(self,another):
        tmp=self.face
        ans=False
        for i in self.order:
            self.roll(i)
            flg=True
            for j in range(6):
                if self.face[j]!=another.face[j]:
                    flg=False
                    break
            if flg==True:
                return True
        return ans

num=int(input())
dices=[Dice(list(map(int,input().split()))) for i in range(num)]
flg=True
for i in range(num):
    for j in range(i+1,num):
        if dices[i].isEqual(dices[j])==True:
            flg=False
            break
if flg:
    print("Yes")
else:
    print("No")