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:
class Dice(object):
    def __init__(self,num):
        self.f=num[0]
        self.s=num[1]
        self.e=num[2]
        self.w=num[3]
        self.n=num[4]
        self.b=num[5]
    def create(self,order):
        if order=='N':
            return [self.s,self.b,self.e,self.w,self.f,self.n]
        elif order=='S':
            return [self.n,self.f,self.e,self.w,self.b,self.s]
        elif order=='E':
            return [self.w,self.s,self.f,self.b,self.n,self.e]
        else:
            return [self.e,self.s,self.b,self.f,self.n,self.w]
    def judge(self,dice_2):
        T={0:'N',1:'E',2:'S',3:'W'}
        m=[dice_2.s,dice_2.w,dice_2.n,dice_2.e,dice_2.f,dice_2.b]
        for i in range(6):
            if m[i]==self.f:#?????¢??¨?????´???????????????????????????
                if i==4:temp=dice_2#?????¢??????????????´
                elif i==5:temp=Dice(Dice(dice_2.create('N')).create('N'))#?????¢??¨?????´
                else:temp=Dice(dice_2.create(T[i]))#??´??¢??¨?????´

                if self.b==temp.b:
                        side_1=''.join(list(map(str,[self.s,self.w,self.n,self.e])))*2
                        side_2=''.join(list(map(str,[temp.s,temp.w,temp.n,temp.e])))
                        if side_2 in side_1:return 'accordance'
        return 'discordance'
    @staticmethod
    def isdifferent(dices):
        for i in range(len(dices)):
            for j in range(i+1,len(dices)):
                if dices[i].judge(dices[j])=='accordance':return 'No'
        return 'Yes'

n=eval(input())
dices=[]
for i in range(n):
    dices.append(Dice(list(map(int,input().split()))))
print(Dice.isdifferent(dices))

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, init_values = ['1','2','3','4','5','6']):
        self.value = dict(zip(["top", "front","right","left","back","bottom"]\
                             , init_values))

    #north, south, east and west
    def roll(self, direction):
        if direction == 'N':
            self.value["top"], self.value["front"], self.value["bottom"], self.value["back"] = \
            self.value["front"], self.value["bottom"], self.value["back"], self.value["top"]
        elif direction == 'S':
            self.value["top"], self.value["back"], self.value["bottom"], self.value["front"] = \
            self.value["back"], self.value["bottom"], self.value["front"], self.value["top"]
        elif direction == 'E':
            self.value["top"], self.value["left"], self.value["bottom"], self.value["right"] = \
            self.value["left"], self.value["bottom"], self.value["right"], self.value["top"]
        elif direction == 'W':
            self.value["top"], self.value["right"], self.value["bottom"], self.value["left"] = \
            self.value["right"], self.value["bottom"], self.value["left"], self.value["top"]
        else:
            print("Error: illegal format.")

    # clockwise, counterclockwise
    def spin(self, direction):
        if direction == "CW":
            self.value["front"], self.value["right"], self.value["back"], self.value["left"] = \
            self.value["right"], self.value["back"], self.value["left"], self.value["front"]
        elif direction == "CCW":
            self.value["front"], self.value["left"], self.value["back"], self.value["right"] = \
            self.value["left"], self.value["back"], self.value["right"], self.value["front"]
        else:
            print("Error: illegal format.")

    def is_same(self, other_dice):
        for direction in 'SESESE':
            other_dice.roll(direction)
            if self.value["top"] == other_dice.value["top"]:
                for j in range(4):
                    other_dice.spin("CW")
                    if self.value == other_dice.value:
                        return True
        return False

n = int(input())
dice_arr = []
for i in range(n):
    dice_arr.append(Dice(input().split()))

result = "Yes"
for i in range(len(dice_arr)-1):
    for j in range(i+1,len(dice_arr)):
        if dice_arr[i].is_same(dice_arr[j]):
            result = "No"
            break
    if result == "No":
        break

print(result)

Submission status: Accepted

Solution code:

