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, f):
        assert(len(f) == 6)
        self.face = f
        self.N = [1, 5, 2, 3, 0, 4]
        self.S = [4, 0, 2, 3, 5, 1]
        self.E = [3, 1, 0, 5, 4, 2]
        self.W = [2, 1, 5, 0, 4, 3]
        self.R = [0, 2, 4, 1, 3, 5]

    def rotate(self, dir):
        rot = self.__getattribute__(dir)
        old = self.face
        new = [-1 for _ in range(6)]
        for i in range(6):
            new[i] = old[rot[i]]
        self.face = new

    def __eq__(self, E):
        D = self
        for _ in range(4):
            
            if D.face[0] == E.face[0]:
                for _ in range(4):
                    
                    if D.face == E.face:
                        return True
                    else:
                        D.rotate('R')
            D.rotate('N')
        for _ in range(4):
            
            if D.face[0] == E.face[0]:
                for _ in range(4):
                    
                    if D.face == E.face:
                        return True
                    else:
                        D.rotate('R')
            D.rotate('E')
        return False

n = int(input())
S = []
for _ in range(n):
    S.append(dice(list(map(int, input().split()))))
ans = True
for i in range(n):
    for j in range(i+1, n):
        ans &= S[i] != S[j]
print('Yes' if ans else 'No')

Solution (Python):
n = int(input())

diceA = [[0 for i in range(6)] for j in range(n)]

diceB = [[0 for i in range(6)] for j in range(n)]

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

diceC = [[1,2,3,5,4,2,3,5,6],[2,1,4,6,3,1,4,6,5],[3,1,2,6,5,1,2,6,4],[4,1,5,6,2,1,5,6,3],[5,1,3,6,4,1,3,6,2],[6,2,4,5,3,2,4,5,1]]

m = "judge"

for o in range(n-1):
  for l in range(1,n-o):
    for i in range(6):
      if diceB[o+l][0] == diceA[o][i]:
        for j in range(1,5):
          if diceB[o+l][1] == diceA[o][diceC[i][j]-1]:
            for k in range(1,4):
              if diceB[o+l][1+k] == diceA[o][diceC[i][j+k]-1]:
                m = "same"
              else:
                m = "diff"
                break
            if m == "same":
              if diceB[o+l][5] == diceA[o][diceC[i][8]-1]:
                m = "same"
                break
              else:
                m = "diff"
                break
      if m == "same":
        break
    if m == "same":
      break
  if m == "same":
    break

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

Solution (Python):
class Dice():

    def __init__(self, d):
        self.d = d
        self.north = [2, 6, 3, 4, 1, 5]
        self.south = [5, 1, 3, 4, 6, 2]
        self.east = [4, 2, 1, 6, 5, 3]
        self.west = [3, 2, 6, 1, 5, 4]
        self.label = [(self.d[0], self.d[1], self.d[2])]

    def roll(self, direction):
        if direction == 'S':
            self.d = [ self.d[self.south[i]-1] for i in range(6) ]
        elif direction == 'N':
            self.d = [ self.d[self.north[i]-1] for i in range(6) ]
        elif direction == 'E':
            self.d = [ self.d[self.east[i]-1] for i in range(6) ]
        elif direction == 'W':
            self.d = [ self.d[self.west[i]-1] for i in range(6) ]

    def rollAll(self):
        for i in range(4):
            for i in range(4):
                self.roll('E')
                self.label.append((self.d[0], self.d[1], self.d[2]))
            self.roll('S')
        self.roll('E')
        self.roll('S')
        for i in range(4):
            self.roll('E')
            self.label.append((self.d[0], self.d[1], self.d[2]))
        self.roll('S')
        self.roll('S')
        for i in range(4):
            self.roll('E')
            self.label.append((self.d[0], self.d[1], self.d[2]))

    def getLabel(self):
        return set(self.label)

    def getDice(self):
        return self.d



