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:
#-*- coding:utf-8 -*-
import sys
n = input()
rolls =[]
for x in xrange(n):
    rolls.append(raw_input().split())
def pareExist(li1,li2):
    for x in xrange(3):
        if set(rolls1pare[x]) not in map(set,rolls2pare):
            return False
    return True
#??????????????¨??????????????????????????????
#?????´????????????????????¨??????????????£???????????§??????
for l1 in xrange(n):
    for l2 in xrange(n):
        #??????????????????????????????
        #?????????????????????????????´????????????????????????????????????????????£????????????????????????
        if l1==l2:
            break
        rolls_copy = rolls
        #??¨??¨????????¢?????£????????????????????´???????????¢???3????????¨??????????¢????
        rolls1pare = [(rolls_copy[l1][0],rolls_copy[l1][5]),(rolls_copy[l1][2],rolls_copy[l1][3]),(rolls_copy[l1][1],rolls_copy[l1][4])]
        testpare = (rolls_copy[l1][0],rolls_copy[l1][5])
        testparerev = (rolls_copy[l1][5],rolls_copy[l1][0])
        rolls2pare = [(rolls_copy[l2][0],rolls_copy[l2][5]),(rolls_copy[l2][2],rolls_copy[l2][3]),(rolls_copy[l2][1],rolls_copy[l2][4])]
        # print rolls1pare
        # print rolls2pare
        #?????????????????¢???????????°?????´?????????????????????
        if not pareExist(rolls1pare,rolls2pare):
            break
        #??????????????¢????????¢??§?????´??????????????????????????????????¢????
        if testpare in rolls2pare:
            pareps = rolls2pare.index(testpare)
            revflag = False
        elif testparerev in rolls2pare:
            pareps = rolls2pare.index(testparerev)
            revflag = True
        else:
            break
        #?¬???????????????¢??\????????¨????????????????????£??????????¢????
        #??????????????????????????????
        li1 = [rolls_copy[l1][1],rolls_copy[l1][2],rolls_copy[l1][4],rolls_copy[l1][3]]
        # print pareps
        if pareps==0:
            if revflag:
                tmp = rolls_copy[l2][2]
                rolls_copy[l2][2] = rolls_copy[l2][3]
                rolls_copy[l2][3] = tmp
            li2 = [rolls_copy[l2][1],rolls_copy[l2][2],rolls_copy[l2][4],rolls_copy[l2][3]]
        elif pareps==1:
            if revflag:
                tmp = rolls_copy[l2][1]
                rolls_copy[l2][1] = rolls_copy[l2][4]
                rolls_copy[l2][4] = tmp
            li2 = [rolls_copy[l2][0],rolls_copy[l2][1],rolls_copy[l2][5],rolls_copy[l2][4]]
        elif pareps==2:
            if revflag:
                tmp = rolls_copy[l2][0]
                rolls_copy[l2][0] = rolls_copy[l2][5]
                rolls_copy[l2][5] = tmp
            li2 = [rolls_copy[l2][0],rolls_copy[l2][3],rolls_copy[l2][5],rolls_copy[l2][2]]
        else:
            break
        #?????????????????´?¢????
        # print li1
        # print li2
        i=0
        j=li2.index(li1[0])
        matchflag = True#else??\??£???????????´?????????
        for x in xrange(4):
            # print "%s : %s"%(li1[i],li2[j])
            if li1[i]==li2[j]:
                j+=1
                i+=1
            else:
                matchflag =False
                break
            if i>3:
                i=0
            if j>3:
                j=0
        if matchflag:
            print "No"
            sys.exit(0)
print "Yes"

Submission status: Accepted

Solution code:
ROLL_MASTER = (
    (0, 1, 2, 3, 4, 5), (1, 0, 3, 2, 5, 4), (2, 0, 1, 4, 5, 3),
    (3, 0, 4, 1, 5, 2), (4, 0, 2, 3, 5, 1), (5, 1, 3, 2, 4, 0))
