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, 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 i in range(n):
    j = i+1
    while j < n:
        for k in range(6):
            if k % 2 == 0:
                dices[j].north()
            else:
                dices[j].west()

            for l in range(4):
                dices[j].rotate()
                if dices[j].isSameDice(dices[i]):
                    flag = True
                    break
            if flag:
                break
        if flag:
            break
        j += 1
    if flag:
        break

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

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):
        for i in range(6):
            if i % 2 == 0:
                self.north()
            else:
                self.west()
            for j in range(4):
                self.rotate()
                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 i in range(n):
    j = i+1
    while j < n:
        if dices[i].isSameDice(dices[j]):
            flag = True
            break
        j += 1

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

Submission status: Accepted

Solution code:
mask = [[i for i in range(6)], (1, 5, 2, 3, 0, 4), (2, 1, 5, 0, 4,3),(3, 1, 0, 5, 4, 2), (4, 0, 2, 3, 5, 1)]
mask += [[mask[1][i] for i in mask[1]]]

def set_top(dice, top):
    return [dice[i] for i in mask[top]]

def twist(dice):
    return [dice[i] for i in (0, 3, 1, 4, 2, 5)]

def equal(dice1, dice2):
    for i in range(6):
        tmp_dice = set_top(dice2, i)
        for _ in range(4):
            if dice1 == tmp_dice:
                return True
            tmp_dice = twist(tmp_dice)
    return False

def diff_check_all(dices, n):
    for i in range(n -1):
        for j in range(i + 1, n):
            if equal(dices[i], dices[j]):
                return False
    return True
            

n = int(input())
dices = [input().split() for _ in range(n)]

print('Yes' if diff_check_all(dices, n) else 'No')

Submission status: Accepted

Solution code:
mask = [[i for i in range(6)], (1, 5, 2, 3, 0, 4), (2, 1, 5, 0, 4,3),(3, 1, 0, 5, 4, 2), (4, 0, 2, 3, 5, 1)]
mask += [[mask[1][i] for i in mask[1]]]

def set_top(dice, top):
    return [dice[i] for i in mask[top]]

def twist(dice):
    return [dice[i] for i in (0, 3, 1, 4, 2, 5)]

def equal(dice1, dice2):
    if sorted(dice1) != sorted(dice2):
        return False
    
    for i in range(6):
        tmp_dice = set_top(dice2, i)
        for _ in range(4):
            if dice1 == tmp_dice:
                return True
            tmp_dice = twist(tmp_dice)
    return False

def diff_check_all(dices, n):
    for i in range(n -1):
        for j in range(i + 1, n):
            if equal(dices[i], dices[j]):
                return False
    return True
            

n = int(input())
dices = [input().split() for _ in range(n)]

print('Yes' if diff_check_all(dices, n) else 'No')

Submission status: Accepted

Solution code:
import sys
 
IDX_TBL = {1:[2,3,5,4], 2:[3,1,4,6], 3:[1,2,6,5],
           4:[1,5,6,2], 5:[1,3,6,4], 6:[2,4,5,3]}
OPPSITE_TBL = {1:6, 2:5, 3:4, 4:3, 5:2, 6:1}

def is_same(l1, l2):
    if l1[1] in l2:
        idx_list = [i for i,x in enumerate(l2) if x==l1[1]]
        for idx in idx_list:
            nstr1 = "".join([l1[i] for i in IDX_TBL[1]])
            nstr2 = "".join([l2[i] for i in IDX_TBL[idx]])
            if nstr2 in nstr1*2:
                if l1[6] == l2[7-l2.index(l1[1])]:
                    return True
    return False

n=input()
nums_list = []
for _ in range(n):
    nums_list.append(["_"] + raw_input().split(" "))

for i in range(0, n):
    for j in range(i+1, n):
        if is_same(nums_list[i], nums_list[j]):
            print "No"
            sys.exit(0)