n = int(input())
ll = []
for i in range(n):
    d = [ int(s) for s in input().split() ]
    dice = Dice(d)
    dice.rollAll()
    l = dice.getLabel()
    if l not in ll:
        ll.append(l)

if len(ll) == n:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys


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

    def rotate_front(self):
        t, b, f, r = self.top, self.bottom, self.front, self.rear
        self.top = r
        self.bottom = f
        self.front = t
        self.rear = b

    def rotate_rear(self):
        t, b, f, r = self.top, self.bottom, self.front, self.rear
        self.top = f
        self.bottom = r
        self.front = b
        self.rear = t

    def rotate_right(self):
        t, b, r, l = self.top, self.bottom, self.right, self.left
        self.top = l
        self.bottom = r
        self.right = t
        self.left = b

    def rotate_left(self):
        t, b, r, l = self.top, self.bottom, self.right, self.left
        self.top = r
        self.bottom = l
        self.right = b
        self.left = t

    def get_tfr(self):
        return [self.top, self.front, self.right]

    def get_all(self):
        return (self.top, self.bottom, self.front, self.rear, self.right, self.left)

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n=int(input())
    fin=set()
    top, front, right, left, rear, bottom = map(int, input().split())
    fin.add((top, bottom, front, rear, right, left))
    for _ in range(n-1):
        top, front, right, left, rear, bottom = map(int, input().split())
        d = Dice(top, bottom, front, rear, right, left)
        states = set()
        states.add(d.get_all())
        for _ in range(3):
            d.rotate_right()
            states.add(d.get_all())
        d.rotate_front()
        d.rotate_front()
        states.add(d.get_all())
        for _ in range(3):
            d.rotate_right()
            states.add(d.get_all())

        d.rotate_front()
        states.add(d.get_all())
        for _ in range(3):
            d.rotate_right()
            states.add(d.get_all())
        d.rotate_front()
        d.rotate_front()
        states.add(d.get_all())
        for _ in range(3):
            d.rotate_right()
            states.add(d.get_all())

        d.rotate_right()
        d.rotate_front()
        states.add(d.get_all())
        for _ in range(3):
            d.rotate_right()
            states.add(d.get_all())
        d.rotate_front()
        d.rotate_front()
        states.add(d.get_all())
        for _ in range(3):
            d.rotate_right()
            states.add(d.get_all())

        for t in fin:
            if t in states:
                print("No")
                exit()
    print("Yes")

main()

Solution (Python):
class Dice():
    def __init__(self, arr):
        self.top = arr[0]
        self.front = arr[1]
        self.right = arr[2]
        self.left = arr[3]
        self.back = arr[4]
        self.bottom = arr[5]
        
    def rotate(self, direction):
        if direction == "N":
            self.back, self.top, self.front, self.bottom = \
            self.top, self.front, self.bottom, self.back
        elif direction == "S":
            self.front, self.bottom, self.back, self.top = \
            self.top, self.front, self.bottom, self.back
        elif direction == "E":
            self.right, self.bottom, self.left, self.top = \
            self.top, self.right, self.bottom, self.left
        elif direction == "W":
            self.left, self.bottom, self.right, self.top = \
            self.top, self.left, self.bottom, self.right
        elif direction == "R": 
            self.front, self.right, self.back, self.left =\
            self.right, self.back, self.left, self.front
            
    def get_faces(self):
        return [self.top, self.front, self.right, self.left,
               self.back, self.bottom]
    
n = int(input())
dice_list = []
for _ in range(n):
    dice_list.append(Dice(input().split()))
    
def is_same(dice1, dice2):
    flag = False
    
    if len(dice1.get_faces() and dice2.get_faces()) == 6:
        direction_list = ["", "S", "E", "S", "E", "S"]
        for direction in direction_list:
            dice2.rotate(direction)
            
            for i in range(4):
                if dice1.get_faces() == dice2.get_faces():
                    flag = True
                    break                  
                dice2.rotate("R")
                
            if flag:
                break
                
    return flag

flag = True