TWIST_MASTER = (0, 2, 4, 1, 3, 5)


def roll(dice, top):
    return tuple(dice[i] for i in ROLL_MASTER[top])


def twist(dice):
    return tuple(dice[i] for i in TWIST_MASTER)


def twist_check(d1, d2):
    if d1[0] != d2[0] or d1[5] != d2[5]:
        return False
    for _ in range(4):
        if d1 == d2:
            return True
        d2 = twist(d2)
    return False


def equal_check(d1, d2):
    for i in range(6):
        if twist_check(d1, roll(d2, i)):
            return True
    return False


def differs_all():
    n, d1, dset = int(input()), tuple(map(int, input().split())), set()
    dset.add(d1)

    for _ in range(n - 1):
        d2 = tuple(map(int, input().split()))
        for d1 in dset:
            if equal_check(d1, d2):
                return False
        dset.add(d2)
    return True


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

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, nums):
        self.nums = nums
        self.top, self.front, self.right = 0, 1, 2

    def __eq__(self, dice):
        for x in "NNNNEEE":
            dice.move(x)
            for _ in range(4):
                dice.move("ESW")
                if self.nums[self.top] == dice.nums[dice.top] and \
                        self.nums[self.front] == dice.nums[dice.front] and \
                        self.nums[self.right] == dice.nums[dice.right] and \
                        self.nums[5 - self.top] == dice.nums[5 - dice.top] and \
                        self.nums[5 - self.front] == dice.nums[5 - dice.front] and \
                        self.nums[5 - self.right] == dice.nums[5 - dice.right]:
                    return True
        return False

    def move(self, op):
        for c in op:
            if c == 'N':
                self.top, self.front = self.front, 5 - self.top
            elif c == 'S':
                self.top, self.front = 5 - self.front, self.top
            elif c == 'E':
                self.top, self.right = 5 - self.right, self.top
            else:
                self.top, self.right = self.right, 5 - self.top

n = int(input())
ans = "Yes"
dices = []
dices.append(Dice([int(n) for n in input().split()]))
for _ in range(n - 1):
    new_dice = Dice([int(n) for n in input().split()])
    for dice in dices:
        if dice == new_dice:
            ans = "No"
            break
    dices.append(new_dice)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

class dice_class:
    def __init__(self, list):
        self.num = list

    def sut(self, top):  #set_up_top
        i = 0
        while i < 3:
            if self.num[0] == top:
                break
            else:
                self.roll('E')
            if self.num[0] == top:
                break
            else:
                self.roll('N')
            i += 1

    def suf(self, front):   #set_up_front
        i = 0
        while i < 4:
            if self.num[1] == front:
                break
            else:
                self.roll('SEN')
            i += 1

    def roll(self, s):
        for i in s:
            if i == 'E':
                self.rollE()
            elif i == 'N':
                self.rollN()
            elif i == 'S':
                self.rollS()
            elif i == 'W':
                self.rollW()

    def rollE(self):
        self.num = [self.num[3], self.num[1], self.num[0], self.num[5], self.num[4], self.num[2]]

    def rollN(self):
        self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]]

    def rollS(self):
        self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]]

    def rollW(self):
        self.num = [self.num[2], self.num[1], self.num[5], self.num[0], self.num[4], self.num[3]]


if __name__ == "__main__":
    n = int(raw_input())
    dice_List = []
    for i in range(n):
        dice_List.append(dice_class(map(int, raw_input().split())))
    flg = True

    for i in range(n):
        for j in range(i+1, n):
            for k in range(6):
                if k % 2:
                    dice_List[i].roll('E')
                else:
                    dice_List[i].roll('N')
                dice_List[j].sut(dice_List[i].num[0])
                dice_List[j].suf(dice_List[i].num[1])
                if dice_List[i].num == dice_List[j].num:
                    flg = False
                    break
    if flg:
        print "Yes"
    else:
        print "No"

Submission status: Accepted

Solution code:
import sys
import itertools

