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:
    def __init__(self,num):
        self.num = num.copy()
        
    def east(self):
        temp = self.num.copy()
        self.num[1-1] = temp[4-1]
        self.num[4-1] = temp[6-1]
        self.num[6-1] = temp[3-1]
        self.num[3-1] = temp[1-1]

    def north(self):
        temp = self.num.copy()
        self.num[1-1] = temp[2-1]
        self.num[2-1] = temp[6-1]
        self.num[6-1] = temp[5-1]
        self.num[5-1] = temp[1-1]

    def south(self):
        temp = self.num.copy()
        self.num[1-1] = temp[5-1]
        self.num[5-1] = temp[6-1]
        self.num[6-1] = temp[2-1]
        self.num[2-1] = temp[1-1]

    def west(self):
        temp = self.num.copy()
        self.num[1-1] = temp[3-1]
        self.num[3-1] = temp[6-1]
        self.num[6-1] = temp[4-1]
        self.num[4-1] = temp[1-1]

    def right(self):
        temp = self.num.copy()
        self.num[2-1] = temp[4-1]
        self.num[4-1] = temp[5-1]
        self.num[5-1] = temp[3-1]
        self.num[3-1] = temp[2-1]

    def same(self,dice):
        for _ in range(20):
            self.north()
            for _ in range(20):
                self.east()
                for _ in range(20):
                    self.right()
                    if self.num == dice: return True
        return False

diff = True
n = int(input())
dices = []
for _ in range(n):  dices.append(Dice(list(map(int,input().split()))))
for i in dices[1:]: diff = diff and not(dices[0].same(i.num))
if diff: print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
d=[(0,0,1),(-1,0,0),(0,1,0),(0,-1,0),(1,0,0),(0,0,-1)]
def crosspro(y,x):
    return (y[1]*x[2]-y[2]*x[1],y[2]*x[0]-y[0]*x[2],y[0]*x[1]-y[1]*x[0])
def north(r):
    res=[]
    for p in r:
        res.append((p[2],p[1],-p[0]))
    return res
def south(r):
    res=[]
    for p in r:
        res.append((-p[2],p[1],p[0]))
    return res
def east(r):
    res=[]
    for p in r:
        res.append((p[0],p[2],-p[1]))
    return res
def west(r):
    res=[]
    for p in r:
        res.append((p[0],-p[2],p[1]))
    return res
def left(r):
    res=[]
    for p in r:
        res.append((p[1],-p[0],p[2]))
    return res
def right(r):
    res=[]
    for p in r:
        res.append((-p[1],p[0],p[2]))
    return res
T=["","N","E","W","S","NN"]
U=["","L","LL","LLL"]
def change(S):
    D=d
    for i in S:
        if i=="N":
            D=north(D)
        elif i=="E":
            D=east(D)
        elif i=="W":
            D=west(D)
        elif i=="S":
            D=south(D)
        elif i=="L":
            D=left(D)
        else:
            D=right(D)
    return D
def same(c1,c2):
    for i in T:
        for j in U:
            D=change(i+j)
            flag=0
            for x in range(6):
                for y in range(6):
                    if d[x]==D[y]:
                        if c1[x]!=c2[y]:
                            flag=1
            if flag==0:
                return True
    return False
N=int(input())
c=[[int(i) for i in input().split()] for j in range(N)]
for i in range(N):
    for j in range(N):
        if i<j:
            if same(c[i],c[j]):
                print("No")
                exit()
print("Yes")

Submission status: Accepted

Solution code:
number = int(input())
dices = []
for i in range(number):
    dices.append(input().split())
    
tf = 0
for i in range(number - 1):
    for j in range(i + 1, number):
        
        dice_1 = dices[i]
        dice_2 = dices[j]
        rolls = {' ':[0, 1, 2, 3, 4, 5], 
                 'W':[2, 1, 5, 0, 4, 3], 
                 'N':[1, 5, 2, 3, 0, 4], 
                 'E':[3, 1, 0, 5, 4, 2], 
                 'S':[4, 0, 2, 3, 5, 1]
                }
        orders = [' ', 'N', 'W', 'E', 'S', 'NN']
        for order in orders:
            copy_2 = dice_2
            for d in order:
                roll = rolls[d]
                copy_2 = [copy_2[i] for i in roll]    
            l = [1, 2, 4, 3]
            a0 = copy_2[0] == dice_1[0]
            a1 = copy_2[5] == dice_1[5]
            a2 = ' '.join([copy_2[s]for s in l]) in ' '.join([dice_1[s]for s in l] * 2)
            if  a0 and a1 and a2:
                tf += 1
