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

Solution (Python):
import random
class Dice:
    def __init__(self,top,front,right,left,back,bottom):
        self.top, self.bottom=top,bottom
        self.right, self.left=right,left
        self.front, self.back=front,back
    def turn(self,order):
        if order=="N":
            self.top,self.front,self.bottom,self.back=self.front,self.bottom,self.back,self.top
        if order=="S":
            self.top,self.front,self.bottom,self.back=self.back,self.top,self.front,self.bottom
        if order=="E":
            self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom
        if order=="W":
            self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top
def same(a,b):
    if ((a.top,a.bottom,a.right,a.left,a.front,a.back)==(b.top,b.bottom,b.right,b.left,b.front,b.back)):
        return True
    else:
        return False
n=input()
dicelist=[]
dice=[]
for i in range(n):
    dicelist.append(map(int,raw_input().split()))
for i in range(n):
    dice.append(Dice(dicelist[i][0],dicelist[i][1],dicelist[i][2],dicelist[i][3],dicelist[i][4],dicelist[i][5]))
flg=0
for i in range(1,n):
    if flg==1:
        break
    for j in range(1000):
        if flg==1:
            break
        d="NSWE"[random.randint(0,3)]
        dice[i].turn(d)
        for k in range(i):
            if same(dice[k],dice[i]):
                print "No"
                flg=1
                break
if flg==0:
    print "Yes"

Solution (Python):
import copy


def move(lon, lat, news):
    target, other, pop_index, insert_index = lon, lat, 0, 3
    if news == "E" or news == "W":
        target, other = lat, lon
    if news == "S" or news == "W":
        pop_index, insert_index = 3, 0
    target.insert(insert_index, target.pop(pop_index))
    other[0], other[2] = target[0], target[2]


def set_upper(lon, lat, upper):
    news = "N" if upper in lon else "E"
    while lon[0] != upper:
        move(lon, lat, news)


def rotate(lon, lat, com):
    if com == "R":
        lon[1], lat[1], lon[3], lat[3] = lat[3], lon[1], lat[1], lon[3]
    elif com == "L":
        lon[1], lat[1], lon[3], lat[3] = lat[1], lon[3], lat[3], lon[1]


def compare(val1, val2):
    lon2, lat2 = copy.copy(longitude), copy.copy(latitude)
    for u in range(6):
        set_upper(lon2, lat2, u)
        for f in range(4):
            rotate(lon2, lat2, "R")
            if False not in map(lambda x1, x2: val1[x1] == val2[x2], longitude + latitude, lon2 + lat2):
                return True
    return False


longitude = [0, 1, 5, 4]
latitude = [0, 3, 5, 2]




















values = []
n = int(input())
for i in range(n):
    values.append(input().split())
value1, *tail = values
while tail:
    for value2 in tail:
        if compare(value1, value2):
            print("No")
            exit()
    head, *tail = tail
print("Yes")

Solution (Python):
import random

class dice:
    def __init__(self, nums=[0]*6):
        self.top = nums[0]
        self.front = nums[1]
        self.right = nums[2]
        self.left  = nums[3]
        self.back = nums[4]
        self.bottom = nums[5]
    
    def set_nums(self, nums):
        self.top = nums[0]
        self.front = nums[1]
        self.right = nums[2]
        self.left  = nums[3]
        self.back = nums[4]
        self.bottom = nums[5]
    
    def roll(self, dr):
        if dr==0:
            self.top, self.front, self.bottom, self.back = self.front, self.bottom, self.back, self.top
        elif dr==1:
            self.top, self.front, self.bottom, self.back = self.back, self.top, self.front, self.bottom
        elif dr==2:
            self.top, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.top
        elif dr==3:
            self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        
    def check_same(self, d2):
        if (self.top == d2.top and self.right == d2.right and self.bottom == d2.bottom and self.left == d2.left and self.front == d2.front and self.back == d2.back):
            return True
        else:
            return False
    
    def check(self, d2):
        trial = 0
        while trial<100:
            if self.check_same(d2):
                return True
            else:
                self.roll(random.randint(0,3))
                trial += 1
        return False

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

