Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

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



Sample input:
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1


Sample output:
No

Submission status: Accepted

Solution code:
def dicing(lis, inst):
    if inst == 'N':
        ans_lis = [lis[1],lis[5],lis[2],lis[3],lis[0],lis[4]]
    if inst == 'W':
        ans_lis = [lis[2],lis[1],lis[5],lis[0],lis[4],lis[3]]
    if inst == 'S':
        ans_lis = [lis[4],lis[0],lis[2],lis[3],lis[5],lis[1]]
    if inst == 'E':
        ans_lis = [lis[3],lis[1],lis[0],lis[5],lis[4],lis[2]]
    
    return(ans_lis)

def turn_right(lis):
    inst = list('ENW')
    for i in range(len(inst)):
        lis = dicing(lis, inst[i])
    return(lis)

def find_above(lis, num1, num2):
    inst1 = list('NNNEWW')
    for i in range(len(inst1)):
        if lis[0] == num1 and lis[5] == num2:
            break
        
        lis = dicing(lis, inst1[i])
        if lis[0] == num1 and lis[5] == num2:
            break
    return(lis)

def find_samedice(dice1,dice2):
    YN = 'No'
    lis = find_above(dice1, dice2[0], dice2[5])
    for i in range(4):
        lis = turn_right(lis)
        if lis == dice2:
            YN = 'Yes'
            break
    return(YN)

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

ans = 'Yes'
for i in range(N):
    for j in range(N):
        if i < j:
            if find_samedice(dices[i], dices[j]) == 'Yes':
                ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
from collections import deque

def is_equal(dice1, dice2):

    equal = "No"

    if dice1.min != dice2.min or dice1.max != dice2.max:
        return "No"

    top0 = dice1.disp_top_face()
    front0 = dice1.disp_front_face()

    flag = 1

    for _ in range(100):

        if dice2.disp_top_face() == top0:
            flag = 0
            break

        for _ in range(4):
            dice2.lotate("S")

            if dice2.disp_top_face() == top0:
                flag = 0
                break

        if flag :
            dice2.lotate("E")
        else:
            break

    for _ in range(4):

        if dice2.disp_front_face() == front0:
            break

        dice2.lotate("E")
        dice2.lotate("S")
        dice2.lotate("W")

    if dice1.disp_top_face() == dice2.disp_top_face() and \
       dice1.disp_bottom_face() == dice2.disp_bottom_face() and \
       dice1.disp_front_face() == dice2.disp_front_face() and \
       dice1.disp_left_face() == dice2.disp_left_face() and \
       dice1.disp_right_face() == dice2.disp_right_face() and \
       dice1.disp_back_face() == dice2.disp_back_face():

       equal = "Yes"

    return equal

class Dice():
    def __init__(self, seq):
        self.v = deque([seq[5], seq[4], seq[0], seq[1]])
        self.h = deque([seq[3], seq[0], seq[2], seq[5]])

        self.max = max(seq)
        self.min = min(seq)

    def lotate(self, direction):

        if   direction == "E":
            self.h.rotate()
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "W":
            self.h.rotate(-1)
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "N":
            self.v.rotate(-1)
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        elif direction == "S":
            self.v.rotate()
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        else:
            pass

    def disp_top_face(self):
        return self.v[2]

    def disp_front_face(self):
        return self.v[3]

    def disp_back_face(self):
        return self.v[1]

    def disp_right_face(self):
        return self.h[2]

    def disp_left_face(self):
        return self.h[0]

    def disp_bottom_face(self):
        return self.h[3]

if __name__ == "__main__":

    param = input()
    n = int(param)

    dices = list()

    for _ in range(n):
        param = input().split(" ")
        seq = [int(a) for a in param]
        d = Dice(seq)
        dices.append(d)

    different = "Yes"

    for i in range(len(dices)-1):

        if len(dices) - 1 < 2:
            if is_equal(dices[i], dices[i+1]) == "Yes":
                different = "No"
        else:
            for j in range( i + 1, len(dices) - 1 ):
                if is_equal(dices[i], dices[j]) == "Yes":
                    different = "No"

    print(different)

Submission status: Accepted

Solution code:
import itertools