if tf > 0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys

from typing import List


class Dice:

    def __init__(self, values: List[int]):
        self.face_value = values

    def get_value(self, face_num) -> int:
        return self.face_value[face_num]

    def get_all_values(self) -> str:
        return ' '.join(map(str, self.face_value))

    def get_upper_value(self) -> int:
        return self.get_value(0)

    def invoke_method(self, mkey: str) -> None:
        if mkey == 'S':
            self.S()
        elif mkey == 'N':
            self.N()
        elif mkey == 'E':
            self.E()
        elif mkey == 'W':
            self.W()
        else:
            raise ValueError(f'This method does not exist. : {mkey}')

    def set_value(self, s0, s1, s2, s3, s4, s5) -> None:
        self.face_value[0] = s0
        self.face_value[1] = s1
        self.face_value[2] = s2
        self.face_value[3] = s3
        self.face_value[4] = s4
        self.face_value[5] = s5

    def S(self) -> None:
        self.set_value(self.face_value[4], self.face_value[0],
                       self.face_value[2], self.face_value[3],
                       self.face_value[5], self.face_value[1])

    def N(self) -> None:
        self.set_value(self.face_value[1], self.face_value[5],
                       self.face_value[2], self.face_value[3],
                       self.face_value[0], self.face_value[4])

    def E(self) -> None:
        self.set_value(self.face_value[3], self.face_value[1],
                       self.face_value[0], self.face_value[5],
                       self.face_value[4], self.face_value[2])

    def W(self) -> None:
        self.set_value(self.face_value[2], self.face_value[1],
                       self.face_value[5], self.face_value[0],
                       self.face_value[4], self.face_value[3])

    def T(self) -> None:
        """横回転."""
        self.set_value(self.face_value[0], self.face_value[2],
                       self.face_value[4], self.face_value[1],
                       self.face_value[3], self.face_value[5])


def check_T(dice1, dice2) -> bool:
    """横回転させて一致したらTrueを返す."""
    for _i in range(4):
        dice1.T()
        if dice1.get_all_values() == dice2.get_all_values():
            return True
    return False


def is_same_dice(dice1, dice2) -> bool:
    for _i in range(4):
        dice1.S()
        if dice1.get_upper_value() == dice2.get_upper_value():
            if check_T(dice1, dice2):
                return True
    for _i in range(4):
        dice1.E()
        if dice1.get_upper_value() == dice2.get_upper_value():
            if check_T(dice1, dice2):
                return True
    return False


# 提出用1
N = int(input())
dices = [Dice([int(j) for j in input().split()]) for i in range(N)]

# # 提出用2
# dices = []
# for j in range(N):
#     dices.append(Dice([int(i) for i in input().split()]))

# # 動作確認用1
# dices = []
# with open('input_itp1_11_d_1.txt', mode='r', encoding='utf8') as fin:
#     N = int(next(fin))
#     for n in range(N):
#         dices.append(Dice([int(i) for i in next(fin).split()]))

# # 動作確認用2
# with open('input_itp1_11_d_1.txt', mode='r', encoding='utf8') as fin:
#     N = int(next(fin))
#     dices = [Dice([int(j) for j in next(fin).split()]) for i in range(N)]

# # debug表示
# for i in range(N):
#     print(dices[i].get_all_values())
#     for j in range(6):
#         print(dices[i].get_value(j))

for i in range(len(dices) - 1):
    for j in range(i + 1, len(dices)):
        if is_same_dice(dices[i], dices[j]):
            print('No')
            sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys

from typing import List