for i in range(n-1):
    for j in range(i+1, n):
        if is_same(dice_list[i], dice_list[j]):
            flag = False
            
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
n=int(input())
dice=[input().split() for i in range(n)]
def E(ls):
    ls=[ls[3],ls[1],ls[0],ls[5],ls[4],ls[2]]
    return ls

def N(ls):
    ls=[ls[1],ls[5],ls[2],ls[3],ls[0],ls[4]]
    return ls

def R(ls):
    ls=[ls[0],ls[2],ls[4],ls[1],ls[3],ls[5]]
    return ls
    
def same(d1,d2):
    d1_ls=[d1,]
    for i in range(3):
        d1=E(d1)
        d1_ls.append(d1)
    d1=E(d1)
    d1=N(d1)
    d1_ls.append(d1)
    d1=N(N(d1))
    d1_ls.append(d1)
    for i in range(6):
        d=d1_ls[i]
        for j in range(3):
            d=R(d)
            d1_ls.append(d)
    if d2 in d1_ls:
        return True
    else:
        return False
k=0
for i in range(n):
    for j in range(i+1,n):
        if same(dice[i],dice[j]):
            k+=1
            break 
    else:continue    
    break
if k==1:
    print('No')
else:
    print('Yes')

Solution (Python):
import sys
def rotate(arr,i):
    if i=='W':
        arr=[arr[k-1] for k in [3,2,6,1,5,4]]
    if i=='E':
        arr=[arr[k-1] for k in [4,2,1,6,5,3]]
    if i=='N':
        arr=[arr[k-1] for k in [2,6,3,4,1,5]]
    if i=='S':
        arr=[arr[k-1] for k in [5,1,3,4,6,2]]
    return arr
def isIdentical(arr,arr2):
    deck=[]
    for i in 'W'*4:
        arr=rotate(arr,i)
        for k in 'NNNN':
            arr=rotate(arr,k)
            deck.append(arr)
    arr=rotate(arr,'N')
    arr=rotate(arr,'W')
    for k in 'NNNN':
        arr=rotate(arr,k)
        deck.append(arr)
    arr=rotate(arr,'W')
    arr=rotate(arr,'W')
    for k in 'NNNN':
        arr=rotate(arr,k)
        deck.append(arr)
    if arr2 in deck:
        return True
    else:
        return False
n=int(input())
allarr=[]
for i in range(n):
    allarr.append(input().split())
for i1,v1 in enumerate(allarr):
    for v2 in allarr[i1+1:]:
        if isIdentical(v1,v2):
            print('No')
            sys.exit()
print('Yes')

Solution (Python):
class Dice:
    
    def __init__(self, U, S, E, W, N, D):
        self.u, self.d = U, D
        self.e, self.w = E, W
        self.s, self.n = S, N       
    
    def roll(self, command):
        if command == 'E':
            self.e, self.u, self.w, self.d = self.u, self.w, self.d, self.e
        elif command == 'W':
            self.e, self.u, self.w, self.d = self.d, self.e, self.u, self.w
        elif command == 'S':
            self.s, self.u, self.n, self.d = self.u, self.n, self.d, self.s
        else:
            self.s, self.u, self.n, self.d = self.d, self.s, self.u, self.n

    def rightside(self, upside, forward):
        self.structure = {self.u:{self.w: self.s, self.s: self.e, self.e: self.n, self.n: self.w},
                          self.d:{self.n: self.e, self.e: self.s, self.s: self.w, self.w: self.n},
                          self.e:{self.u: self.s, self.s: self.d, self.d: self.n, self.n: self.u},
                          self.s:{self.u: self.w, self.w: self.d, self.d: self.e, self.e: self.u},
                          self.w:{self.u: self.n, self.n: self.d, self.d: self.s, self.s: self.u},
                          self.n:{self.u: self.e, self.e: self.d, self.d: self.w, self.w: self.u}}
        
        print(self.structure[upside][forward])

    def __eq__(self, other):

        other_hex = [other.u, other.s, other.e, other.w, other.n, other.d]
        self_hex = [self.u, self.s, self.e, self.w, self.n, self.d]
        if sorted(other_hex) != sorted(self_hex):
            return False

        for i in 'NNNNENNNENNNWNNNWNNNENNN':
            self.roll(i)
            if other.u == self.u and other.s == self.s and other.e == self.e \
            and other.w == self.w and other.n == self.n and other.d == self.d:
                return True
            
        return False

                