class Dice:
    def __init__(self):
        self.front = '1'
        self.back = '6'
        self.top = '5'
        self.bottom = '2'
        self. right = '3'
        self.left = '4'
    def turnRight(self):
        temp = self.top
        self.top = self.left
        self.left = self.bottom
        self.bottom = self.right
        self.right = temp
        return self.top
    def turnLeft(self):
        temp = self.top
        self.top = self.right
        self.right = self.bottom
        self.bottom = self.left
        self.left = temp
        return self.top
    def turnFront(self):
        temp = self.top
        self.top = self.back
        self.back = self.bottom
        self.bottom = self.front
        self.front = temp
        return self.top
    def turnBack(self):
        temp = self.top
        self.top = self.front
        self.front = self.bottom
        self.bottom = self.back
        self.back = temp
        return self.top
    def __eq__(self, other):
        return (self.top, self.bottom, self.front, self.back, self.right, self.left) == other
    def __ne__(self, other):
        return (self.top, self.bottom, self.front, self.back, self.right, self.left) != other

def compdice(A, B):
    for rot1 in range(4):
        for rot2 in range(4):
            if A == B:
                return True
            B.turnRight()
        B.turnFront()
    B.turnRight()
    B.turnFront()
    for rot in range(4):
        if A == B:
            return True
        B.turnRight()
    B.turnBack()
    B.turnBack()
    for rot in range(4):
        if A == B:
            return True
        B.turnRight()
    return False

ans = 'Yes'
n = int(input())
dices = []
for line in range(n):
    dice = Dice()
    dice.top, dice.front, dice.right, dice.left, dice.back, dice.bottom = input().split()
    dices.append(dice)
dicepairs = itertools.combinations(dices, 2)
for dicepair in dicepairs:
    A, B = dicepair
    if compdice(A, B):
        ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
def move_dice(d, dir):
    if(dir == 'N'):
        d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
    if(dir == 'S'):
        d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]
    if(dir == 'E'):
        d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
    if(dir == 'W'):
        d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]

def rotate_right_dice(d):
    d[1], d[2], d[3], d[4] = d[3], d[1], d[4], d[2]

def to_up_dice(d, num_index):
    move_num = {0:0, 1:3, 2:2, 3:0, 4:1, 5:2}
    if(num_index==2 or num_index==3):
        move_dice(d, 'E')
    for _ in range(move_num[num_index]):
        move_dice(d, 'N')

def to_front_dice(d, num):
    while(d[1] != num):
        rotate_right_dice(d)

def equal_dice(d1, d2):
    for i in range(6):
        tmp_d = list(d1)
        to_up_dice(tmp_d, i)
        for _ in range(4):
            if(tmp_d == d2): return 'Yes'
            else: rotate_right_dice(tmp_d)
    return 'No'

def equal_dice_n(d_list, n):
    for i in range(n-1):
        for j in range(i+1, n):
            if(equal_dice(d_list[i], d_list[j]) == 'Yes'):
                return 'No'
    return 'Yes'

n = int(input())
d_list = [list(map(int, input().split())) for _ in range(n)]
print(equal_dice_n(d_list, n))

Submission status: Accepted

Solution code:
n=int(input())

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

def gen_all( d1 ):
    ds = { d1 }
    while 1:
        ds2 = { rot(d, r) for d in ds for r in list('NEWS') }.union(ds)
        if ds == ds2: break
        ds = ds2
    return ds

ds = {}

for i in range(n):
    d=tuple(map(int,input().split()))
    ds[i] = (d, gen_all(d))

dep=any ([ ds[i][0] in ds[j][1] for i in range(n) for j in range(i+1,n) ])
    
print('No' if dep else 'Yes')

Submission status: Accepted

Solution code:
# move the dice from south to north
def s2n(dice):
    aft_dice = [dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]]
    return aft_dice

# move the dice from west to east
def w2e(dice):
    aft_dice = [dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]]
    return aft_dice