flg = 0
for i in range(n):
    if flg:
        break
    for j in range(i+1,n):
        if ds[i].check(ds[j]):
            flg = 1

if flg:
    print('No')
else:
    print('Yes')

Solution (Python):
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


class Dice():

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

    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


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

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def get_Top(self):
        return self.number[0]
        
    def query(self, top_num, front_num):
        self.save_data = [i for i in range(6)]
        for i in range(6):
            self.save_data[i] = self.number[i]
            
        ret = -1
        
        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break
            
        for i in range(6):
            self.number[i] = self.save_data[i]
            
        return ret
        
    def equals(self, another):
        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 False

n = int(input())
dice = []
for i in range(n):
    tmp_dice = Dice()
    table = list(map(int,input().split()))
    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(n-1):
    for j in range(i+1, n):
        if dice[i].equals(dice[j]):
            FLG = False
            break

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

Solution (Python):
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,top_num,front_num):

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

        ret = -1

        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break

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

        return ret

    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):
n = int(input())
d = [input().split() for i in range(n)]





def rotate(faces, move):
    for i in range(len(move)):
        m = move[i]
        
        if m == "N":
            
            tmp = faces[4]
            faces[4] = faces[0]
            faces[0] = faces[1]
            faces[1] = faces[5]
            faces[5] = tmp
            
        elif m == "S":
            
            tmp = faces[1]
            faces[1] = faces[0]
            faces[0] = faces[4]
            faces[4] = faces[5]
            faces[5] = tmp
            
        elif m == "E":
            
            tmp = faces[2]
            faces[2] = faces[0]
            faces[0] = faces[3]
            faces[3] = faces[5]
            faces[5] = tmp
            
        elif m == "W":
            
            tmp = faces[3]
            faces[3] = faces[0]
            faces[0] = faces[2]
            faces[2] = faces[5]
            faces[5] = tmp





















        
def equals(a, b):
    for (a1, b1) in zip(a, b):
        if a1 != b1:
            return False
            
    return True


def check(a, b):
    
    isMatch = equals(a, b)
    
    
    looping = True
    for j in range(4):
        
        if isMatch:
            break
        for i in range(4):
            
            rotate(a, "N")
            if equals(a, b):
                isMatch = True
                break
        
        
        rotate(a, "W")
        
    
    
    
    
    
    rotate(a, "NW")
    
    for j in range(4):
        
        if isMatch:
            break
        for i in range(4):
            
            rotate(a, "N")
            if equals(a, b):
                isMatch = True
                break
        
        
        rotate(a, "W")
        
    
    return isMatch
    

result = True
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        
        if (check(d[i], d[j])):
            result = False

if result:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys
class dice:
    def __init__(s, i):
        s.d1,s.d2,s.d3,s.d4,s.d5,s.d6 = map(int, i)
    
    def W(s):
        tmp = s.d1
        s.d1 = s.d3
        s.d3 = s.d6
        s.d6 = s.d4
        s.d4 = tmp
        
    def E(s):
        tmp = s.d1
        s.d1 = s.d4
        s.d4 = s.d6
        s.d6 = s.d3
        s.d3 = tmp
        
    def N(s):
        tmp = s.d1
        s.d1 = s.d2
        s.d2 = s.d6
        s.d6 = s.d5
        s.d5 = tmp
        
    def S(s):
        tmp = s.d1
        s.d1 = s.d5
        s.d5 = s.d6
        s.d6 = s.d2
        s.d2 = tmp
        
    def L(s):
        tmp = s.d2
        s.d2 = s.d3
        s.d3 = s.d5
        s.d5 = s.d4
        s.d4 = tmp
        
    def isSame(s, d):
        flg = False
        
        
        for i in range(6):
            
            for j in range(6):
                if s.d1 == d.d1 and s.d6 == d.d6:
                    
                    for j in range(3):
                        if s.d2 == d.d2 and s.d3 == d.d3 and s.d4 == d.d4 and s.d5 == d.d5:
                            
                            return True
                        else:
                            
                            d.L()
                    
                
                if j <= 3:
                    d.N()
                elif j == 4:
                    d.E()
                else:
                    d.E()
                    d.E()
            
            
            if i <= 3:
                s.N()
            elif i == 4:
                s.E()
            else:
                s.E()
                s.E()
        
        
        return False