print "Yes"

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, data):
        self.data = data

    def __eq__(self, value):

            
        for i in range(4):
            if self.data[0] == value.data[0]:
                for j in range(4):
                    if self.data == value.data:
                        return True
                    self.move('R')
            self.move('E')

        for i in range(4):
            if self.data[0] == value.data[0]:
                for j in range(4):
                    if self.data == value.data:
                        return True
                    self.move('R')
            self.move('N')
        return False

    def move(self, direction):
        if direction == 'E':
            self.data[0],self.data[3], self.data[5], self.data[2] = \
                self.data[3],self.data[5], self.data[2], self.data[0] 
        elif direction == 'N':
            self.data[0],self.data[1], self.data[5], self.data[4] = \
                self.data[1],self.data[5], self.data[4], self.data[0]
        elif direction == 'S':
            self.data[0],self.data[1], self.data[5], self.data[4] = \
                self.data[4],self.data[0], self.data[1], self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2], self.data[5], self.data[3] = \
                self.data[2],self.data[5], self.data[3], self.data[0]
        elif direction == 'R':
            self.data[1],self.data[2], self.data[4], self.data[3] = \
                self.data[2],self.data[4], self.data[3], self.data[1]

a = []
for i in range(int(input())):
    a += [Dice(input().split())]

p = 'Yes'
for i in range(len(a) - 1):
    for j in range(i + 1,len(a)):
        if a[i] == a[j]:
            p = 'No'
            break
print(p)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 22 11:38:11 2015