# spin the dice to right
def rspin(dice):
    aft_dice = [dice[0],dice[2],dice[4],dice[1],dice[3],dice[5]]
    return aft_dice

# is same dice ?
def isd(dice1, dice2):
    flag = 0
    for i in xrange(4):
        for j in xrange(4):
            flag += 1 if dice1 == dice2 else 0
            dice2 = rspin(dice2)
        dice2 = s2n(dice2)

    dice2 = w2e(dice2)
    for i in xrange(4):
        flag += 1 if dice1 == dice2 else 0
        dice2 = rspin(dice2)

    dice2 = w2e(dice2)
    dice2 = w2e(dice2)
    for i in xrange(4):
        flag += 1 if dice1 == dice2 else 0
        dice2 = rspin(dice2)
    return flag

# MAIN
dices = []
n = input()
for i in xrange(n):
    dices.append( map(int, raw_input().split()) )

for i in xrange(n-1):
    for j in xrange(i+1,n):
        if isd(dices[i], dices[j]) > 0:
            print "No"
            exit()
print "Yes"

Submission status: Accepted

Solution code:
import random
class Dice:
    def __init__(self, ls):
        self.top,   self.bottom = ls[0], ls[5]
        self.right, self.left   = ls[2], ls[3]
        self.front, self.back   = ls[1], ls[4]
    def rot(self, d):
        if   d == "N":
            (self.top, self.back, self.bottom, self.front) = (
             self.front, self.top, self.back, self.bottom)
        elif d == "S":
            (self.top, self.back, self.bottom, self.front) = (
             self.back, self.bottom, self.front, self.top)
        elif d == "E":
            (self.top, self.right, self.bottom, self.left) = (
             self.left, self.top, self.right, self.bottom)
        elif d == "W":
            (self.top, self.right, self.bottom, self.left) = (
             self.right, self.bottom, self.left, self.top)
    def show(self):
        return (self.top, self.bottom, self.right,
                self.left, self.front, self.back)
S = set()
N = int(raw_input())
judge = True
for i in xrange(N):
    dice = Dice(map(int, raw_input().split()))
    s = set()
    for loop in xrange(1000):
        nums = dice.show()
        if nums in S:
            judge = False
            break
        s.add(nums)
        dice.rot("NSEW"[random.randint(0, 3)])
    if not judge:
        break
    S |= s
print "Yes" if judge else "No"

Submission status: Accepted

Solution code:
class dice:
    def __init__(self,label):
        self.label = {i+1: l for i,l in enumerate(label)}
    def roll(self,op):
        l = self.label
        if   op=='N': self.label = {1:l[2], 2:l[6], 3:l[3], 4:l[4], 5:l[1], 6:l[5]}
        elif op=='E': self.label = {1:l[4], 2:l[2], 3:l[1], 4:l[6], 5:l[5], 6:l[3]}
        elif op=='W': self.label = {1:l[3], 2:l[2], 3:l[6], 4:l[1], 5:l[5], 6:l[4]}
        elif op=='S': self.label = {1:l[5], 2:l[1], 3:l[3], 4:l[4], 5:l[6], 6:l[2]}
    def yaw(self,op):
        l = self.label
        if   op=='CW' : self.label = {1:l[1], 2:l[3], 3:l[5], 4:l[2], 5:l[4], 6:l[6]}
        elif op=='CCW': self.label = {1:l[1], 2:l[4], 3:l[2], 4:l[5], 5:l[3], 6:l[6]}
    def get_label(self,i=0):
        if 1 <= i <= 6:
            return self.label[i]
        else:
            return [self.label[x] for x in range(1,7)] 

def cmp_dice(d0,d1):
    dc = dice(d0.get_label())
    d1_l = d1.get_label()
    result=False
    if set(dc.get_label())==set(d1_l):
        for i in range(6):
            for _ in range(4):
                if dc.get_label()==d1_l:
                    result=True
                    break
                dc.yaw('CW')
            if dc.get_label()==d1_l:
                break
            if i < 4:
                dc.roll('E')
            if i >= 3:
                dc.roll('N')
            if i >= 4:
                dc.roll('N')
    return result