class Dice():
    def __init__(self, dice_labels):
        self.label = {
            'top': dice_labels[0],
            'south': dice_labels[1],
            'east': dice_labels[2],
            'west': dice_labels[3],
            'north': dice_labels[4],
            'bottom': dice_labels[5]
        }

    def roll(self, str_direction):
        if str_direction == 'E':
            self.__roll_to_east()
        elif str_direction == 'W':
            self.__roll_to_west()
        elif str_direction == 'S':
            self.__roll_to_south()
        elif str_direction == 'N':
            self.__roll_to_north()

    def turn(self, str_direction):
        if str_direction == 'L':
            self.__turn_left()
        elif str_direction == 'R':
            self.__turn_right()

    def __roll_to_east(self):
        self.label['top'], self.label['east'], self.label['west'], self.label['bottom'] = (self.label['west'], self.label['top'], self.label['bottom'], self.label['east'])

    def __roll_to_west(self):
        self.label['top'], self.label['east'], self.label['west'], self.label['bottom'] = (self.label['east'], self.label['bottom'], self.label['top'], self.label['west'])

    def __roll_to_south(self):
        self.label['top'], self.label['south'], self.label['north'], self.label['bottom'] = (self.label['north'], self.label['top'], self.label['bottom'], self.label['south'])

    def __roll_to_north(self):
        self.label['top'], self.label['south'], self.label['north'], self.label['bottom'] = (self.label['south'], self.label['bottom'], self.label['top'], self.label['north'])

    def __turn_right(self):
        self.label['south'], self.label['east'], self.label['west'], self.label['north'] = (self.label['east'], self.label['north'], self.label['south'], self.label['west'])

    def __turn_left(self):
        self.label['south'], self.label['east'], self.label['west'], self.label['north'] = (self.label['west'], self.label['south'], self.label['north'], self.label['east'])


def check_same_surface(dice1, dice2):
    for direction in ['top', 'bottom', 'east', 'west', 'south', 'north']:
        if dice1.label[direction] != dice2.label[direction]:
            return False
    return True


def check_same_dice(dice1, dice2):
    same_pattern_list = []
    for turn_lr in ['R'] * 4:
        for roll_sn in ['N'] * 4:
            for roll_ew in ['E'] * 4:
                dice2.roll(roll_ew)
                same_pattern_list.append(check_same_surface(dice1, dice2))
            dice2.roll(roll_sn)
            same_pattern_list.append(check_same_surface(dice1, dice2))
        dice2.turn(turn_lr)
        same_pattern_list.append(check_same_surface(dice1, dice2))
    return True in same_pattern_list


num_dices = int(input())
dices = []
for dice_number in range(0, num_dices):
    dice_labels = input().split(' ')
    dices.append(Dice(dice_labels))

is_same_dice_result_list = []
for dice1, dice2 in itertools.combinations(dices, 2):
    is_same_dice_result_list.append(check_same_dice(dice1, dice2))

if True in is_same_dice_result_list:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
def lotate(dic, dire):
    if dire == 'N':
        x,y,z,w = dic['up'], dic['back'], dic['bottom'], dic['front']
        dic['back'], dic['bottom'], dic['front'], dic['up'] = x,y,z,w
    elif dire == 'S':
        x, y, z, w = dic['up'], dic['back'], dic['bottom'], dic['front']
        dic['front'], dic['up'], dic['back'], dic['bottom'] = x, y, z, w
    elif dire == 'W':
        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
        dic['left'], dic['bottom'], dic['right'], dic['up'] = x, y, z, w
    elif dire == 'E':
        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
        dic['right'], dic['up'], dic['left'], dic['bottom'] = x, y, z, w
    return dic


n = int(input())
dice = []
for i in range(n):
    a1,b1,c1,d1,e1,f1 = map(int, input().split())
    dice.append({'up': a1, 'front': b1, 'right': c1, 'left': d1, 'back': e1, 'bottom': f1})
ans = 'Yes'
for i in range(1, n):
    for j in range(1, i+1):
        if dice[i-j] == dice[i]:
            ans = 'No'
        else:
            s = 'EEENEEENEEESEEESEEENEEEN'
            for k in s:
                dice[i-j] = lotate(dice[i-j], k)
                if dice[i-j] == dice[i]:
                    ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
import itertools
import random


class Dice(object):

    def __init__(self, *args):
        self.faces = [None]
        self.faces.extend(args)
        self.top = self.faces[1]
        self.up = self.faces[5]
        self.down = self.faces[2]
        self.left = self.faces[4]
        self.right = self.faces[3]
        self.back = self.faces[6]

    def roll(self, direction):
        if direction == "N":
            self.top, self.up, self.down, self.back = self.down, self.top, self.back, self.up
        elif direction == "S":
            self.top, self.up, self.down, self.back = self.up, self.back, self.top, self.down
        elif direction == "W":
            self.top, self.left, self.right, self.back = self.right, self.top, self.back, self.left
        elif direction == "E":
            self.top, self.left, self.right, self.back = self.left, self.back, self.top, self.right
        else:
            raise ValueError("{} is not valid direction.".format(direction))

    def __eq__(self, other):
        return (
           self.top, self.up, self.left, self.down, self.right, self.back
        ) == (
            other.top, other.up, other.left, other.down, other.right, other.back
        )


