Problem:
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

Solution (Python):


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()

Solution (Python):


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()

Solution (Python):


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()

Solution (Python):


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()

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

Solution (Python):
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 
            A,B,C,D,E,F = D,B,A,F,E,C 
            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 
            A,B,C,D,E,F = B,F,C,D,A,E 

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

Solution (Python):
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)

Solution (Python):
class Dice:
    """Dice class"""
    def __init__(self):                  
        self.eyeIndex = 1        
        self.eyeIndex_E = 3      
        self.eyeIndex_W = 4      
        self.eyeIndex_N = 5      
        self.eyeIndex_S = 2      
        self.eye = 0
        self.eye_S = 0
        self.eye_E = 0
        self.eye_W = 0
        self.eye_N = 0
        self.eye_B = 0
        self.eyes = []

    def convEyesIndexToEyes(self):
        self.eye = self.eyes[self.eyeIndex]
        self.eye_S = self.eyes[self.eyeIndex_S]
        self.eye_E = self.eyes[self.eyeIndex_E]
        self.eye_N = self.eyes[self.eyeIndex_N]
        self.eye_W = self.eyes[self.eyeIndex_W]
        self.eye_B = self.eyes[7-self.eyeIndex]

    def shakeDice(self, in_command):
        pre_eyeIndex = self.eyeIndex
        if in_command == "E":
            self.eyeIndex = self.eyeIndex_W 
            self.eyeIndex_E = pre_eyeIndex 
            self.eyeIndex_W = 7 - self.eyeIndex_E
            
        elif in_command == "W":
            self.eyeIndex = self.eyeIndex_E 
            self.eyeIndex_W = pre_eyeIndex
            self.eyeIndex_E = 7 - self.eyeIndex_W
            
        elif in_command == "N":
            self.eyeIndex = self.eyeIndex_S 
            self.eyeIndex_N = pre_eyeIndex 
            self.eyeIndex_S = 7 - self.eyeIndex_N

        elif in_command == "S":
            self.eyeIndex = self.eyeIndex_N         
            self.eyeIndex_S = pre_eyeIndex 
            self.eyeIndex_N = 7 - self.eyeIndex_S 
        
        self.convEyesIndexToEyes()


    def rotateDice(self):
        
        pre_E = self.eyeIndex_E
        pre_S = self.eyeIndex_S
        pre_W = self.eyeIndex_W
        pre_N = self.eyeIndex_N
        
        self.eyeIndex_E = pre_N
        self.eyeIndex_S = pre_E
        self.eyeIndex_W = pre_S
        self.eyeIndex_N = pre_W

        self.convEyesIndexToEyes()
        
    def getEye(self):
        return self.eye
        
    def getEye_S(self):
        return self.eye_S
    
    def getEye_E(self):
        return self.eye_E

    def getEye_N(self):
        return self.eye_N

    def getEye_W(self):
        return self.eye_W

    def getEye_B(self):
        return self.eye_B
        
    def setEyes(self, eyes):             
        eyes = "0 " + eyes
        self.eyes = list(map(int, eyes.split(" ")))
        self.convEyesIndexToEyes()
        

def checkSameDice(dice_1, dice_2):
    shake_direction = "E"
    shake_cnt = 0

    while True:
        if dice_2.getEye() == dice_1.getEye() and dice_2.getEye_B() == dice_1.getEye_B():
            break
    
        dice_2.shakeDice(shake_direction)
        shake_cnt = shake_cnt + 1
        
        if shake_cnt >= 8:
            return False
            break
        if shake_cnt >= 4:
            shake_direction = "N"

    rotate_cnt = 0
    
    while True:
        if dice_1.getEye() == dice_2.getEye() and dice_1.getEye_E() == dice_2.getEye_E() and \
            dice_1.getEye_S() == dice_2.getEye_S() and dice_1.getEye_W() == dice_2.getEye_W() and \
            dice_1.getEye_N() == dice_2.getEye_N():
            break
        
        dice_2.rotateDice()
        rotate_cnt = rotate_cnt + 1
        
        if rotate_cnt >= 5:
            return False
            
    return True


dice_cnt = int(input().rstrip())


dices = []


for i in range(dice_cnt):
    
    tmpDice = Dice()
    tmpDice.setEyes(input().rstrip())
    dices.append(tmpDice)
    tmpDice = None


judge = "Yes"
for i in range(dice_cnt):
    for j in range(i+1, dice_cnt):
        if checkSameDice(dices[i],dices[j]):
            judge = "No"
            break
    
    if judge == "No":
        break
            
print(judge)