class Dice:

    def __init__(self, values: List[int]):
        self.face_value = values

    def get_value(self, face_num) -> int:
        return self.face_value[face_num]

    def get_all_values(self) -> str:
        return ' '.join(map(str, self.face_value))

    def get_upper_value(self) -> int:
        return self.get_value(0)

    def invoke_method(self, mkey: str) -> None:
        if mkey == 'S':
            self.S()
        elif mkey == 'N':
            self.N()
        elif mkey == 'E':
            self.E()
        elif mkey == 'W':
            self.W()
        else:
            raise ValueError(f'This method does not exist. : {mkey}')

    def set_value(self, s0, s1, s2, s3, s4, s5) -> None:
        self.face_value[0] = s0
        self.face_value[1] = s1
        self.face_value[2] = s2
        self.face_value[3] = s3
        self.face_value[4] = s4
        self.face_value[5] = s5

    def S(self) -> None:
        self.set_value(self.face_value[4], self.face_value[0],
                       self.face_value[2], self.face_value[3],
                       self.face_value[5], self.face_value[1])

    def N(self) -> None:
        self.set_value(self.face_value[1], self.face_value[5],
                       self.face_value[2], self.face_value[3],
                       self.face_value[0], self.face_value[4])

    def E(self) -> None:
        self.set_value(self.face_value[3], self.face_value[1],
                       self.face_value[0], self.face_value[5],
                       self.face_value[4], self.face_value[2])

    def W(self) -> None:
        self.set_value(self.face_value[2], self.face_value[1],
                       self.face_value[5], self.face_value[0],
                       self.face_value[4], self.face_value[3])

    def T(self) -> None:
        """横回転."""
        self.set_value(self.face_value[0], self.face_value[2],
                       self.face_value[4], self.face_value[1],
                       self.face_value[3], self.face_value[5])


def check_T(dice1, dice2) -> bool:
    """横回転させて一致したらTrueを返す."""
    for _i in range(4):
        dice1.T()
        if dice1.get_all_values() == dice2.get_all_values():
            return True
    return False


def is_same_dice(dice1, dice2) -> bool:
    for _i in range(4):
        dice1.S()
        if dice1.get_upper_value() == dice2.get_upper_value():
            if check_T(dice1, dice2):
                return True
    for _i in range(4):
        dice1.E()
        if dice1.get_upper_value() == dice2.get_upper_value():
            if check_T(dice1, dice2):
                return True
    return False


# 提出用1
N = int(input())
dices = [Dice([int(j) for j in input().split()]) for i in range(N)]

# # 動作確認用2
# with open('input_itp1_11_d_1.txt', mode='r', encoding='utf8') as fin:
#     N = int(next(fin))
#     dices = [Dice([int(j) for j in next(fin).split()]) for i in range(N)]

for i in range(len(dices) - 1):
    for j in range(i + 1, len(dices)):
        if is_same_dice(dices[i], dices[j]):
            print('No')
            sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
from copy import deepcopy
from itertools import groupby
import queue
import sys

class Dice:
    def __init__(self, nums):
        self.labels = [None] + [ nums[i] for i in range(6) ]
        self.pos = {
            "E" : 3,
            "W" : 4,
            "S" : 2,
            "N" : 5,
            "T" : 1,
            "B" : 6
        }

    def rolled(dice, queries):
        d = deepcopy(dice)
        for q in queries:
            if q == "E":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["W"], d.pos["T"], d.pos["E"], d.pos["B"]
            elif q == "W":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["E"], d.pos["B"], d.pos["W"], d.pos["T"]
            elif q == "S":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["N"], d.pos["T"], d.pos["S"], d.pos["B"]
            elif q == "N":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["S"], d.pos["B"], d.pos["N"], d.pos["T"]
        else:
            return d

    def isDiceSame(d1, d2):
        if not isinstance(d1, Dice) or not isinstance(d2, Dice):
            return False

        if set(d1.labels[1:]) != set(d2.labels[1:]):
            return False

        else:
            q = ["T", "S", "E", "N", "W", "B"]
            memo = [[False] * 7 for i in range(7)]
            memo[d1.pos["T"]][d1.pos["S"]] = ""
            res = {}
            for i in q[:3]:
                if d1.labels[d1.pos[i]] != d2.labels[d2.pos[i]]:
                    break
            else:
                res[memo[d1.pos["T"]][d1.pos["S"]]] = d1

            def bfs_isDiceSame():
                que = queue.Queue()
                que.put(d1)

                while not que.empty():
                    d = que.get()
                    for i in q[1:5]:
                        d_next = Dice.rolled(d, i)
                        if memo[d_next.pos["T"]][d_next.pos["S"]] == False:
                            que.put(d_next)
                            memo[d_next.pos["T"]][d_next.pos["S"]] = memo[d.pos["T"]][d.pos["S"]] + i
                            for j in q[:3]:
                                if d_next.labels[d_next.pos[j]] != d2.labels[d2.pos[j]]:
                                    break
                            else:
                                res[memo[d_next.pos["T"]][d_next.pos["S"]]] = d_next

            bfs_isDiceSame()
            if len(res) == 0:
                return False
            else:
                for k, v in res.items():
                    for i in q[3:]:
                        if v.labels[v.pos[i]] != d2.labels[d2.pos[i]]:
                            break
                    else:
                        return True
                else:
                    return False