class Dice:
    def __init__(self, label):
        self.d = label

    def roll(self, direction):
        if direction == "N":
            self.d[0], self.d[1], self.d[5], self.d[4] = self.d[1], self.d[5], self.d[4], self.d[0]
        elif direction == "S":
            self.d[0], self.d[1], self.d[5], self.d[4] = self.d[4], self.d[0], self.d[1], self.d[5]
        elif direction == "E":
            self.d[0], self.d[2], self.d[5], self.d[3] = self.d[3], self.d[0], self.d[2], self.d[5]
        elif direction == "W":
            self.d[0], self.d[2], self.d[5], self.d[3] = self.d[2], self.d[5], self.d[3], self.d[0]
        else:
            pass

n = int(input())

# ??¨????????¶???????¶??????§????????????
cmd = "N" * 4 + ("W" + "N" * 4) * 3 + "NE" + "N" * 4 + "EE" + "N" * 4 

labels = []

for i in range(n):
    labels.append([int(j) for j in input().split()])

for i in range(n):
    flag = False

    for j in range(i + 1, n):
        label1 = labels[i]
        label2 = labels[j]

        dice1 = Dice(label1)
        dice2 = Dice(label2)

        for op in cmd:
            dice2.roll(op)

            if dice1.d == dice2.d:
                flag = True
                break

        if flag:
            break

    if flag:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self,num):
        self.n = num[4]
        self.e = num[2]
        self.w = num[3]
        self.s = num[1]
        self.center = num[0]
        self.back = num[5]

    def number(self):
        number = [self.center, self.s, self.e, self.w, self.n, self.back]
        return number

    def move(self,str):
        if str == 'N':
            x = self.n
            self.n = self.center
            self.center = self.s
            self.s = self.back
            self.back = x
            return self.center
        elif str == 'S':
            x = self.s
            self.s = self.center
            self.center = self.n
            self.n = self.back
            self.back = x
            return self.center
        elif str== 'E':
            x = self.e
            self.e = self.center
            self.center = self.w
            self.w = self.back
            self.back = x
            return self.center
        elif str == 'W':
            x = self.w
            self.w = self.center
            self.center = self.e
            self.e = self.back
            self.back = x
            return self.center


n = int(input())
dice = []
for i in range(n):
    dice.append([int(j) for j in input().split()])

bool = False
d = []


for dice1 in range(len(dice)-1):
    d1 = Dice(dice[dice1])
    for dice2 in range(len(dice)-1-dice1):
        d2 = Dice(dice[dice2+dice1+1])
        for i in range(4):
            for j in range(4):
                for k in range(4):
                    # print(d1.number(), d2.number())
                    if d1.number() == d2.number():
                        bool = True
                    else:
                        d1.move('N')
                        d1.move('E')
                        d1.move('S')
                d1.move('E')
            d1.move('N')

print('Yes') if bool == False else print('No')

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, men):
        self.men = men[:]

    def throw(self, direction):
        if direction == "E":
            pmen = self.men[:]
            self.men[0] = pmen[3]
            self.men[1] = pmen[1]
            self.men[2] = pmen[0]
            self.men[3] = pmen[5]
            self.men[4] = pmen[4]
            self.men[5] = pmen[2]
        elif direction == "W":
            pmen = self.men[:]
            self.men[0] = pmen[2]
            self.men[1] = pmen[1]
            self.men[2] = pmen[5]
            self.men[3] = pmen[0]
            self.men[4] = pmen[4]
            self.men[5] = pmen[3]
        elif direction == "S":
            pmen = self.men[:]
            self.men[0] = pmen[4]
            self.men[1] = pmen[0]
            self.men[2] = pmen[2]
            self.men[3] = pmen[3]
            self.men[4] = pmen[5]
            self.men[5] = pmen[1]
        elif direction == "N":
            pmen = self.men[:]
            self.men[0] = pmen[1]
            self.men[1] = pmen[5]
            self.men[2] = pmen[2]
            self.men[3] = pmen[3]
            self.men[4] = pmen[0]
            self.men[5] = pmen[4]
        elif direction == "C":
            pmen = self.men[:]
            self.men[0] = pmen[0]
            self.men[1] = pmen[2]
            self.men[2] = pmen[4]
            self.men[3] = pmen[1]
            self.men[4] = pmen[3]
            self.men[5] = pmen[5]
        elif direction == "U":
            pmen = self.men[:]
            self.men[0] = pmen[0]
            self.men[1] = pmen[3]
            self.men[2] = pmen[1]
            self.men[3] = pmen[4]
            self.men[4] = pmen[2]
            self.men[5] = pmen[5]