n = int(input())
dlst = []
for i in range(n):
    dice1 = dice(input().split())
    if i >= 1:
        for d in dlst:
            if dice1.isSame(d):
                print("No")
                sys.exit()
    dlst.append(dice1)
print("Yes")

Solution (Python):

from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


class Dice():

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

    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


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

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def equals(self,another):

        ret = False;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return ret



num_dice = int(input())
DICE = []

for i in range(num_dice):
    table = list(map(int,input().split()))
    tmp_dice = Dice()
    tmp_dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])
    DICE.append(tmp_dice)

FLG = True

for i in range(num_dice-1):
    for k in range(i+1,num_dice):
        if DICE[i].equals(DICE[k]) == True:
            FLG = False
            break


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

Solution (Python):
import sys

class Dise():
    def __init__(self, aLabelList):
        self.LabelList = aLabelList
        self.NEWS = {"N": [0,4,5,1],
                     "E": [0,2,5,3],
                     "W": [0,3,5,2],
                     "S": [0,1,5,4],
                     "R": [1,2,4,3]}
       
    def move(self,aNEWS):
        idx = self.NEWS[aNEWS]
        tmp = self.LabelList[idx[0]]
        self.LabelList[idx[0]] = self.LabelList[idx[3]]
        self.LabelList[idx[3]] = self.LabelList[idx[2]]
        self.LabelList[idx[2]] = self.LabelList[idx[1]]
        self.LabelList[idx[1]] = tmp

def step1():
    for i in range(4):
        if Dise1.LabelList[0] == Dise2.LabelList[0] and \
           Dise1.LabelList[5] == Dise2.LabelList[5]:
            step2()
        else:
            Dise2.move("E")
    
    Dise2.move("N")
    if Dise1.LabelList[0] == Dise2.LabelList[0] and \
       Dise1.LabelList[5] == Dise2.LabelList[5]:
        step2()
    
    Dise2.move("S")
    Dise2.move("S")
    if Dise1.LabelList[0] == Dise2.LabelList[0] and \
       Dise1.LabelList[5] == Dise2.LabelList[5]:
        step2()
    
def step2():
    for i in range(4):
        if Dise1.LabelList[1] == Dise2.LabelList[1] and \
           Dise1.LabelList[2] == Dise2.LabelList[2] and \
           Dise1.LabelList[3] == Dise2.LabelList[3] and \
           Dise1.LabelList[4] == Dise2.LabelList[4]:
            print("No")
            sys.exit()
        else:
            Dise2.move("R")

n = int(input())
DiseList = [Dise(input().split()) for i in range(n)]
for x in range(n-1):
    for y in range(x+1,n):
        Dise1 = DiseList[x]
        Dise2 = DiseList[y]
        step1()

print("Yes")

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

  def vertical(self, direction):
    s = self.state
    state = [s[1], s[5], s[0], s[4]]
    if direction < 0:
      s[0], s[1], s[4], s[5] = state
    elif 0 < direction:
      s[0], s[1], s[4], s[5] = reversed(state)
    return self
  
  def lateral(self, direction):
    s = self.state
    state = [s[2], s[5], s[0], s[3]]
    if direction < 0:
      s[0], s[2], s[3], s[5] = state
    elif 0 < direction:
      s[0], s[2], s[3], s[5] = reversed(state)
    return self

  def north(self):
    self.vertical(-1)
    return self

  def south(self):
    self.vertical(1)
    return self
  
  def east(self):
    self.lateral(1)
    return self

  def west(self):
    self.lateral(-1)
    return self

is_eql = False
n = int(input())
init_states = []

for i in range(n):
  init_states.append(input().split())