if __name__ == '__main__':
    import itertools
    n=int(input())
    d_list = [dice(list(map(int, input().split()))) for _ in range(n)]
    result='Yes'
    for dx, dy in itertools.combinations(d_list,2):
        if cmp_dice(dx,dy):
            result='No'
            break
    print(result)

Submission status: Accepted

Solution code:
class dice:
    def __init__(self,label):
        self.label = {i+1: l for i,l in enumerate(label)}
    def roll(self,op):
        l = self.label
        if   op=='N': self.label = {1:l[2], 2:l[6], 3:l[3], 4:l[4], 5:l[1], 6:l[5]}
        elif op=='E': self.label = {1:l[4], 2:l[2], 3:l[1], 4:l[6], 5:l[5], 6:l[3]}
        elif op=='W': self.label = {1:l[3], 2:l[2], 3:l[6], 4:l[1], 5:l[5], 6:l[4]}
        elif op=='S': self.label = {1:l[5], 2:l[1], 3:l[3], 4:l[4], 5:l[6], 6:l[2]}
    def yaw(self,op):
        l = self.label
        if   op=='CW' : self.label = {1:l[1], 2:l[3], 3:l[5], 4:l[2], 5:l[4], 6:l[6]}
        elif op=='CCW': self.label = {1:l[1], 2:l[4], 3:l[2], 4:l[5], 5:l[3], 6:l[6]}
    def get_label(self,i=0):
        if 1 <= i <= 6:
            return self.label[i]
        else:
            return [self.label[x] for x in range(1,7)] 

def cmp_dice(d0,d1):
    dc = dice(d0.get_label())
    d1_l = d1.get_label()
    result=False
    if set(dc.get_label())==set(d1_l):
        for i in range(6):
            for _ in range(4):
                if dc.get_label()==d1_l:
                    result=True
                    break
                dc.yaw('CW')
            if dc.get_label()==d1_l:
                break
            if i < 4:
                dc.roll('E')
            if i >= 3:
                dc.roll('N')
            if i >= 4:
                dc.roll('N')
    return result

if __name__ == '__main__':
    import itertools
    d_grp={}
    for _ in range(int(input())):
        d = dice(list(map(int, input().split())))
        d_set = tuple(set(d.get_label()))
        if d_set in d_grp:
            d_grp[d_set].append(d)
        else:
            d_grp[d_set]=[d]
    result='Yes'
    for d_list in d_grp.values():
        for dx, dy in itertools.combinations(d_list,2):
            if cmp_dice(dx,dy):
                result='No'
                break
    print(result)

Submission status: Accepted

Solution code:
import sys
import math

def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S

def float_to_str(num):
    return str("{:.10f}".format(num))

def list_input(tp):
    return map(tp, str_input().split())

# # # # # # # # # # # # # # # # # # # # # # # # #

class Dice:
    pip = [0 for i in xrange(6)]

    def __init__(self, arg):
        self.pip = arg

    def rollDir(self, dr):
        nextPip = [0 for i in xrange(6)]
        if dr == "N":
            nextPip[0] = self.pip[1]
            nextPip[1] = self.pip[5]
            nextPip[2] = self.pip[2]
            nextPip[3] = self.pip[3]
            nextPip[4] = self.pip[0]
            nextPip[5] = self.pip[4]
        elif dr == "E":
            nextPip[0] = self.pip[3]
            nextPip[1] = self.pip[1]
            nextPip[2] = self.pip[0]
            nextPip[3] = self.pip[5]
            nextPip[4] = self.pip[4]
            nextPip[5] = self.pip[2]
        self.pip = nextPip

    def roll(self, dr):
        if dr == "N" or dr == "E":
            self.rollDir(dr)
        elif dr == "S":
            self.rollDir("N")
            self.rollDir("N")
            self.rollDir("N")
        elif dr == "W":
            self.rollDir("E")
            self.rollDir("E")
            self.rollDir("E")

    def check(self, a, b):
        while self.pip[0] != a:
            if self.pip[2] != a and self.pip[3] != a:
                self.roll("N")
            else:
                self.roll("N")
                self.roll("W")
                self.roll("S")

        while self.pip[1] != b:
            self.roll("N")
            self.roll("W")
            self.roll("S")
        return self.pip[2]