num = int(input())
dices = []
for i in range(num):
    U, S, E, W, N, D = [int(i) for i in input().split()]
    dice = Dice(U, S, E, W, N, D)
    dices.append(dice)

for i in range(num):
    for j in range(i+1, num):
        if dices[i] == dices[j]:
            print('No')
            break
    else:
        continue
    break
else:
    print('Yes')

Solution (Python):
class Dice:
    def __init__(self, label):
        self.label = label.copy()
    
    def rotateS(self):
        """[1, 2, 6, 5] -> [5, 1, 2, 6]"""
        t = self.label[1]
        self.label[1] = self.label[5]
        self.label[5] = self.label[6]
        self.label[6] = self.label[2]
        self.label[2] = t

    def rotateN(self):
        t = self.label[1]
        self.label[1] = self.label[2]
        self.label[2] = self.label[6]
        self.label[6] = self.label[5]
        self.label[5] = t
    
    def rotateW(self):
        t = self.label[1]
        self.label[1] = self.label[3]
        self.label[3] = self.label[6]
        self.label[6] = self.label[4]
        self.label[4] = t
    
    def rotateE(self):
        t = self.label[1]
        self.label[1] = self.label[4]
        self.label[4] = self.label[6]
        self.label[6] = self.label[3]
        self.label[3] = t

    def rotateR(self):
        'SWN = R'
        t = self.label[3]
        self.label[3] = self.label[2]
        self.label[2] = self.label[4]
        self.label[4] = self.label[5]
        self.label[5] = t

    def rotateL(self):
        'SEN = L'
        t = self.label[3]
        self.label[3] = self.label[5]
        self.label[5] = self.label[4]
        self.label[4] = self.label[2]
        self.label[2] = t


def compare(dice1, dice2):
    if (dice1.label == dice2.label):
        return True
    else:
        return False

def verify(dice1, dice2):
    dice_t = Dice(dice2.label)
    numS = 0
    for i in range(0,4):
        numR = 0
        for _ in range(0,4):
            debugprint(dice1, dice_t)
            if (compare(dice1, dice_t)):
                return True
            dice_t.rotateR()
            numR += 1
        
        dice_t.rotateS()
        numS += 1
    

    dice_t.rotateE()
    for _ in range(0,4):
        debugprint(dice1, dice_t)
        if (compare(dice1, dice_t)):
            return True
        dice_t.rotateR()

    dice_t.rotateE()
    dice_t.rotateE()
    for _ in range(0,4):
        debugprint(dice1, dice_t)
        if (compare(dice1, dice_t)):
            return True
        dice_t.rotateR()

    return False

def debugprint(dice1, dice2, label=''):
    debug=False
    if (debug):
        print(label)
        print('dice1: {}'.format(dice1.label))
        print('dice2: {}'.format(dice2.label))
        print('')



ndice = int(input())
dices = []
for i in range(0,ndice):
    label = []
    label.append(-1)
    label[1:] = map(int,input().split())
    dice = Dice(label)
    dices.append(dice)

for i in range(0,ndice-1):
    for j in range(i+1, ndice):
        if (verify(dices[i], dices[j])):
            print('No')
            exit()
print('Yes')

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 random

class Dice:
    def __init__(self):
        self.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
    
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d
        self.dic={"W":0,"S":1,"E":2,"N":3}

    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[way]

        if way==0:
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way==1:
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way==2:
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c
        else :
            c=self.u
            self.u=self.s
            self.s=self.d
            self.d=self.n
            self.n=c