def is_equal_pair(d1, d2):
    i = 0
    while i < 100:
        if d1 == d2:
            return True
        d2.roll(random.choice(["N", "S", "W", "E"]))
        i += 1
    return False


n = int(input())
dices = []
for i in range(n):
    f = [int(i) for i in input().split()]
    dice = Dice(*f)
    dices.append(dice)

ans = "Yes"
for d1, d2 in itertools.combinations(dices, 2):
    if is_equal_pair(d1, d2):
        ans = "No"
        break

print(ans)

Submission status: Accepted

Solution code:
def East(a,b,c,d,e,f):
    return [d, b, a, f, e, c]
def West(a,b,c,d,e,f):
    return [c, b, f, a, e, d]
def South(a,b,c,d,e,f):
    return [e, a, c, d, f, b]
def North(a,b,c,d,e,f):
    return [b, f, c, d, a, e]
def Rot(a,b,c,d,e,f):
    return [a,d,b,e,c,f]



def Judge(change, change_after):
    flag=0
    for idx in range(0, 5):
        change=South(*change)
        #print(change)
        if change==change_after:
            flag=flag+1
        for idx2 in range(0,4):
            change=Rot(*change)
            #print(change)
            if change==change_after:
               flag=1+flag
               
    for idx in range(0, 5):
        change=West(*change)
        #print(change)
        if change==change_after:
            flag=flag+1
        for idx2 in range(0,4):
            change=Rot(*change)
            #print(change)
            if change==change_after:
               flag=1+flag
    return flag
    
n=int(input())
matrix=[]
for i in range(0, n):
    change=list( map(int,input().split()))
    matrix.append(change)
    #change_after=list( map(int,input().split()))

judge_number=0
for i in range(0, n-1):
    change=matrix[i]
    for j in range(i+1, n):
        change_after=matrix[j]
        judge_number=Judge(change, change_after)+judge_number
       

if judge_number==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from itertools import combinations as combi

class Dice():
    def __init__(self, up, back, right, left, front, down):
        self.up = up
        self.down = down
        self.right = right
        self.left = left
        self.front = front
        self.back = back
    
    def north(self):
        temp = self.up
        self.up = self.back
        self.back = self.down
        self.down = self.front
        self.front = temp
    
    def south(self):
        temp = self.up
        self.up = self.front
        self.front = self.down
        self.down = self.back
        self.back = temp
        
    def east(self):
        temp = self.up
        self.up = self.left
        self.left = self.down
        self.down = self.right
        self.right = temp
    
    def west(self):
        temp = self.up
        self.up = self.right
        self.right = self.down
        self.down = self.left
        self.left = temp
    
    def counterclockwise(self):
        temp = self.back
        self.back = self.left
        self.left = self.front
        self.front = self.right
        self.right = temp
    
    def clockwise(self):
        temp = self.back
        self.back = self.right
        self.right = self.front
        self.front = self.left
        self.left = temp
        
    def operate(self, op):
        if op == "N":
            self.north()
        elif op == "S":
            self.south()
        elif op == "E":
            self.east()
        elif op == "W":
            self.west()
        
    def fix_up(self, up):
        if self.down == up:
            self.north()
            self.north()
        elif self.right == up:
            self.west()
        elif self.left == up:
            self.east()
        elif self.front == up:
            self.south()
        elif self.back == up:
            self.north()

    def fix_back_with_fixed_up(self, back):
        if self.right == back:
            self.clockwise()
        elif self.left == back:
            self.counterclockwise()
        elif self.front == back:
            self.clockwise()
            self.clockwise()
            
    def equals_narrow_sense(self, dice):
        if self.up == dice.up and self.down == dice.down and self.right == dice.right and self.left == dice.left and self.back == dice.back and self.front == dice.front:
            return True
        else:
            return False

def is_equal_dice(dice1, dice2):
    for i in range(6):
        if 0 < i <= 3:
            dice1.north()
        elif i == 4:
            dice1.west()
        elif i == 5:
            dice1.east()
            dice1.east()

        for l in range(4):
            dice1.clockwise()

            for j in range(6):
                if 0 < j <= 3:
                    dice2.north()
                elif j == 4:
                    dice2.west()
                elif j == 5:
                    dice2.east()
                    dice2.east()

                for k in range(4):
                    dice2.clockwise()

                    if dice1.equals_narrow_sense(dice2):
                        return True
    return False