n = int(raw_input())
mens = []
for i in range(n):
    men = map(int,(raw_input()).split(" "))
    mens.append(men)

flag = False

for p in range(n-1):
    for q in range(p+1, n):
        d1 = Dice(mens[p][:])
        d2 = Dice(mens[q][:])

        for i in range(4):
            d1.throw("W")
            for j in range(4):
                d1.throw("S")
                if d1.men == d2.men:
                    flag = True

        for i in range(4):
            d1.throw("C")
            for j in range(4):
                d1.throw("S")
                if d1.men == d2.men:
                    flag = True
if flag:
    print "No"
else:
    print "Yes"

Submission status: Accepted

Solution code:
class Dice:

    __top = 0
    __front = 1
    __right = 2
    __left = 3
    __back = 4
    __bottom = 5

    def __init__(self, a, b, c, d, e, f):
        self.__dice = [a,b,c,d,e,f]

    def S(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__back]
        self.__dice[Dice.__front]  = dice_before[Dice.__top]
        self.__dice[Dice.__right]  = dice_before[Dice.__right]
        self.__dice[Dice.__left]   = dice_before[Dice.__left]
        self.__dice[Dice.__back]   = dice_before[Dice.__bottom]
        self.__dice[Dice.__bottom] = dice_before[Dice.__front]

    def E(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__left]
        self.__dice[Dice.__front]  = dice_before[Dice.__front]
        self.__dice[Dice.__right]  = dice_before[Dice.__top]
        self.__dice[Dice.__left]   = dice_before[Dice.__bottom]
        self.__dice[Dice.__back]   = dice_before[Dice.__back]
        self.__dice[Dice.__bottom] = dice_before[Dice.__right]

    def W(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__right]
        self.__dice[Dice.__front]  = dice_before[Dice.__front]
        self.__dice[Dice.__right]  = dice_before[Dice.__bottom]
        self.__dice[Dice.__left]   = dice_before[Dice.__top]
        self.__dice[Dice.__back]   = dice_before[Dice.__back]
        self.__dice[Dice.__bottom] = dice_before[Dice.__left]

    def N(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__front]
        self.__dice[Dice.__front]  = dice_before[Dice.__bottom]
        self.__dice[Dice.__right]  = dice_before[Dice.__right]
        self.__dice[Dice.__left]   = dice_before[Dice.__left]
        self.__dice[Dice.__back]   = dice_before[Dice.__top]
        self.__dice[Dice.__bottom] = dice_before[Dice.__back]

    def turn(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__top]
        self.__dice[Dice.__front]  = dice_before[Dice.__right]
        self.__dice[Dice.__right]  = dice_before[Dice.__back]
        self.__dice[Dice.__left]   = dice_before[Dice.__front]
        self.__dice[Dice.__back]   = dice_before[Dice.__left]
        self.__dice[Dice.__bottom] = dice_before[Dice.__bottom]

    def top(self):
        return(self.__dice[Dice.__top])

    def front(self):
        return(self.__dice[Dice.__front])

    def right(self):
        return(self.__dice[Dice.__right])

    def left(self):
        return(self.__dice[Dice.__left])

    def back(self):
        return(self.__dice[Dice.__back])

    def bottom(self):
        return(self.__dice[Dice.__bottom])

    def compare(self, dice):
        if (self.__dice[Dice.__top]    == dice.__dice[Dice.__top] and
            self.__dice[Dice.__front]  == dice.__dice[Dice.__front] and
            self.__dice[Dice.__right]  == dice.__dice[Dice.__right] and
            self.__dice[Dice.__left]   == dice.__dice[Dice.__left] and
            self.__dice[Dice.__back]   == dice.__dice[Dice.__back] and
            self.__dice[Dice.__bottom] == dice.__dice[Dice.__bottom]):
            return("Match")
        else:
            return("Unmatch")

    def print(self):
        print('[top   ] :', self.__dice[Dice.__top])
        print('[front ] :', self.__dice[Dice.__front])
        print('[right ] :', self.__dice[Dice.__right])
        print('[left  ] :', self.__dice[Dice.__left])
        print('[back  ] :', self.__dice[Dice.__back])
        print('[bottom] :', self.__dice[Dice.__bottom])


def S(dice, top):
    for t in range(4):
        if dice.top() == top:
            return dice
        dice.S()
    return dice