try:
  for i in range(0, n):
    for j in range(i + 1, n):
      dice1 = Dice(init_states[i])
      dice2 = Dice(init_states[j])
  
      for c in list('NNNNWNNNWNNNENNNENNNWNNN'):       
        if c == 'N':
          dice2.north()
        elif c == 'S':
          dice2.south()
        elif c == 'W':
          dice2.west()
        elif c == 'E':
          dice2.east()
        if dice1.state == dice2.state:
          is_eql = True
          raise Exception
except Exception:
  pass

print('No' if is_eql else 'Yes')

Solution (Python):
import sys
class dice:
    def __init__(s, i):
        s.d1,s.d2,s.d3,s.d4,s.d5,s.d6 = map(int, i)
    
    def W(s):
        tmp = s.d1
        s.d1 = s.d3
        s.d3 = s.d6
        s.d6 = s.d4
        s.d4 = tmp
        
    def E(s):
        tmp = s.d1
        s.d1 = s.d4
        s.d4 = s.d6
        s.d6 = s.d3
        s.d3 = tmp
        
    def N(s):
        tmp = s.d1
        s.d1 = s.d2
        s.d2 = s.d6
        s.d6 = s.d5
        s.d5 = tmp
        
    def S(s):
        tmp = s.d1
        s.d1 = s.d5
        s.d5 = s.d6
        s.d6 = s.d2
        s.d2 = tmp
        
    def L(s):
        tmp = s.d2
        s.d2 = s.d3
        s.d3 = s.d5
        s.d5 = s.d4
        s.d4 = tmp
        
    def isSame(s, d):
        flg = False
        
        
        for i in range(6):
            
            for j in range(6):
                if s.d1 == d.d1 and s.d6 == d.d6:
                    
                    for j in range(3):
                        if s.d2 == d.d2 and s.d3 == d.d3 and s.d4 == d.d4 and s.d5 == d.d5:
                            
                            return True
                        else:
                            
                            d.L()
                    
                
                if j <= 3:
                    d.N()
                elif j == 4:
                    d.E()
                else:
                    d.E()
                    d.E()
            
            
            if i <= 3:
                s.N()
            elif i == 4:
                s.E()
            else:
                s.E()
                s.E()
        
        
        return False

n = int(input())
dlst = []
for i in range(n):
    dice1 = dice(input().split())
    if i >= 1:
        for d in dlst:
            if dice1.isSame(d):
                print("No")
                sys.exit()
    dlst.append(dice1)
print("Yes")

Solution (Python):
import random

class  Dise:
    def __init__(self,top,flont,right,left,back,bottom):
        self.top,self.flont,self.right,self.left,self.back,self.bottom=top,flont,right,left,back,bottom
        self.order='NNNNWNNNWNNNENNNENNNWNN'
    def rot(self,d):
        if d=='N':
            self.top,self.flont,self.bottom,self.back=self.flont,self.bottom,self.back,self.top
        elif d=='E':
            self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom
        elif d=='S':
                self.top,self.flont,self.bottom,self.back=self.back,self.top,self.flont,self.bottom
        elif d=='W':
            self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top
    
    def gettop(self):
        return self.top
    def getfront(self):
        return self.flont
    def getright(self):
        return self.right
    def getleft(self):
        return self.left
    def getback(self):
        return self.back
    def getbottom(self):
        return self.bottom
    
    def equals(self,another):
        for i in range(len(self.order)):
            self.rot(self.order[i])
            flag=0
            if dise1.gettop()==dise2.gettop() and dise1.getfront()==dise2.getfront() and dise1.getright()==dise2.getright() and dise1.getleft()==dise2.getleft() and dise1.getback()==dise2.getback() and dise1.getbottom()==dise2.getbottom():
                flag=1
                break
        if flag==1:
            return 1
        else:
            return 0

n=int(input())
A=[[0*6]for i in range(n)]
for i in range(n):
    A[i]=list(map(int,input().split()))
    
flag=1
for i in range(n):
    for j in range(i+1,n):
        dise1=Dise(A[i][0],A[i][1],A[i][2],A[i][3],A[i][4],A[i][5])
        dise2=Dise(A[j][0],A[j][1],A[j][2],A[j][3],A[j][4],A[j][5])
        if dise1.equals(dise2)==1:
            flag=0
            break