dice_n = int(input())

dice_lst = []
for _ in range(dice_n):
    up, back, right, left, front, down = map(int, input().split())
    dice_lst.append(Dice(up, back, right, left, front, down))
    
equal_flag = False
for pair in combi(dice_lst, 2):
    if is_equal_dice(pair[0], pair[1]):
        equal_flag = True
        break

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

Submission status: Accepted

Solution code:
import sys

class Dice():
    top=0
    n=1
    e=3
    w=2
    s=4
    bottom=5
    dice=[1,2,3,4,5,6]
    def __init__(self,num):
        self.dice=num

    def roll(self,direction):
        if(direction=="N"):
            self.top,self.bottom,self.n,self.s = self.n,5-self.n,5-self.top,self.top
        elif(direction=="E"):
            self.top,self.bottom,self.e,self.w = self.e,5-self.e,5-self.top,self.top
        elif(direction=="W"):
            self.top,self.bottom,self.e,self.w = self.w,5-self.w,self.top,5-self.top
        elif(direction=="S"):
            self.top,self.bottom,self.n,self.s = self.s,5-self.s,self.top,5-self.top

    def equal(self,another):
        if(self.dice[self.top] != another.dice[another.top]):
            return False
        if(self.dice[self.n] != another.dice[another.n]):
            return False
        if(self.dice[self.e] != another.dice[another.e]):
            return False
        if(self.dice[self.w] != another.dice[another.w]):
            return False
        if(self.dice[self.s] != another.dice[another.s]):
            return False
        if(self.dice[self.bottom] != another.dice[another.bottom]):
            return False

        return True

n=int(input())
dicea=Dice(list(map(int,input().split())))

for i in range(n-1):
    diceb=Dice(list(map(int,input().split())))

    roll_order="NNNNWNNNWNNNENNNENNNWNNNN"
    for j in range(len(roll_order)):
        if(dicea.equal(diceb)):
            print("No")
            sys.exit()
        else:
            diceb.roll(roll_order[j])
print("Yes")

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,u,s,e,w,n,d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d
    
    def rot(self,way):
        # vertically
        if way == 0:
            c = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = c
        #rotate
        if way == 1:
            c = self.e
            self.e = self.n
            self.n = self.w
            self.w = self.s
            self.s = c
        #holizantally
        if way == 2:
            c = self.w
            self.w = self.d
            self.d = self.e
            self.e = self.u
            self.u = c

def compare(inp1,inp2):
    if not inp1[0] in inp2:
        return 'No'
    dice1 = Dice(inp1[0],inp1[1],inp1[2],inp1[3],inp1[4],inp1[5])
    dice2 = Dice(inp2[0],inp2[1],inp2[2],inp2[3],inp2[4],inp2[5])
    count = 0
    flag = 0
    while True:
        if dice1.u == dice2.u:
            for s in range(5):
                if dice1.s == dice2.s and dice1.e == dice2.e and dice1.w == dice2.w and dice1.n == dice2.n:
                    if dice1.d == dice2.d:
                        flag = 1
                        return 'Yes'
                    break
                else:
                    dice2.rot(1)
            if not flag:
                if dice1.d == dice2.s and dice1.u == dice2.n:
                    if (dice1.s == dice2.u) and (dice1.n == dice2.d) and (dice1.e == dice2.e) and (dice1.w == dice2.w):
                        return 'Yes'
                    else:
                        return 'No'
                elif dice1.d == dice2.e and dice1.u == dice2.w:
                    if (dice1.s == dice2.s) and (dice1.n == dice2.n) and (dice1.e == dice2.u) and (dice1.w == dice2.d):
                        return 'Yes'
                    else:
                        return 'No'
                elif dice1.d == dice2.w and dice1.u == dice2.e:
                    if (dice1.s == dice2.s) and (dice1.n == dice2.n) and (dice1.e == dice2.d) and (dice1.w == dice2.u):
                        return 'Yes'
                    else:
                        return 'No'
                elif dice1.d == dice2.n and dice1.u == dice2.s:
                    if (dice1.s == dice2.d) and (dice1.n == dice2.u) and (dice1.e == dice2.e) and (dice1.w == dice2.w):
                        return 'Yes'
                    else:
                        return 'No'
                else:
                    return 'No'
            break
        elif count < 5:
            dice2.rot(0)
            count += 1
        else:
            dice2.rot(1)
            count = 0
            
times = int(input())
input_list = list()
results = list()
for t in range(times):
    inp = list(map(int,input().split()))
    input_list.append(inp)