def turn(dice, front):
    for t in range(4):
        if dice.front() == front:
            return dice
        dice.turn()
    return dice


n = int(input())
dice = []

a, b, c, d, e, f = input().split()
top = max(a,b,c,d,e,f)
dice1 = Dice(a, b, c, d, e, f)
dice1 = S(dice1, top)

for i in range(n - 1):
    a, b, c, d, e, f = input().split()
    dice.append(Dice(a, b, c, d, e, f))

for i in range(len(dice)):
    for to in range(2):
        dice[i] = S(dice[i], top)
        if dice[i].top() == top:
            break
        else:
            dice[i].turn()

    front = dice1.front()
    for fr in range(4):
        dice[i] = turn(dice[i], front)
        if dice[i].front() == front:
            break

    if (dice1.compare(dice[i]) == 'Match'):
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
def move(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(dice_1):
    dice = {dice_1}
    while True:
        dice2 = {move(d,r) for d in dice for r in list("NEWS")}.union(dice)
        if dice == dice2: break
        dice = dice2
    return dice    


n = int(input())
count = 0
dice = [0 for i in range(n)]


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

for i in range(n):
    for k in range(i):
        if count == 1: break
        if dice[i] in gen_all(dice[k]):
            print("No")
            count = 1
            break
if count == 0:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

def rot(dice,rotation):
    if rotation == "E":
        dice = (dice[3],dice[1],dice[0],dice[5],dice[4],dice[2])
    elif rotation == "W":
        dice = (dice[2],dice[1],dice[5],dice[0],dice[4],dice[3])
    elif rotation == "N":
        dice = (dice[1],dice[5],dice[2],dice[3],dice[0],dice[4])
    elif rotation == "S":
        dice = (dice[4],dice[0],dice[2],dice[3],dice[5],dice[1])
    return dice

def make_all_pattern(dice):
    pattern = {dice}
    pattern2 = pattern
    while True:
        pattern2 = pattern.union({rot(d,r) for d in pattern for r in list("NEWS")})
        if pattern2 == pattern:
            break
        pattern = pattern2
    return pattern

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


pattern = set()
for i in range(n-1):
    pattern = pattern.union(make_all_pattern(dice[i]))
    if dice[i+1] in pattern:
        print("No")
        break

else:
    print("Yes")

Submission status: Accepted

Solution code:
#!usr/bin/env python3

import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
            del tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
            del tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
            del tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp
            del tmp

    def spin_die_clockwise(self):
        tmp = self.pips[1]
        self.pips[1] = self.pips[2]
        self.pips[2] = self.pips[4]
        self.pips[4] = self.pips[3]
        self.pips[3] = tmp
        del tmp


def init_die():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)

    return die


def roll_die(die):
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    return die


def question_rightside(die):
    q = int(sys.stdin.readline().strip('\n'))

    for question in range(q):
        q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]

        if q_pips[0] == die.pips[1]:
            die.move_die('N')
        elif q_pips[0] == die.pips[2]:
            die.move_die('W')
        elif q_pips[0] == die.pips[3]:
            die.move_die('E')
        elif q_pips[0] == die.pips[4]:
            die.move_die('S')
        elif q_pips[0] == die.pips[5]:
            die.move_die('N')
            die.move_die('N')

        while die.pips[1] != q_pips[1]:
            die.spin_die_clockwise()

        print(die.pips[2])


def are_identical(die1, die2):
    if sorted(die1.pips) != sorted(die2.pips):
        return 'No'
    else:
        for idx, pip in enumerate(die2.pips):
            for spin in range(4):
                if die1.pips == die2.pips:
                    return 'Yes'
                else:
                    die1.spin_die_clockwise()
            if idx in {0, 1, 2}:
                die1.move_die('N')
            if idx in {3}:
                die1.move_die('N')
                die1.move_die('E')
            if idx in {4}:
                die1.move_die('E')
                die1.move_die('E')

        return 'No'


def main():
    n = int(sys.stdin.readline().strip('\n'))
    dice = [Die([int(pip) for pip in sys.stdin.readline().strip('\n').split()])
            for _ in range(n)]

    not_identical_count = 0

    if len(dice) != 2:
        num_of_all_not_identical = len(dice) * (len(dice)-1)
    else:
        num_of_all_not_identical = 2

    for idx_base, die_base in enumerate(dice):
        for idx_compared, die_compared in enumerate(dice):
            if idx_base != idx_compared:
                if are_identical(die_base, die_compared) == 'No':
                    not_identical_count += 1

    if not_identical_count != num_of_all_not_identical:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3