def dice_check(dice_1,dice_2):
    lst=["W","S"]
    flag=0
    for i in range(100):
        if dice_1.u==dice_2.u and dice_1.w==dice_2.w and dice_1.s==dice_2.s and dice_1.e==dice_2.e and dice_1.n==dice_2.n and dice_1.d==dice_2.d:
            flag=1
        dice_1.rot(random.choice(lst))
    return flag

flag2=0
dices = []
dice_number=int(input())
for i in range(dice_number):
    u,s,e,w,n,d=map(int,input().split())
    dice=Dice(u,w,s,e,n,d)
    dices.append(dice)
for i in range(dice_number):
    for j in range(i+1,dice_number):
        if dice_check(dices[i],dices[j])==1:
            flag2=1
if flag2==0:
    print("Yes")
else:
    print("No")

Solution (Python):
class Dice:
    def __init__(self, top, front, right, left, back, bottom):
        self.TOP = top
        self.BOTTOM = bottom
        self.FRONT = front
        self.BACK = back
        self.LEFT = left
        self.RIGHT = right
    
    def move(self, direction):
        if direction == "N":
            self.move_N()
        elif direction == "E":
            self.move_E()
        elif direction == "S":
            self.move_S()
        elif direction == "W":
            self.move_W()
        elif direction == "SIDE":
            self.move_SIDE()
        else:
            raise Exception
    
    def move_N(self):
        tmp = self.TOP
        self.TOP = self.FRONT
        self.FRONT = self.BOTTOM
        self.BOTTOM = self.BACK
        self.BACK = tmp

    def move_S(self):
        tmp = self.TOP
        self.TOP = self.BACK
        self.BACK = self.BOTTOM
        self.BOTTOM = self.FRONT
        self.FRONT = tmp
        
    def move_W(self):
        tmp = self.TOP
        self.TOP = self.RIGHT
        self.RIGHT = self.BOTTOM
        self.BOTTOM = self.LEFT
        self.LEFT = tmp

    def move_E(self):
        tmp = self.TOP
        self.TOP = self.LEFT
        self.LEFT = self.BOTTOM
        self.BOTTOM = self.RIGHT
        self.RIGHT = tmp
    
    def move_SIDE(self):
        tmp = self.FRONT
        self.FRONT = self.RIGHT
        self.RIGHT = self.BACK
        self.BACK = self.LEFT
        self.LEFT = tmp

def is_same(dice, dice2):
    for _ in range(4):
        dice.move("SIDE")
        for _ in range(4):
            dice.move("N")
            if dice.TOP == dice2.TOP and dice.FRONT == dice2.FRONT \
                and dice.RIGHT == dice2.RIGHT and dice.LEFT == dice2.LEFT \
                and dice.BACK == dice2.BACK and dice.BOTTOM == dice2.BOTTOM:
                return True
        for _ in range(4):
            dice.move("E")
            if dice.TOP == dice2.TOP and dice.FRONT == dice2.FRONT \
                and dice.RIGHT == dice2.RIGHT and dice.LEFT == dice2.LEFT \
                and dice.BACK == dice2.BACK and dice.BOTTOM == dice2.BOTTOM:
                return True
    return False
    
dices = []
n = int(input())
is_OK = True
for _ in range(n):
    top, front, right, left, back, bottom = map(int,input().split())
    new_dice = Dice(top, front, right, left, back, bottom)
    for d in dices:
        if is_same(new_dice, d):
            is_OK = False
            break
    if is_OK == False:
        break
    dices.append(new_dice)
    
if is_OK:
    print("Yes")
else:
    print("No")

Solution (Python):
class Dice():
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5
    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]
        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
    def equal(self,another):
      ret=False
      for loc in "NNNNWNNNWNNNENNNENNNWNNN":
        self.roll(loc)
        if self.number==another.number:
          ret=True
          break
      return ret         