@author: hirose
"""

# -*- coding: utf-8 -*-

from random import *
import copy

def command(hougaku, label):
    temp = {}
    temp = copy.deepcopy(label)
    if(hougaku == 'E'):
        label[1] = temp[4]
        label[3] = temp[1]
        label[4] = temp[6]
        label[6] = temp[3]
    elif(hougaku == 'W'):
        label[1] = temp[3]
        label[3] = temp[6]
        label[4] = temp[1]
        label[6] = temp[4]
    elif(hougaku == 'N'):
        label[1] = temp[2]
        label[2] = temp[6]
        label[5] = temp[1]
        label[6] = temp[5]
    elif(hougaku == 'S'):
        label[1] = temp[5]
        label[2] = temp[1]
        label[5] = temp[6]
        label[6] = temp[2]

if __name__=="__main__":
    n = input()
    label = {}
    for i in range(n):
        label[i] = {}
        temp = map(int, raw_input().split())
        for j in range(6):
            label[i][j+1] = temp[j]
        #print label[i]
    flag = 0
    for i in range(n-1):
        #print label[i]
        for j in range(i+1,n):
            count = 0
            #print label[j]
            while True:
                if(label[i] == label[j]):
                    flag = 1
                    break
                x = random()
                if(x < 0.25):
                    command('E', label[j])
                elif(x < 0.50):
                    command('W', label[j])
                elif(x < 0.75):
                    command('N', label[j])
                else:
                    command('S', label[j])
                count += 1
                if(count > 50):
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if(flag == 0):
        print 'Yes'
    else:
        print 'No'

Submission status: Accepted

Solution code:
import sys

class Dice(object):
    def __init__(self, dice):
        self.__dice = tuple(dice)

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

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

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

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

    def number(self, face_id):
        return self.__dice[face_id - 1]

    def equals(self, dice):
        for i in range(4):
            for j in range(4):
                if self.__dice == dice.__dice:
                    return True
                dice.roll_north()
            dice.roll_west()
        return False

n = int(sys.stdin.readline())
dices = []
for i in range(n):
    dices.append(Dice([int(a) for a in sys.stdin.readline().split()]))

for i in range(n):
    for j in range(i + 1, n):
        if dices[i].equals(dices[j]):
            print("No")
            exit(0)
print("Yes")

Submission status: Accepted

Solution code:
import copy, sys

class Dice(object):
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, directions):
        if directions == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if directions == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if directions == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if directions == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

        self.roll(directions[0])
        self.roll(directions[1:])

    def equal(self, dice):
        d = copy.copy(self)

        if(dice.front == d.top):
            d.roll('S')
        elif(dice.front == d.right):
            d.roll('WS')
        elif(dice.front == d.left):
            d.roll('ES')
        elif(dice.front == d.back):
            d.roll('SS')
        elif(dice.front == d.bottom):
            d.roll('N')

        if(dice.top == d.right):
            d.roll('W')
        elif(dice.top == d.left):
            d.roll('E')
        elif(dice.top == d.bottom):
            d.roll('WW')

        return not(dice.top != d.top or dice.front != d.front or dice.right != d.right or dice.left != d.left or dice.back != d.back or dice.bottom != d.bottom)

if __name__ == '__main__':
    n = int(input())
    dices = []
    for i in range(n):
        d = Dice([int(_) for _ in input().split()])
        for dice in dices:
            if d.equal(dice):
                print('No')
                sys.exit()
        dices.append(d)
    print('Yes')

Submission status: Accepted

Solution code:
import copy, sys

class Dice(object):
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, directions):
        if directions == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if directions == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if directions == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if directions == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

        self.roll(directions[0])
        self.roll(directions[1:])

    def equal(self, dice):
        d = copy.copy(self)

        if(dice.front == d.top):
            d.roll('S')
        elif(dice.front == d.right):
            d.roll('WS')
        elif(dice.front == d.left):
            d.roll('ES')
        elif(dice.front == d.back):
            d.roll('SS')
        elif(dice.front == d.bottom):
            d.roll('N')

        if(dice.top == d.right):
            d.roll('W')
        elif(dice.top == d.left):
            d.roll('E')
        elif(dice.top == d.bottom):
            d.roll('WW')

        return not(dice.top != d.top or dice.front != d.front or dice.right != d.right or dice.left != d.left or dice.back != d.back or dice.bottom != d.bottom)

if __name__ == '__main__':
    n = int(input())
    dices = [[] for _ in range(600)]
    for i in range(n):
        nums = [int(_) for _ in input().split()]
        d = Dice(nums)
        s = sum(nums)
        for dice in dices[s]:
            if d.equal(dice):
                print('No')
                sys.exit()
        dices[s].append(d)
    print('Yes')

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import sys
import io
import re
import math
import itertools
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.141592653589
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
#start = time.clock()
ans=chk=0
a=[0,2,5,3]
b=[0,1,5,4]
c=[1,2,4,3]

def rolling(word,dice):
    if word=='S':
        dice[0],dice[1],dice[5],dice[4]=dice[4],dice[0],dice[1],dice[5]
    elif word=='N':
        dice[0],dice[1],dice[5],dice[4]=dice[1],dice[5],dice[4],dice[0]
    elif word=='W':
        dice[0],dice[2],dice[5],dice[3]=dice[2],dice[5],dice[3],dice[0]
    else:
        dice[0],dice[2],dice[5],dice[3]=dice[3],dice[0],dice[2],dice[5]
    return dice

def sortdice(dice1,dice2,p,q,r):
    for i in range(4):
        dice1[p[0]],dice1[p[1]],dice1[p[2]],dice1[p[3]]=dice1[p[1]],dice1[p[2]],dice1[p[3]],dice1[p[0]]
        for j in range(4):
            dice1[q[0]],dice1[q[1]],dice1[q[2]],dice1[q[3]]=dice1[q[1]],dice1[q[2]],dice1[q[3]],dice1[q[0]]
            for k in range(4):
                dice1[r[0]],dice1[r[1]],dice1[r[2]],dice1[r[3]]=dice1[r[1]],dice1[r[2]],dice1[r[3]],dice1[r[0]]
                if dice1==dice2:
                    print 'No'
                    exit()
    return 0
n=int(raw_input())
l=[]
for i in range(n):
    l.append(map(int,raw_input().split()))
for i in range(0,n-1):
    for j in range(i+1,n):
        sortdice(l[i],l[j],a,b,c)
print 'Yes'

Submission status: Accepted

Solution code:
class Dice:	
	def __init__( self, nums ):
		self.face = nums
	
	def rolltoTopIndex( self, faceindex ):	
		if faceindex == 1:
			self.roll( "N" )
		elif faceindex == 2:
			self.roll( "W" )
		elif faceindex == 3:
			self.roll( "E" )
		elif faceindex == 4:
			self.roll( "S" )
		elif faceindex == 5:
			self.roll( "NN" )
	
	def roll( self, actions ):
		for act in actions:
			t = 0
			if act == "E":
				t =   self.face[0]
				self.face[0] =   self.face[3]
				self.face[3] =   self.face[5]
				self.face[5] =   self.face[2]
				self.face[2] = t
			elif  act == "N":
				t =   self.face[0]
				self.face[0] =   self.face[1]
				self.face[1] =   self.face[5]
				self.face[5] =   self.face[4]
				self.face[4] = t
			elif  act == "S":
				t =  self.face[ 0]
				self.face[0] =  self.face[4]
				self.face[4] =  self.face[5]
				self.face[5] =  self.face[1]
				self.face[1] = t	
			elif  act == "W":
				t =  self.face[0]
				self.face[0] =  self.face[2]
				self.face[2] =  self.face[5]
				self.face[5] =  self.face[3]
				self.face[3] = t	
			elif  act == "M":
				t =  self.face[1]
				self.face[1] =  self.face[2]
				self.face[2] =  self.face[4]
				self.face[4] =  self.face[3]
				self.face[3] = t

def isDiffDice( dice1, dice2 ):
	diceface = dice2.face
	cnt = 0
	for i in range( 6 ):
		if dice1.face[0] == dice2.face[i]:
			dice2.rolltoTopIndex( i )
			for j in range( 1, 5 ):
				if dice1.face[1] == dice2.face[1]:
					cnt = 0
					for k in range( 6 ):
						if dice1.face[k] == dice2.face[k]:
							cnt += 1
					if cnt == 6:
						break
				dice2.roll( "M" )
		if cnt == 6:
			break
		dice2.face = diceface
			
	if cnt == 6:
		return False
	else:
		return True


n = int( raw_input( ) )
dices = [ Dice( [ int( val ) for val in raw_input( ).split( " " ) ] ) for i in range( n ) ]

isdiff = True
for i in range( 0, n-1 ):
	for j in range( i+1, n ):
		if not isDiffDice( dices[i], dices[j] ):
			print( "No" )
			isdiff = False
			break
	if not isdiff:
		break

if isdiff:
	print( "Yes" )

Submission status: Accepted

Solution code:
class Dice:	
	def __init__( self, nums ):
		self.face = nums
	
	def rolltoTopIndex( self, faceindex ):	
		if faceindex == 1:
			self.roll( "N" )
		elif faceindex == 2:
			self.roll( "W" )
		elif faceindex == 3:
			self.roll( "E" )
		elif faceindex == 4:
			self.roll( "S" )
		elif faceindex == 5:
			self.roll( "NN" )
	
	def roll( self, actions ):
		for act in actions:
			t = 0
			if act == "E":
				t =   self.face[0]
				self.face[0] =   self.face[3]
				self.face[3] =   self.face[5]
				self.face[5] =   self.face[2]
				self.face[2] = t
			elif  act == "N":
				t =   self.face[0]
				self.face[0] =   self.face[1]
				self.face[1] =   self.face[5]
				self.face[5] =   self.face[4]
				self.face[4] = t
			elif  act == "S":
				t =  self.face[ 0]
				self.face[0] =  self.face[4]
				self.face[4] =  self.face[5]
				self.face[5] =  self.face[1]
				self.face[1] = t	
			elif  act == "W":
				t =  self.face[0]
				self.face[0] =  self.face[2]
				self.face[2] =  self.face[5]
				self.face[5] =  self.face[3]
				self.face[3] = t	
			elif  act == "M":
				t =  self.face[1]
				self.face[1] =  self.face[2]
				self.face[2] =  self.face[4]
				self.face[4] =  self.face[3]
				self.face[3] = t

def isDiffDice( dice1, dice2 ):
	diceface = dice2.face
	cnt = 0
	for i in range( 6 ):
		if dice1.face[0] == dice2.face[i]:
			dice2.rolltoTopIndex( i )
			for j in range( 1, 5 ):
				if dice1.face[1] == dice2.face[1]:
					cnt = 0
					for k in range( 6 ):
						if dice1.face[k] == dice2.face[k]:
							cnt += 1
					if cnt == 6:
						break
				dice2.roll( "M" )
		if cnt == 6:
			break
		dice2.face = diceface
			
	if cnt == 6:
		return False
	else:
		return True


n = int( input( ) )
dices = [ Dice( [ int( val ) for val in input( ).split( " " ) ] ) for i in range( n ) ]

isdiff = True
for i in range( 0, n-1 ):
	for j in range( i+1, n ):
		if not isDiffDice( dices[i], dices[j] ):
			print( "No" )
			isdiff = False
			break
	if not isdiff:
		break

if isdiff:
	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:
#coding:utf-8
#1_11_C

class Dice:
    def __init__(self, ary):
        self.top, self.south, self.east, self.west, self.north, self.bottom = ary

    def roll_n(self):
        self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom

    def roll_e(self):
        self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom

    def twist(self):
        self.north, self.east, self.south, self.west = self.west, self.north, self.east, self.south

    def isEqual(self, dice):
        if self.top == dice.top and self.south == dice.south and self.east == dice.east and self.west == dice.west and self.north == dice.north and self.bottom == dice.bottom:
            return True
        else:
            return False

def isSame(diceX,diceY):
    flag = False
    
    for i in range(6):
        if i % 2 == 0:
            diceX.roll_n()
        else:
            diceX.roll_e()
    
        for j in range(4):
            if diceX.isEqual(diceY):
                flag = True
                break
            else:
                diceX.twist()
    
        if flag:
            break
    
    if flag:
        return True
    else:
        return False

n = int(input())
dices = [Dice(map(int,input().split())) for i in range(n)]

flag = False
for i in range(len(dices)):
    for j in range(i+1, len(dices)):
        if isSame(dices[i],dices[j]):
            flag = True

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

Submission status: Accepted

Solution code:
# coding=utf-8
from itertools import combinations


class Dice(object):

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

    def getLabel(self, i):
        return self.label[i - 1]

    def _rotateS(self):
        self.label = [self.getLabel(i) for i in [5, 1, 3, 4, 6, 2]]

    def _rotateN(self):
        self.label = [self.getLabel(i) for i in [2, 6, 3, 4, 1, 5]]

    def _rotateE(self):
        self.label = [self.getLabel(i) for i in [4, 2, 1, 6, 5, 3]]

    def _rotateW(self):
        self.label = [self.getLabel(i) for i in [3, 2, 6, 1, 5, 4]]

    def _spinPos(self):
        self.label = [self.getLabel(i) for i in [1, 4, 2, 5, 3, 6]]

    def _spinNeg(self):
        self.label = [self.getLabel(i) for i in [1, 3, 5, 2, 4, 6]]

    def rotate(self, rotates):
        for r in rotates:
            if r == 'S':
                self._rotateS()
            elif r == 'N':
                self._rotateN()
            elif r == 'E':
                self._rotateE()
            elif r == 'W':
                self._rotateW()
            elif r == 'T':
                self._spinPos()
            elif r == 'B':
                self._spinNeg()

    def matchTopFront(self, top, front):
        try:
            iTop = self.label.index(top) + 1
            topRot = {1: '', 2: 'N', 3: 'W', 4: 'E', 5: 'S', 6: 'SS'}
            self.rotate(topRot[iTop])

            iFront = self.label.index(front) + 1
            frontRot = {2: '', 3: 'B', 4: 'T', 5: 'TT'}
            self.rotate(frontRot[iFront])
            return True
        except KeyError:
            return False

    def copy(self):
        return Dice(self.label[:])

    def __eq__(self, other):
        # ?????¢???????????¢?????\????????§6????????????
        for rs in ['', 'S', 'N', 'E', 'W', 'SS']:
            tmp = self.copy()
            for r in rs:
                tmp.rotate(r)
            # ?????¢????????¢????????§??????
            top = tmp.getLabel(1) == other.getLabel(1)
            bottom = tmp.getLabel(6) == other.getLabel(6)
            # ??´??¢?????????????????????????????????????????¢??????????????????????????´??????????????°??????
            # top and bottom ???False??????????????????????????????????????§?????¢??°?????????

            def _side():
                result, n = False, 3
                while not result and n > 0:
                    if tmp.label[1:5] == other.label[1:5]:
                        result = True
                    else:
                        tmp.rotate('T')
                        n -= 1
                return result

            if top and bottom and _side():
                return True
        else:
            return False


def sub(face1, face2):
    # ????????????????????????????????´?????????????????´???
    if set(face1) != set(face2):
        return False
    # ???????????????????????´???
    elif len(face1) == len(set(face1)):
        d1 = Dice(face1)
        d2 = Dice(face2)
        if d2.matchTopFront(d1.getLabel(1), d1.getLabel(2)):
            return True if d1.label == d2.label else False
        else:
            return False
    # ???????????????????????´???
    else:
        d1 = Dice(face1)
        d2 = Dice(face2)
        return True if d1 == d2 else False


def main():
    n = input()
    faces = [map(int, raw_input().split()) for _ in xrange(n)]
    for f1, f2 in combinations(faces, 2):
        if f1 == f2 or sub(f1, f2) == True:
            print 'No'
            break
    else:
        print 'Yes'


if __name__ == '__main__':
    main()