import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
            del tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
            del tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
            del tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp
            del tmp

    def spin_die_clockwise(self):
        tmp = self.pips[1]
        self.pips[1] = self.pips[2]
        self.pips[2] = self.pips[4]
        self.pips[4] = self.pips[3]
        self.pips[3] = tmp
        del tmp


def init_die():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)

    return die


def roll_die(die):
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    return die


def question_rightside(die):
    q = int(sys.stdin.readline().strip('\n'))

    for question in range(q):
        q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]

        if q_pips[0] == die.pips[1]:
            die.move_die('N')
        elif q_pips[0] == die.pips[2]:
            die.move_die('W')
        elif q_pips[0] == die.pips[3]:
            die.move_die('E')
        elif q_pips[0] == die.pips[4]:
            die.move_die('S')
        elif q_pips[0] == die.pips[5]:
            die.move_die('N')
            die.move_die('N')

        while die.pips[1] != q_pips[1]:
            die.spin_die_clockwise()

        print(die.pips[2])


def are_identical(die1, die2):
    if sorted(die1.pips) != sorted(die2.pips):
        return 'No'
    else:
        for idx, pip in enumerate(die2.pips):
            for spin in range(4):
                if die1.pips == die2.pips:
                    return 'Yes'
                else:
                    die1.spin_die_clockwise()
            if idx in {0, 1, 2}:
                die1.move_die('N')
            if idx in {3}:
                die1.move_die('N')
                die1.move_die('E')
            if idx in {4}:
                die1.move_die('E')
                die1.move_die('E')

        return 'No'


def check_all_dice_not_identical():
    n = int(sys.stdin.readline().strip('\n'))
    dice = [Die([int(pip) for pip in sys.stdin.readline().strip('\n').split()])
            for _ in range(n)]

    not_identical_count = 0

    if len(dice) != 2:
        num_of_all_not_identical = len(dice) * (len(dice)-1)
    else:
        num_of_all_not_identical = 2

    for idx_base, die_base in enumerate(dice):
        for idx_compared, die_compared in enumerate(dice):
            if idx_base != idx_compared:
                if are_identical(die_base, die_compared) == 'No':
                    not_identical_count += 1

    if not_identical_count != num_of_all_not_identical:
        return 'No'
    else:
        return 'Yes'


def main():
    print(check_all_dice_not_identical())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3

import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
            del tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
            del tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
            del tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp
            del tmp

    def spin_die_clockwise(self):
        tmp = self.pips[1]
        self.pips[1] = self.pips[2]
        self.pips[2] = self.pips[4]
        self.pips[4] = self.pips[3]
        self.pips[3] = tmp
        del tmp


def init_die():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)

    return die


def roll_die(die):
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    return die


def question_rightside(die):
    q = int(sys.stdin.readline().strip('\n'))

    for question in range(q):
        q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]

        if q_pips[0] == die.pips[1]:
            die.move_die('N')
        elif q_pips[0] == die.pips[2]:
            die.move_die('W')
        elif q_pips[0] == die.pips[3]:
            die.move_die('E')
        elif q_pips[0] == die.pips[4]:
            die.move_die('S')
        elif q_pips[0] == die.pips[5]:
            die.move_die('N')
            die.move_die('N')

        while die.pips[1] != q_pips[1]:
            die.spin_die_clockwise()

        print(die.pips[2])


def are_identical(die1, die2):
    if sorted(die1.pips) != sorted(die2.pips):
        return 'No'
    else:
        for idx, pip in enumerate(die2.pips):
            for spin in range(4):
                if die1.pips == die2.pips:
                    return 'Yes'
                else:
                    die1.spin_die_clockwise()
            if idx in {0, 1, 2}:
                die1.move_die('N')
            if idx in {3}:
                die1.move_die('N')
                die1.move_die('E')
            if idx in {4}:
                die1.move_die('E')
                die1.move_die('E')

        return 'No'