for il in input_list:
    for l in input_list:
        if input_list.index(il) != input_list.index(l):
            results.append(compare(il,l))

if 'Yes' in results:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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


def roll(s, rolllist):
    news = list(s)
    for i in range(6):
        news[i] = s[rolllist[i]]
    return news


# 同じサイコロならTrue 異なるならFalse
def isSameDice(s1, s2):
    rl = {0: [0, 1, 2, 3, 4, 5],
          1: [1, 5, 2, 3, 0, 4],  # N
          2: [2, 1, 5, 0, 4, 3],  # W
          3: [3, 1, 0, 5, 4, 2],  # E
          4: [4, 0, 2, 3, 5, 1],  # S
          5: [5, 4, 2, 3, 1, 0]}
    roll_z = [0, 3, 1, 4, 2, 5]
    if not (s1[0] in s2):
        return False
    # t = s2.index(s1[0])
    tl = [i for i, x in enumerate(s2) if x == s1[0]]
    for t in tl:
        s2 = roll(s2, rl[t])
        ss = s2
        for i in range(6):
            if s1 == ss:
                return True
            ss = roll(ss, roll_z)
    return False


c = []
for i in range(len(s)):
    for j in range(len(s)):
        if i < j:
            c.append([i, j])
for cc in c:
    if isSameDice(s[cc[0]], s[cc[1]]):
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
face = [0]*6
class Dice():

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

    def setnumbers(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 spin(self, command):
        for i in range(6):
            face[i] = self.number[i]
        if command == 'S':
            self.setnumbers(face[4], face[0], face[2], face[3], face[5], face[1])
            # print('command is S')
        elif command == 'N':
            self.setnumbers(face[1], face[5], face[2], face[3], face[0], face[4])
            # print('command is N')
        elif command == 'E':
            self.setnumbers(face[3], face[1], face[0], face[5], face[4], face[2])
            # print('command is E')
        elif command == 'W':
            self.setnumbers(face[2], face[1], face[5], face[0], face[4], face[3])
            # print('command is W')
    def equal(self, another):
        set = False
        for i in self.order:
            self.spin(i)
            FLAG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLAG = False
                    break
            if FLAG == True:
                return True
        return set

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

    k= Dice()
    dice.append(k)

    k.setnumbers(inp[0], inp[1], inp[2], inp[3], inp[4], inp[5])


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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    dices=[]
    same = 0
    for _ in range(n):
        dices.append(list(map(int, input().split())))

    for i in range(n-1):
        for j in range(i+1,n):
            same += check_dice(dices[i], dices[j])
        if same >= 1:
            print('No')
            break

    if same == 0:
        print('Yes')


def check_dice(f, s):
    yes = 0
    for _ in range(4):
        s[0],s[2],s[5],s[3] = s[2],s[5],s[3],s[0]
        for _ in range(4):
            s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]
            if f == s:
                yes = 1

    for _ in range(4):
        s[0],s[1],s[5],s[4] = s[1],s[5],s[4],s[0]
        for _ in range(4):
            s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]
            if f == s:
                yes = 1

    return yes

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import random

class Dice():
    def __init__(self):
        self.face = [i for i in range(6)]
        self.memo = [i for i in range(6)]

    def setface(self,initface):
        for i in range(6):
            self.face[i] = initface[i]

    def roll(self,direction):
        for i in range(6):
            self.memo[i] = self.face[i]
        index = {'E':(3,1,0,5,4,2),'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'W':(2,1,5,0,4,3)}
        for i in range(6):
            self.face[i] = self.memo[index[direction][i]]

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

n = int(input())
dice1 = Dice()
dice1.setface(list(map(int,input().split())))
flag = 0
for d in range(n-1):
    dicei = Dice()
    dicei.setface(list(map(int,input().split())))
    for i in range(1000):
        dicei.roll(['E','N','S','W'][random.randint(0,3)])
        for j in range(6):
            if dice1.face[j]!=dicei.face[j]:
                break
        else:
            if not flag:print('No' )
            flag = 1
            break
if not flag:
    print('Yes')

Submission status: Accepted

Solution code:
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):
            # print(f'a {D.face}')
            if D.face[0] == E.face[0]:
                for _ in range(4):
                    # print(f'b {D.face}')
                    if D.face == E.face:
                        return True
                    else:
                        D.rotate('R')
            D.rotate('N')
        for _ in range(4):
            # print(f'c {D.face}')
            if D.face[0] == E.face[0]:
                for _ in range(4):
                    # print(f'd {D.face}')
                    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')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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')