if flag==1:
    print('Yes')
else:
    print('No')

Solution (Python):

class Dice():
 East = [ [0,3,5,2,4,0]
		 ,[4,0,1,6,0,3]
		 ,[2,6,0,0,1,5]
		 ,[5,1,0,0,6,2]
		 ,[3,0,6,1,0,4]
		 ,[0,4,2,5,3,0]
		 ]
 def __init__(self,N):
  self.label = N
  self.top = 1
  self.north = 5
 def move(self,ori):
  
  if ori=='S':
   t = self.top
   self.top = self.north
   self.north = 7-t
  elif ori=='N':
   t = self.top
   self.top = 7-self.north
   self.north = t
  elif ori=='E':
   east = self.East[self.north-1][self.top-1]
   self.top = 7-east
  elif ori=='W':
   east = self.East[self.north-1][self.top-1]
   self.top = east

  elif ori=='C': 
   east = self.East[self.north-1][self.top-1]
   self.north = east
 def gettop(self):
  return( self.label[self.top-1] )
 def getbottom(self):
  return( self.label[6-self.top] )
 def getnorth(self):
  return( self.label[self.north-1] )
 def getsouth(self):
  return( self.label[6-self.north] )
 def geteast(self):
  east = self.East[self.north-1][self.top-1]
  return( self.label[east-1] )
 def getwest(self):
  east = self.East[self.north-1][self.top-1]
  return( self.label[6-east] )

n = int(input())
Dices = [Dice(0 for x in range(6)) for y in range(n)]
for ni in range(n):
 label = list(map(int, input().split() ))
 Dices[ni] = Dice(label)
bAllDiff = True
for no in range(n-1):
 D = Dices[no]
 for ni in range(no+1,n):
  E = Dices[ni]
  
  bChecked = False
  sMove = 'NNNEEE'
  for mi in range(len(sMove)+1):
   if D.gettop() == E.gettop() and D.getbottom() == E.getbottom():
    sRot = 'CCCC'
    for ri in range(len(sRot)):
     if D.getnorth() == E.getnorth() and D.geteast() == E.geteast() and D.getsouth() == E.getsouth() and D.getwest() == E.getwest():
      bChecked = True
      bAllDiff = False
      
      break
     if ri<len(sRot):
      E.move(sRot[ri])
   if bChecked:
    break
   if mi<len(sMove):
    E.move(sMove[mi])
  
  
if bAllDiff:
 print('Yes')
else:
 print('No')

Solution (Python):

def dice_rotation(list1, str1):
    if str1 == "S":
        list1[0],list1[1],list1[4],list1[5] = list1[4],list1[0],list1[5],list1[1]
    elif str1 == "E":
        list1[0],list1[2],list1[3],list1[5] = list1[3],list1[0],list1[5],list1[2]
    elif str1 == "N":
        list1[0],list1[1],list1[4],list1[5] = list1[1],list1[5],list1[0],list1[4]
    elif str1 == "W":
        list1[0],list1[2],list1[3],list1[5] = list1[2],list1[5],list1[0],list1[3]
    return list1


def dice_find(list1, int1, int2):
    try:
        position_numnber = list1.index(int2)
    except:
        position_numnber = -1
    if position_numnber == 0:
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 2:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 4:
        list1 = dice_rotation(list1, "S")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "N")
    try:
        position_numnber = list1.index(int1)
    except:
        position_numnber = -1
    if position_numnber == 2:
        list1 = dice_rotation(list1, "W")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "W")
    return list1


def list_overlapping_check(list1):
    result = True
    for i in range(1, len(list1)):
        list1[i] = dice_find(list1[i], list1[0][0], list1[0][1])
        if list1[0] == list1[i]:
            result = False
            break
    if result == True and len(list1) > 2:
        result = list_overlapping_check(list1[1:])
    return result


input_count = int(input())
check_data = list()
for i in range(input_count):
    check_data.append(list(map(int, input().split())))


if list_overlapping_check(check_data) == True:
    print("Yes")