n = int(sys.stdin.readline().rstrip())
d_nums = [tuple([int(x) for x in sys.stdin.readline().rstrip().split()]) for _ in range(n)]

if len(d_nums) != len(set(d_nums)):
    print("No")
else:
	
    def var(data):
        ava = sum(data)/len(data)
        return sum([(ava-data[i])**2 for i in range(len(data))])/len(data)

    d_nums.sort(key=lambda t: sum(t))
    d_nums.sort(key=lambda t: var(t))
    for (_, g) in groupby(d_nums, key=lambda t: var(t)):
        gl = list(g)
        if len(gl) == 1:
            continue
        else:
            for i in range(len(gl)):
                for j in range(i+1, len(gl)):
                    if Dice.isDiceSame(Dice(gl[i]), Dice(gl[j])):
                        print("No")
                        sys.exit()
    else:
        print("Yes")

Submission status: Accepted

Solution code:
class Dice:
  def make_dice(self, value):
    self.face = value
  def move(self, direc):
    if direc == "N":
      self.face = [self.face[1], self.face[5], self.face[2], self.face[3], self.face[0], self.face[4]]
      return self.face
    elif direc == "E":
      self.face = [self.face[3], self.face[1], self.face[0], self.face[5], self.face[4], self.face[2]]
      return self.face
    elif direc == "S":
      self.face = [self.face[4], self.face[0], self.face[2], self.face[3], self.face[5], self.face[1]]
      return self.face
    elif direc == "W":
      self.face = [self.face[2], self.face[1], self.face[5], self.face[0], self.face[4], self.face[3]]
      return self.face
  def check_face(self, face1):
    for i in range(4):
      if face1 == self.face:
        return self.face
      else:
        self.face[1],self.face[2],self.face[4],self.face[3] = self.face[2],self.face[4],self.face[3],self.face[1]

def comp_dices(dice1,dice2,num):
  for i in range(6):
    dice2.make_dice(num)
    if i == 0:
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 1:
      dice2.move("N")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 2:
      dice2.move("E")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 3:
      dice2.move("S")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 4:
      dice2.move("W")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
    elif i == 5:
      dice2.move("N")
      dice2.move("N")
      dice2.check_face(dice1.face)
      if dice1.face == dice2.face:
        return True
      else:
        return False

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

for i in range(n):
  for j in range(i+1,n):
    flag = comp_dices(dice[i],dice[j],num[j])
    if flag:
      break
  if flag:
    break

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

import random

class Dice:
    def __init__(self, top, s, e, w, n, bottom):
        self.top    = top
        self.s      = s
        self.e      = e
        self.w      = w
        self.n      = n
        self.bottom = bottom

    def rotate(self, dist):
        if dist == 'N':
            self.top, self.s, self.n, self.bottom = self.s, self.bottom, self.top, self.n 
        elif dist == 'S':
            self.s, self.bottom, self.top, self.n = self.top, self.s, self.n, self.bottom 
        elif dist == 'E':
            self.top, self.e, self.w, self.bottom = self.w, self.top, self.bottom, self.e 
        elif dist == 'W':
            self.w, self.top, self.bottom, self.e = self.top, self.e, self.w, self.bottom 

if __name__ == '__main__':
    random.seed(0)

    n = input()
    dice = [Dice(*map(int, raw_input().split())) for _ in range(n)]
    ref  = [set() for _ in range(n)]

    for _ in range(1000):
        if len(ref[0]) > 23:
            break

        dist = 'NEWS'[random.randint(0,3)]
        for i in range(n):
            ref[i].add((dice[i].top, dice[i].s, dice[i].e))
            dice[i].rotate(dist)
    
    print 'Yes' if len(set(map(str, ref))) == n else 'No'

Submission status: Accepted