def sameCheck(dice1, dice2):
    for i in xrange(4):
        for j in xrange(4):
            if dice1.pip == dice2.pip:
                return True
            dice2.roll("E")
        dice2.roll("N")
    dice2.roll("N")
    dice2.roll("E")
    dice2.roll("S")
    for i in xrange(4):
        if dice1.pip == dice2.pip:
            return True
        dice2.roll("E")
    dice2.roll("N")
    dice2.roll("E")
    dice2.roll("E")
    dice2.roll("S")
    for i in xrange(4):
        if dice1.pip == dice2.pip:
            return True
        dice2.roll("E")
    return False

n = input()
dice = []

for i in xrange(n):
    tmp_dice = Dice(list_input(int))
    dice.append(tmp_dice)

for i in xrange(n):
    for j in xrange(i+1, n):
        if sameCheck(dice[i], dice[j]):
            print "No"
            sys.exit()

print "Yes"

Submission status: Accepted

Solution code:
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
 
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
 
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
 
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]

    def compare(self, label):
        for op in 'EEENEEENEEESEEESEEENEEEN':
            if self.get_label() == label:
                return True
            self.roll(op)
        else:
            return False
  
if __name__=='__main__':
    n = int(input())
    L = []
    for i in range(n):
        label = list(map(int,input().split()))
        for d in L:
            if d.compare(label): break
        else:
            L.append(dice(label))
            continue
        print('No')
        break
    else:
        print('Yes')

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,pips):
        self.top = pips[0]
        self.south = pips[1]
        self.east = pips[2]
        self.west = pips[3]
        self.north =pips[4]
        self.bottom=pips[5]
    def n(self):
        self.top,self.south,self.bottom,self.north = \
        self.south,self.bottom,self.north,self.top
    def s(self):
        self.top,self.north,self.bottom,self.south = \
        self.north,self.bottom,self.south,self.top
    def e(self):
        self.top,self.west,self.bottom,self.east = \
        self.west,self.bottom,self.east,self.top
    def w(self):
        self.top,self.east,self.bottom,self.west = \
        self.east,self.bottom,self.west,self.top
    def r(self):
        self.north,self.east,self.south,self.west = \
        self.east,self.south,self.west,self.north
    def set_ts(self,t,s):
        for i in range(4):
            if self.top != t:
                if self.east == t or self.west == t:
                    self.e()
                else:
                    self.n()
            else:
                break
        for i in range(4):
            if self.south != s:
                self.r()
            else:
                break
        if(self.top == t and self.south == s):
            return True
        else:
            return False
    def gen_pattern(self):
        pat = []
        for i in range(6):
            if i < 4:
                self.n()
            elif i == 4:
                self.e()
            elif i == 5:
                self.e()
                self.e()
            for j in range(4):
                self.r()
                pat.append([self.top,self.north,self.south,self.east,self.west,self.bottom])

        return pat


n = int(input())
dices = []
pat = []
for i in range(n):
    pips = [int(x) for x in input().split()]
    dices.append(Dice(pips))
    pat.append(sorted(dices[i].gen_pattern()))
pat_uniq = []
for x in pat:
    if x not in pat_uniq:
        pat_uniq.append(x)