Solution (Python):
class Dice:
    def __init__(self):
        self.faces=[]

    def rotate(self, direction):
        tmp = self.faces.copy()

        if direction =="N":
            self.faces[5-1] = tmp[1-1]
            self.faces[1-1] = tmp[2-1]
            self.faces[2-1] = tmp[6-1]
            self.faces[6-1] = tmp[5-1]
        if direction =="S":
            self.faces[5-1] = tmp[6-1]
            self.faces[1-1] = tmp[5-1]
            self.faces[2-1] = tmp[1-1]
            self.faces[6-1] = tmp[2-1]
        if direction =="W":
            self.faces[4-1] = tmp[1-1]
            self.faces[1-1] = tmp[3-1]
            self.faces[3-1] = tmp[6-1]
            self.faces[6-1] = tmp[4-1]
        if direction =="E":
            self.faces[3-1] = tmp[1-1]
            self.faces[1-1] = tmp[4-1]
            self.faces[4-1] = tmp[6-1]
            self.faces[6-1] = tmp[3-1]
        return 0

    def spin(self):
        self.faces[4-1], self.faces[2-1],self.faces[5-1],self.faces[3-1] =\
        self.faces[2-1], self.faces[3-1],self.faces[4-1],self.faces[5-1]

        return 0

res = "Yes"
dices = []
lines = int(input())
for i in range(lines):
    dices.append(Dice())
    dices[i].faces=[int(x) for x in input().split(" ")]


for i, d1 in enumerate(dices):
    for d2 in dices[i+1 :]:
        for _ in range(3):
            for _ in range(4):
                for ___ in range(4):
                    
                    
                    if d1.faces == d2.faces:
                        res = "No"
                        break
                    d2.spin()
                d2.rotate("W")
            d2.rotate("N")

print(res)

Solution (Python):
class Dice:
    def __init__(self):
        self.faces=[]

    def rotate(self, direction):
        tmp = self.faces.copy()

        if direction =="N":
            self.faces[5-1] = tmp[1-1]
            self.faces[1-1] = tmp[2-1]
            self.faces[2-1] = tmp[6-1]
            self.faces[6-1] = tmp[5-1]
        if direction =="S":
            self.faces[5-1] = tmp[6-1]
            self.faces[1-1] = tmp[5-1]
            self.faces[2-1] = tmp[1-1]
            self.faces[6-1] = tmp[2-1]
        if direction =="W":
            self.faces[4-1] = tmp[1-1]
            self.faces[1-1] = tmp[3-1]
            self.faces[3-1] = tmp[6-1]
            self.faces[6-1] = tmp[4-1]
        if direction =="E":
            self.faces[3-1] = tmp[1-1]
            self.faces[1-1] = tmp[4-1]
            self.faces[4-1] = tmp[6-1]
            self.faces[6-1] = tmp[3-1]
        return 0

    def spin(self):
        self.faces[4-1], self.faces[2-1],self.faces[5-1],self.faces[3-1] =\
        self.faces[2-1], self.faces[3-1],self.faces[4-1],self.faces[5-1]

        return 0

dices = []
lines = int(input())
for i in range(lines):
    dices.append(Dice())
    dices[i].faces=[int(x) for x in input().split(" ")]

for i, d1 in enumerate(dices):
    for d2 in dices[i+1 :]:
        for _ in range(3):
            for _ in range(4):
                for ___ in range(4):
                    
                    
                    if d1.faces == d2.faces:
                        print("No")
                        exit()
                    d2.spin()
                d2.rotate("W")
            d2.rotate("N")

print("Yes")

Solution (Python):


import sys
import os


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

def dice_roll(dice, c):
    copy = dice[:]
    if c == 'E':
        dice[2] = copy[0]
        dice[5] = copy[2]
        dice[3] = copy[5]
        dice[0] = copy[3]
    elif c == 'N':
        dice[0] = copy[1]
        dice[4] = copy[0]
        dice[5] = copy[4]
        dice[1] = copy[5]
        pass
    elif c == 'S':
        dice[1] = copy[0]
        dice[0] = copy[4]
        dice[4] = copy[5]
        dice[5] = copy[1]
    elif c == 'W':
        dice[0] = copy[2]
        dice[2] = copy[5]
        dice[5] = copy[3]
        dice[3] = copy[0]
    
    elif c == 'R':
        dice[2] = copy[1]
        dice[4] = copy[2]
        dice[3] = copy[4]
        dice[1] = copy[3]
    return dice