else:
    print("No")

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

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

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

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

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

    def up_front_to_right(self, top, front):
        if (top, front) in [(self.top, self.front), (self.front, self.bottom), (self.bottom, self.back), (self.back, self.top)]:
            return self.right
        elif (top, front) in [(self.front, self.top), (self.bottom, self.front), (self.back, self.bottom), (self.top, self.back)]:
            return self.left
        elif (top, front) in [(self.left, self.front), (self.front, self.right), (self.right, self.back), (self.back, self.left)]:
            return self.top
        elif (top, front) in [(self.front, self.left), (self.right, self.front), (self.back, self.right), (self.left, self.back)]:
            return self.bottom
        elif (top, front) in [(self.top, self.left), (self.left, self.bottom), (self.bottom, self.right), (self.right, self.top)]:
            return self.front
        elif (top, front) in [(self.left, self.top), (self.bottom, self.left), (self.right, self.bottom), (self.top, self.right)]:
            return self.back
        else:
            return -1

    def inverse(self, a):
        if a == self.top:
            return self.bottom
        elif a == self.front:
            return self.back
        elif a == self.right:
            return self.left
        elif a == self.left:
            return self.right
        elif a == self.back:
            return self.front
        elif a == self.front:
            return self.back
        else:
            return -1


def same(dice0, dice1):
    x = dice0.list
    for i in range(6):
        for j in range(i + 1, 6):
            if x[i] != dice0.inverse(x[j]):
                a = dice0.up_front_to_right(x[i], x[j])
                b = dice1.up_front_to_right(x[i], x[j])
                if a != b:
                    return False
    return True


n = int(input())
X = []
for i in range(n):
    *x, = map(int, input().split())
    X.append(Dice(x))
for i in range(n):
    for j in range(i + 1, n):
        if same(X[i], X[j]):
            print('No')
            exit()
print('Yes')

Solution (Python):
import sys
import os


N = int(input())
dices = []
for i in range(N):
    dice = list(map(int, input().split()))
    dices.append(dice)

def dice_roll(dice, c):
    copy = dice[:]
    if c == 'E':
        dice[2] = copy[0]
        dice[5] = copy[2]
        dice[3] = copy[5]
        dice[0] = copy[3]
    elif c == 'N':
        dice[0] = copy[1]
        dice[4] = copy[0]
        dice[5] = copy[4]
        dice[1] = copy[5]
        pass
    elif c == 'S':
        dice[1] = copy[0]
        dice[0] = copy[4]
        dice[4] = copy[5]
        dice[5] = copy[1]
    elif c == 'W':
        dice[0] = copy[2]
        dice[2] = copy[5]
        dice[5] = copy[3]
        dice[3] = copy[0]
    
    elif c == 'R':
        dice[2] = copy[1]
        dice[4] = copy[2]
        dice[3] = copy[4]
        dice[1] = copy[3]
    return dice


def check(dice0_input, dice1_input):
    
    dice0 = dice0_input[:]
    dice1 = dice1_input[:]

    
    num = 0
    while dice0[0] != dice1[0]:
        if num % 2 == 0:
            dice0 = dice_roll(dice0, 'E')
        else:
            dice0 = dice_roll(dice0, 'N')
        num += 1
        if num > 10:
            return False

    
    num = 0
    while dice0[1] != dice1[1]:
        dice0 = dice_roll(dice0, 'R')
        num += 1
        if num > 10:
            return False

    if dice0[2] == dice1[2] and dice0[3] == dice1[3] and dice0[4] == dice1[4] and dice0[5] == dice1[5]:
        return True
    else:
        return False


def check2(dice0, dice1):
    
    for i in range(6):
        result = check(dice0, dice1)
        if result:
            return True
        else:
            if i % 2 == 0:
                dice0 = dice_roll(dice0, 'N')
            else:
                dice0 = dice_roll(dice0, 'E')
    return False

for i in range(N):
    for j in range(i+1, N):
        is_same = check2(dices[i], dices[j])
        if is_same:
            print('No')
            quit()
print('Yes')