dices=[]
n=int(input())
for _ in range(n):
  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(n-1):
  for j in range(i+1,n):
    if dices[i].equal(dices[j]):
      print("No")
      exit()
print("Yes")

Solution (Python):
class dice():
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
    
    def setnum(self,s):
        self.number = s

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

    def Qright(self,up,flont,num):
        uf = (up,flont)
        if uf == (num[1],num[2]) or uf ==(num[2],num[4]) or uf ==(num[4],num[3]) or uf ==(num[3],num[1]):
            ans = num[0]
        elif uf == (num[0],num[3]) or uf ==(num[3],num[5]) or uf ==(num[5],num[2]) or uf ==(num[2],num[0]):
            ans = num[1]
        elif uf == (num[0],num[1]) or uf ==(num[1],num[5]) or uf ==(num[5],num[4]) or uf ==(num[4],num[0]):
            ans = num[2]
        elif uf == (num[0],num[4]) or uf ==(num[4],num[5]) or uf ==(num[5],num[1]) or uf ==(num[1],num[0]):
            ans = num[3]
        elif uf == (num[0],num[2]) or uf ==(num[2],num[5]) or uf ==(num[5],num[3]) or uf ==(num[3],num[0]):
            ans = num[4]
        elif uf == (num[1],num[3]) or uf ==(num[3],num[4]) or uf ==(num[4],num[2]) or uf ==(num[2],num[1]):
            ans = num[5]
        print(ans)



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

testall = 'NNNNENNNNENNNNENNNNENWNNNNEENNNN'

flg=0
for i in range(n):
    dice1 = dice()
    dice1.setnum(num_list[i])

    temp_num=[]
    temp_num = num_list.copy()
    temp_num.remove(num_list[i])
    for j in range(n-1):
        cnt = 0
        for k in range(len(testall)):
            dice1.kai(testall[k])
            
            if dice1.number == temp_num[j]:
                flg = 1
                
                break
        if flg == 1:
            
            break
    if flg == 1:
        
        break
    del dice1
if flg==0:
    print('Yes')
else:
    print('No')

Solution (Python):
import random

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


class Dice():
    def __init__(self, dice, directions):
        self.dice = dice
        self.directions = directions

    def roll(self):
        for direction in self.directions:
            NS = [0, 1, 5, 4]
            WE = [0, 2, 5, 3]
            copy_dice = self.dice[:]

            if direction == 'N':
                for j in range(4):
                    self.dice[NS[j]] = copy_dice[NS[j-3]]
            elif direction == 'S':
                for j in range(4):
                    self.dice[NS[j]] = copy_dice[NS[j-1]]
            elif direction == 'W':
                for j in range(4):
                    self.dice[WE[j]] = copy_dice[WE[j-3]]
            else:
                for j in range(4):
                    self.dice[WE[j]] = copy_dice[WE[j-1]]

        return self.dice


def check_equal(dice_1, dice_2):
    for i in range(n+100):
        dice_A = Dice(dice_1, random.choice(['N', 'S', 'W', 'E']))

        if dice_A.roll() == dice_2:
            return True
            break

    else:
        return False

check_dice = True

for i in range(n):
    for j in range(i+1, n):
        if check_equal(dice_list[i], dice_list[j]) == True:
            check_dice = False
            break


if check_dice == True:
    print('Yes')
else:
    print('No')

Solution (Python):


dirc = ((0, 1, 2, 3, 4, 5), (4, 0, 2, 3, 5, 1), (3, 1, 0, 5, 4, 2),
(2, 1, 5, 0, 4, 3), (1, 5, 2, 3, 0, 4), (5, 4, 2, 3, 1, 0))
sideNum = (1, 2, 4, 3)