def check(dice0_input, dice1_input):
    
    dice0 = dice0_input[:]
    dice1 = dice1_input[:]

    
    num = 0
    while dice0[0] != dice1[0]:
        if num % 2 == 0:
            dice0 = dice_roll(dice0, 'E')
        else:
            dice0 = dice_roll(dice0, 'N')
        num += 1
        if num > 10:
            return False

    
    num = 0
    while dice0[1] != dice1[1]:
        dice0 = dice_roll(dice0, 'R')
        num += 1
        if num > 10:
            return False

    if dice0[2] == dice1[2] and dice0[3] == dice1[3] and dice0[4] == dice1[4] and dice0[5] == dice1[5]:
        return True
    else:
        return False


def check2(dice0, dice1):
    
    for i in range(6):
        result = check(dice0, dice1)
        if result:
            return True
        else:
            if i % 2 == 0:
                dice0 = dice_roll(dice0, 'N')
            else:
                dice0 = dice_roll(dice0, 'E')
    return False

for i in range(N):
    for j in range(i+1, N):
        is_same = check2(dices[i], dices[j])
        if is_same:
            print('No')
            quit()
print('Yes')

Solution (Python):
class dice:
    def __init__(self,label):
        self.spots = label

    def roll(self,way):
        if way == "N":
            self.spots = [self.spots[1],self.spots[5],self.spots[2],self.spots[3],self.spots[0],self.spots[4]]
        if way == "E":
            self.spots = [self.spots[3],self.spots[1],self.spots[0],self.spots[5],self.spots[4],self.spots[2]]
        if way == "W":
            self.spots = [self.spots[2],self.spots[1],self.spots[5],self.spots[0],self.spots[4],self.spots[3]]
        if way == "S":
            self.spots = [self.spots[4],self.spots[0],self.spots[2],self.spots[3],self.spots[5],self.spots[1]]
    def output(self):
        return self.spots

dice_set=[]
dice_same=0


for l in range(int(input())):
    dice_set.append(list(map(int,input().split())))


for m in range(len(dice_set)):
    dice_list=[]       

    label = dice_set[m]
    rotation = dice(label)
    for i in range(3):
        dice_list.append(rotation.output())
        for j in range(3):
            rotation.roll("E")
            dice_list.append(rotation.output())
        rotation.roll("N")

    rotation.roll("N")
    rotation.roll("N")

    for i in range(3):
        dice_list.append(rotation.output())
        for j in range(3):
            rotation.roll("W")
            dice_list.append(rotation.output())
        rotation.roll("N")

    for n in range(m+1,len(dice_set)):
        if dice_set[n] in dice_list:
            dice_same += 1

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

Solution (Python):
class Dice:
    """????????????????????????"""
    def __init__(self, s):
        self.s = [0 for _ in range(6)]
        self.s[0] = s[0]
        self.s[1] = s[1]
        self.s[2] = s[2]
        self.s[3] = s[3]
        self.s[4] = s[4]
        self.s[5] = s[5]

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

    def issame(self, s):
        answer = 0
        for _ in range(3):
            for _ in range(4):
                self.roll("N")
                self.roll("E")
                self.roll("S")
                if self.s == s:
                    answer = 1
            self.roll("N")
            for _ in range(4):
                self.roll("N")
                self.roll("E")
                self.roll("S")
                if self.s == s:
                    answer = 1
            self.roll("E")
        return answer


n = int(input())
for i in range(n):
    s = list(map(int, input().split()))
    code = "dice{} = Dice(s)".format(i)
    exec(code)

answer = "Yes"
for i in range(n-1):
    for j in range(i+1, n):
        code = "ans = dice{0}.issame(dice{1}.s)".format(i, j)
        exec(code)
        if ans == 1:
            answer = "No"

print(answer)

Solution (Python):

store=[]
str=["N","S","E","W"]
rep={
    "N":[4,0,2,3,5,1],
    "S":[1,5,2,3,0,4],
    "E":[2,1,5,0,4,3],
    "W":[3,1,0,5,4,2]
}

def rotate_dice(b,s):
    result = [0,0,0,0,0,0]
    for i in range(6):
        result[i]=b[rep[s][i]]
    return result
    
def generate(b):
    if (b in store)==False:
        store.append(b)
        for s in str:
            generate(rotate_dice(b,s))

def check(a,b):
    generate(b)
    if a in store:
        return False
    else:
        return True

n=int(input())
dices=[0]*n
for i in range(n):
    dices[i]=input().split()
result = 1
i=0
while i < n-1:
    j=i+1
    while j < n:
        r = check(dices[i],dices[j])
        store = []
        result *= r
        j+=1
    i+=1

if result == 1:
    print("Yes")
else:
    print("No")