Solution code:
n=0
for i in range(int(input())):
	if i==0:
		d1=list(map(int,input().split()))
	else:
		d2=list(map(int,input().split()))
			
		for i in range(4):
			d2[0],d2[1],d2[4],d2[5]=d2[1],d2[5],d2[0],d2[4]
			for i in range(4):
				d2[1],d2[3],d2[4],d2[2]=d2[3],d2[4],d2[2],d2[1]
				if d1[0]==d2[0] and d1[1]==d2[1] and d1[2]==d2[2] and d1[3]==d2[3] and d1[4]==d2[4] and d1[5]==d2[5]:
					n+=1
		for i in range(4):
			d2[0],d2[3],d2[5],d2[2]=d2[3],d2[5],d2[2],d2[0]
			for i in range(4):
				d2[1],d2[3],d2[4],d2[2]=d2[3],d2[4],d2[2],d2[1]
				if d1[0]==d2[0] and d1[1]==d2[1] and d1[2]==d2[2] and d1[3]==d2[3] and d1[4]==d2[4] and d1[5]==d2[5]:
					n+=1
if n==0:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
#
# itp1 11d
#
import random


class Cube:
    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 rotate(self, dic):
        if dic == "N":
            tmp = self.u
            self.u = self.s
            self.s = self.d
            self.d = self.n
            self.n = tmp
        elif dic == "E":
            tmp = self.u
            self.u = self.w
            self.w = self.d
            self.d = self.e
            self.e = tmp
        elif dic == "W":
            tmp = self.u
            self.u = self.e
            self.e = self.d
            self.d = self.w
            self.w = tmp
        else:
            tmp = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = tmp


def main():
    N = int(input())
    cubeL = []
    for i in range(N):
        u, s, e, w, n, d = map(int, input().split())
        cube = Cube(u, s, e, w, n, d)
        cubeL.append(cube)

    ret = "Yes"
    for i in range(N):
        for j in range(i+1, N):
            flag = True
            for k in range(100):
                cubeL[j].rotate(random.choice("NEWS"))
                if cubeL[i].u == cubeL[j].u and cubeL[i].n == cubeL[j].n and cubeL[i].w == cubeL[j].w and cubeL[i].e == cubeL[j].e and cubeL[i].s == cubeL[j].s and cubeL[i].d == cubeL[j].d:
                    flag = False
                    break
            if not flag:
                break
        if not flag:
            ret = "No"
            break
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# coding: utf-8
import random


class Dice() :

    mask = {'N':(1,5,2,3,0,4), 'E':(3,1,0,5,4,2),
            'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1),'CW':(0,2,4,1,3,5)}

    way = ("N","E","W","S","CW","Nop")

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

    def move(self, data):
        if data == "Nop":
            return
        self.label = [self.label[idx] for idx in self.mask[data]]

    def get_up(self):
        return self.label[0]

    def compare_6sq(self, dice2):
        check = True
        for i in range(6):
            if self.label[i] == dice2.label[i] :
                continue
            else:
                check = False
                break

        return check
    
    def compare_4rot(self, dice2):
        ok = False
        for i in range(4):
            self.move("CW")
            if self.compare_6sq(dice2) :
                ok =True
                break
        return ok
    
    def compare(self,dice2):
        ok = False
        orderway =("Nop","E","N","E","N","E")

        for s in orderway:
            self.move(s)
            if self.compare_4rot(dice2):
                ok = True
                break
        
        return ok
    
    def check_dicelist(self, dicelist):
        
        for tdice in dicelist:
            if self.compare(tdice):
                return True

        if len(dicelist) != 1 and dicelist[0].check_dicelist(dicelist[1:]) :
            return True

        return False
    




def check_alldice(dicelist):
    return dicelist[0].check_dicelist(dicelist[1:])

length = int(input())
dicelist1 = []
for _ in range(length):
    dicelist1.append(Dice(input().split()))

if not(check_alldice(dicelist1)) :
    print ("Yes")
else:
    print ("No")

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math

#0:中央,1:南,2:東,3:西,4:北,5:裏側
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]

    def equal(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].equal(DICE[k])==True:
            FLG = False
            break
            