def judge(diceRef, diceNew):
    for i in diceNew:
        if diceRef.count(i) != diceNew.count(i):
            return False
    for i in range(6):
        diceTmp = [0 for k in range(6)]
        for j in range(6):
            diceTmp[dirc[i][j]] = diceRef[j]
        if diceNew[0] == diceTmp[0] and diceNew[5] == diceTmp[5]:
            sideNew = ''
            sideTmp = ''
            for j in sideNum:
                sideNew += str(diceNew[j])
                sideTmp += str(diceTmp[j])
            sideTmp += sideTmp
            if sideNew in sideTmp:
                return True
    return False

dice = list()
n = int(input())
dice.append(list(map(int, input().split())))
for i in range(1, n):
    dice.append(list(map(int, input().split())))
    for j in range(i):
        if judge(dice[j], dice[i]):
            print('No')
            exit()    
print('Yes')

Solution (Python):
class Dice:
    def __init__(self, default = [1, 2, 3, 4, 5, 6]):
        self.d = default

    def e(self):
        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[3], self.d[0], self.d[5], self.d[2]

    def w(self):
        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[2], self.d[5], self.d[0], self.d[3]

    def n(self):
        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[1], self.d[5], self.d[0], self.d[4]

    def s(self):
        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[4], self.d[0], self.d[5], self.d[1]

    def r(self):
        self.d[1], self.d[2], self.d[3], self.d[4] = self.d[3], self.d[1], self.d[4], self.d[2]

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

    def forward(self):
        return self.d[1]

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

    def bottom(self):
        return self.d[5]

    def forTop(self, num):  
        for i in range(4):
            if self.top() == num:
                break
            self.e()
        else:
            for j in range(3):
                if self.top() == num:
                    break
                self.s()
    def same(self, dice):
        if self.d == dice.d:
            return True

    def same_rotate(self, dice):
        saved_d = self.d[:]
        for i in range(4):
            for j in range(4):
                if self.same(dice):
                    self.d = saved_d
                    return True
                else:
                    self.e()
            self.s()
        for i in range(4):
            for j in range(4):
                if self.same(dice):
                    self.d = saved_d
                    return True
                else:
                    self.e()
            self.r()
        for i in range(4):
            for j in range(4):
                if self.same(dice):
                    self.d = saved_d
                    return True
                else:
                    self.s()
            self.r()
        self.d = saved_d
        return False



def main():
    n = int(input())
    data = [Dice(list(map(int, input().split()))) for _ in range(n)]

    for i in range(n - 1):
        for j in range(i + 1, n):
            if data[i].same_rotate(data[j]):
                print('No')
                return

    print('Yes')
    return





if __name__ == '__main__':
    main()

Solution (Python):
class Dice:
    
    def __init__(self,l):
        self.f=l
        
    def __str__(self):
        l=self.f
        s=f'[U:{l[0]},S:{l[1]},E:{l[2]},W:{l[3]},N:{l[4]},D:{l[5]}]'
        return(s)
       
    def roll(self,c):
        if c=='N':
            ni=[1,5,2,3,0,4]
        elif c=='S':
            ni=[4,0,2,3,5,1]
        elif c=='E':
            ni=[3,1,0,5,4,2]
        elif c=='W':
            ni=[2,1,5,0,4,3]
        self.f=[self.f[j] for j in ni]
    
    def rotate(self,r):
        if r==+1: 
            ni=[0,3,1,4,2,5]
        elif r==-1: 
            ni=[0,2,4,1,3,5]
        self.f=[self.f[j] for j in ni]

    def patterns(self):
        fs=[]
        for i in range(6):
            if i%2==0:
                self.roll('N')
            else:
                self.roll('E')
            for j in range(4):
                self.rotate(+1)
                fs.append(self.f)
        return fs
        
    def lookEast(self,l):
        for f in self.patterns():
            if f[0]==l[0] and f[1]==l[1]:
                return f[2]
    
    def equals(self,d):
        for f in self.patterns():
            if f==d.f:
                return True
        return False

n=int(input())
d0=Dice(list(map(int,input().split())))
flag = True 
for i in range(n-1):
    if d0.equals(Dice(list(map(int,input().split())))):flag=False;break
print('Yes' if flag else 'No')