def check_all_dice_not_identical():
    n = int(sys.stdin.readline().strip('\n'))
    dice = [init_die() for _ in range(n)]

    not_identical_count = 0

    if len(dice) != 2:
        num_of_all_not_identical = len(dice) * (len(dice)-1)
    else:
        num_of_all_not_identical = 2

    for idx_base, die_base in enumerate(dice):
        for idx_compared, die_compared in enumerate(dice):
            if idx_base != idx_compared:
                if are_identical(die_base, die_compared) == 'No':
                    not_identical_count += 1

    if not_identical_count != num_of_all_not_identical:
        return 'No'
    else:
        return 'Yes'


def main():
    print(check_all_dice_not_identical())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
class Dice():
	__S1 = 'NNNNENNNNENNNNENNNNrNNNNllNNNN'
	__leng = len(__S1)
	
	def __init__(self, label):
		self.d = label
		
	def __eq__(self, other):
		for j in range(self.__leng):
			if self.pmatch(other):
					return True
					break
			other.roll(self.__S1[j])
		else:
			return False
	
	def __ne__(self, other):
		return not self == other
		
	def pmatch(self, other):
		if (self.d[1] != other.d[1] or self.d[2] != other.d[2] or self.d[3] != other.d[3] or self.d[4] != other.d[4] or self.d[5] != other.d[5] or self.d[6] != other.d[6]):
			return False
		else:
			return True
	
	def roll(self, drt):
		if drt == 'N':
			self.d[1], self.d[2], self.d[6], self.d[5] = self.d[2], self.d[6], self.d[5], self.d[1]
		elif drt == 'E':
			self.d[1], self.d[3], self.d[6], self.d[4] = self.d[4], self.d[1], self.d[3], self.d[6]
		elif drt == 'S':
			self.d[2], self.d[6], self.d[5], self.d[1] = self.d[1], self.d[2], self.d[6], self.d[5]
		elif drt == 'W':
			self.d[4], self.d[1], self.d[3], self.d[6] = self.d[1], self.d[3], self.d[6], self.d[4]
		elif drt == 'r':
			self.d[2], self.d[3], self.d[5], self.d[4] = self.d[4], self.d[2], self.d[3], self.d[5]
		elif drt == 'l':
			self.d[4], self.d[2], self.d[3], self.d[5] = self.d[2], self.d[3], self.d[5], self.d[4]
	
	def printl(self, lct):
		print(self.d[lct])

N = int(input())
a = [0 for i in range(N)]
for i in range(N):
	b = [0]
	b.extend(list(map(int, input().split())))
	a[i] = Dice(b)

for i in range(N):
	for j in range(i+1,N):
		if a[i] == a[j]:
			print("No")
			break
	else:
		continue
	break
else:
	print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
M = []
for i in range(n):
    a = [int(j) for j in input().split()]
    M.append(a)
t = 0
    
for i in range(n):
    for j in range(i+1,n):
        A,B,C,D,E,F = tuple(M[i])
        u,v,w,x,y,z = tuple(M[j])
        s = 0
        for _ in range(3):
            for _ in range(4):
                if A == u and B == v and C == w and D == x and E == y and F == z:
                    s = 1
                    break
                A,B,C,D,E,F = A,C,E,B,D,F #R
            A,B,C,D,E,F = D,B,A,F,E,C #E
            for _ in range(4):
                if A == u and B == v and C == w and D == x and E == y and F == z:
                    s = 1
                    break
                A,B,C,D,E,F = A,C,E,B,D,F #R
            A,B,C,D,E,F = B,F,C,D,A,E #N

        if s != 0:
            t = 1
            
if t == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
class dice:
    def __init__(self, pip):
        self.pip = pip
        
    def move(self,dir):
        if str(dir) == "E":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[3],self.pip[0],self.pip[5],self.pip[2]
        elif str(dir) == "W":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[2],self.pip[5],self.pip[0],self.pip[3]
        elif str(dir) == "N":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[1],self.pip[5],self.pip[0],self.pip[4]
        elif str(dir) == "S":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[4],self.pip[0],self.pip[5],self.pip[1]

n = int(input())
ans = "Yes"
ds =[]

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

for i in range(len(ds)-1):
    for j in range(i+1,len(ds)):
        d_tmp = dice(ds[j].pip)
        for op in "EEENEEENEEESEEESEEENEEEN":
            if ds[i].pip == d_tmp.pip:
                ans = "No"
                break
            d_tmp.move(op)

print(ans)