if FLG == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
class Dice():
	def __init__(self):
		self.number = [_ for _ in range(6)]
		self.work = [_ for _ 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 _ in range(6):
			self.work[_] = self.number[_]
		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 get_right(self,n1,n2):
		if(n1 == self.number[0]):
			if(n2 == self.number[1]): return(self.number[2])
			elif(n2 == self.number[2]): return(self.number[4])
			elif(n2 == self.number[3]): return(self.number[1])
			elif(n2 == self.number[4]): return(self.number[3])
		elif(n1 == self.number[1]):
                        if(n2 == self.number[0]): return(self.number[3])
                        elif(n2 == self.number[2]): return(self.number[0])
                        elif(n2 == self.number[3]): return(self.number[5])
                        elif(n2 == self.number[5]): return(self.number[2])
		elif(n1 == self.number[2]):
                        if(n2 == self.number[0]): return(self.number[1])
                        elif(n2 == self.number[1]): return(self.number[5])
                        elif(n2 == self.number[4]): return(self.number[0])
                        elif(n2 == self.number[5]): return(self.number[4])
		elif(n1 == self.number[3]):
                        if(n2 == self.number[0]): return(self.number[4])
                        elif(n2 == self.number[1]): return(self.number[0])
                        elif(n2 == self.number[4]): return(self.number[5])
                        elif(n2 == self.number[5]): return(self.number[1])
		elif(n1 == self.number[4]):
                        if(n2 == self.number[0]): return(self.number[2])
                        elif(n2 == self.number[2]): return(self.number[5])
                        elif(n2 == self.number[3]): return(self.number[0])
                        elif(n2 == self.number[5]): return(self.number[3])
		elif(n1 == self.number[5]):
                        if(n2 == self.number[1]): return(self.number[3])
                        elif(n2 == self.number[2]): return(self.number[1])
                        elif(n2 == self.number[3]): return(self.number[4])
                        elif(n2 == self.number[4]): return(self.number[2])

	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

n = int(input())
dice = []
for _ in range(n):
	data = list(map(int,input().split()))
	dice.append(Dice())
	dice[_].setNumber(data[0],data[1],data[2],data[3],data[4],data[5])

flag = True
for _ in range(n-1):
	for i in range(_+1,n):
		if(dice[_].equals(dice[i])):
			flag = False
			break

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

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self, s1, s2, s3, s4, s5, s6):
        self.s1 = s1
        self.s2 = s2
        self.s3 = s3
        self.s4 = s4
        self.s5 = s5
        self.s6 = s6
    def east(self):
        prev_s6 = self.s6
        self.s6 = self.s3
        self.s3 = self.s1
        self.s1 = self.s4
        self.s4 = prev_s6
    def west(self):
        prev_s6 = self.s6
        self.s6 = self.s4
        self.s4 = self.s1
        self.s1 = self.s3
        self.s3 = prev_s6
    def north(self):
        prev_s6 = self.s6
        self.s6 = self.s5
        self.s5 = self.s1
        self.s1 = self.s2
        self.s2 = prev_s6
    def south(self):
        prev_s6 = self.s6
        self.s6 = self.s2
        self.s2 = self.s1
        self.s1 = self.s5
        self.s5 = prev_s6
    def rotate(self):
        prev_s2 = self.s2
        self.s2 = self.s4
        self.s4 = self.s5
        self.s5 = self.s3
        self.s3 = prev_s2
    def top(self):
        return self.s1
    def front(self):
        return self.s2
    def right(self):
        return self.s3

    def isSameDice(self, anotherDice):
        if self.s1 == anotherDice.s1 and \
           self.s2 == anotherDice.s2 and \
           self.s3 == anotherDice.s3 and \
           self.s4 == anotherDice.s4 and \
           self.s5 == anotherDice.s5 and \
           self.s6 == anotherDice.s6:
            return True
        return False


dices = []
n = int(input())
for i in range(n):
    s1, s2, s3, s4, s5, s6 = map(int, input().split())
    dices.append(Dice(s1, s2, s3, s4, s5, s6))

flag = False
for idx1, dice1 in enumerate(dices):
    for idx2, dice2 in enumerate(dices):
        if idx1 == idx2:
            continue

        for i in range(6):
            if i % 2 == 0:
                dice2.north()
            else:
                dice2.west()

            for j in range(4):
                dice2.rotate()
                if dice2.isSameDice(dice1):
                    flag = True
                    break
            if flag:
                break
        if flag:
            break
    if flag:
        break

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