if len(pat) == len(pat_uniq):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import itertools
class Dice:
    def __init__(self, labels):
        self.labels = labels
        self.up = labels[0]
        self.front = labels[1]
        self.right = labels[2]
        self.left = labels[3]
        self.back = labels[4]
        self.down = labels[5]
    def east(self):
        self.up, self.right, self.down, self.left = self.left, self.up, self.right, self.down
        self.update_labels()
    def north(self):
        self.up, self.back, self.down, self.front = self.front, self.up, self.back, self.down
        self.update_labels()
    def south(self):
        self.up, self.front, self.down, self.back = self.back, self.up, self.front, self.down
        self.update_labels()
    def west(self):
        self.up, self.left, self.down, self.right = self.right, self.up, self.left, self.down
        self.update_labels()
    def clockwise(self):
        self.front, self.left, self.back, self.right = self.right, self.front, self.left, self.back
        self.update_labels()
    def counterclockwise(self):
        self.front, self.right, self.back, self.left = self.left, self.front, self.right, self.back
        self.update_labels()
    def set_up(self, up):
        for i in range(6):
            if up == self.up:
                break
            if i % 2:
                self.east()
            else:
                self.north()
    def set_front(self, front):
        while True:
            if front == self.front:
                break
            self.clockwise()
    def update_labels(self):
        self.labels = [self.up, self.front, self.right, self.left, self.back, self.down]

def is_the_same(d1, d2):
    for i in range(30):
        if d1.labels == d2.labels:
            return True
        if i % 5 == 0:
            if i % 10 == 0:
                d2.east()
            else:
                d2.north()
        else:
            d2.clockwise()
    else:
        return False

n = int(input())
dices = []
for _ in range(n):
    dices.append(Dice(list(map(int, input().split()))))
for d in itertools.combinations(dices, 2):
    if is_the_same(d[0], d[1]):
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
class Dice():

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

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def rotate(self):
        self.change([1, 4, 2, 5, 3, 6])

    def change(self, convert):
        num = []
        for i in range(6):
            num.append(self.label[convert[i] - 1])
        self.label = num

    def is_same_dice(self, another_dice):
        for i in range(6):
            if i % 2 == 0:
                self.north()
            else:
                self.west()
            for j in range(4):
                self.rotate()
                if self.label == another_dice:
                    return True
        return False


def main():
    dices = []
    n = int(input())
    for i in range(n):
        dices.append(Dice([int(x) for x in input().split()]))

    flag = False
    for i in range(n):
        j = i + 1
        while j < n:
            if dices[i].is_same_dice(dices[j].label):
                flag = True
                break
            j += 1

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def N(Dice):
    num=Dice[0]
    Dice[0]=Dice[1]
    Dice[1]=Dice[5]
    Dice[5]=Dice[4]
    Dice[4]=num
def E(Dice):
    num=Dice[0]
    Dice[0]=Dice[3]
    Dice[3]=Dice[5]
    Dice[5]=Dice[2]
    Dice[2]=num
def W(Dice):
    num=Dice[0]
    Dice[0]=Dice[2]
    Dice[2]=Dice[5]
    Dice[5]=Dice[3]
    Dice[3]=num
def S(Dice):
    num=Dice[0]
    Dice[0]=Dice[4]
    Dice[4]=Dice[5]
    Dice[5]=Dice[1]
    Dice[1]=num
def DICE(Dice,Dice2):
    if (Dice[0] in Dice2)==False:
        """print('No')"""
        return 0
    else:
        for j in range(6):
            if j%2==0:
                N(Dice2)
            else:
                W(Dice2)
            for i in range(4):
                N(Dice2)
                W(Dice2)
                S(Dice2)
                if Dice==Dice2:
                    break
            if Dice==Dice2:
                break
    if Dice==Dice2:
        """print('Yes')"""
        return 1
    else:
        """print('No')"""
        return 0
cnt=0             
a=int(input())
Dice=[i for i in range(a)]
for i in range(a):
     Dice[i]=[int(i) for i in input().split()]
for i in range(a-1):
    for j in range(i+1,a):
        cnt+=DICE(Dice[i],Dice[j])
if cnt==0:
    print("Yes")
else:
    print("No")