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:
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, another_dice):

        self.save_data = [i for i in range(6)]
        # 元の値の保存
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        is_same_face = False
        for i in range(len(self.order)):
            self.roll(self.order[i])
            if [f == s for f, s in zip(self.number, another_dice)].count(False) == 0:
                is_same_face = True
                break

        # 元の値の復元
        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]
        return is_same_face


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

for i in range(query_num):
    for q in range(query_num):
        if i == q:
            continue
        first_dice = dices[i]
        second_dice = dices[q]
        if first_dice.query(second_dice.number) == True:
            print("No")
            sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
class Dice():
	def __init__(self):
		self.number = [int(i) for i in range(1,7)]
	
	def set_number(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,s):
		tmp = self.number
		if s == "S":
			self.set_number(tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1])
		elif s == "E":
			self.set_number(tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2])
		elif s == "N":
			self.set_number(tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4])
		elif s == "W":
			self.set_number(tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3])

	def get_number(self,i):
		# top: 0, front: 1, right: 2, left: 3, back: 4, bottom: 5 
		return self.number[i]

	def get_position(self,i):
		return self.number.index(i)
	
	def get_dice(self):
		return [self.number[0],self.number[1],self.number[2],self.number[3],self.number[4],self.number[5]]

def check_dice(diceA,diceB):
	dice_numA = diceA.get_dice()
	dice_numB = diceB.get_dice()
	dice_numA.sort()
	dice_numB.sort()
	if dice_numA == dice_numB:
		top = diceA.get_number(0)
		front = diceA.get_number(1)
		while diceB.get_number(1) != front:
			if diceB.get_position(front) == 2 or diceB.get_position(front) == 3:
				diceB.roll("E")
			else:
				diceB.roll("S")
		if diceB.get_number(4) != top:
			while diceB.get_number(0) != top:
				diceB.roll("E")
			if diceA.get_dice() == diceB.get_dice():
				return 0
	return 1

if __name__ == '__main__':
	num = int(input())
	dice_num = []
	for i in range(num):
		dice_num.append([int(s) for s in input().split()])

	dice = []
	for i in range(num):
		dice.append(Dice())
		dice[i].set_number(dice_num[i][0],dice_num[i][1],dice_num[i][2],dice_num[i][3],dice_num[i][4],dice_num[i][5])

	flag = 0

	for i in range(num):
		for k in range(i+1,num):
			if check_dice(dice[i],dice[k]) == 0:
				print("No")	
				exit()
	print("Yes")

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.number = [i for i in range(6)]
        self.tmp = [i for i in range(6)]
        self.set_cmd = '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 next(self,direction):
        for i in range(6):
            self.tmp[i] = self.number[i]

        if direction == 'E':
            self.setNumber(self.tmp[3], self.tmp[1], self.tmp[0], self.tmp[5], self.tmp[4], self.tmp[2])
        elif direction == 'N':
            self.setNumber(self.tmp[1], self.tmp[5], self.tmp[2], self.tmp[3], self.tmp[0], self.tmp[4])
        elif direction == 'S':
            self.setNumber(self.tmp[4], self.tmp[0], self.tmp[2], self.tmp[3], self.tmp[5], self.tmp[1])
        elif direction == 'W':
            self.setNumber(self.tmp[2], self.tmp[1], self.tmp[5], self.tmp[0], self.tmp[4], self.tmp[3])
    def get_result(self):
        return self.number[0]

    def cheak(self,altanative):

        flag = True

        for i in range(len(self.set_cmd)):
            self.next(self.set_cmd[i])
            flag = True
            for j in range(6):
                if self.number[j] != altanative.number[j]:
                    flag = False
                    break
            else:
                if flag == True:
                    return flag

        return flag

dice1 = Dice()
Dice_arr = []
n = int(input())

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

judge = False

for i in range(n-1):
    for j in range(i+1,n):
        if Dice_arr[i].cheak(Dice_arr[j]) == True:
            judge = True
            break

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

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, labels):
        self.top = labels[0]
        self.front = labels[1]
        self.right = labels[2]
        self.left = labels[3]
        self.back = labels[4]
        self.bottom = labels[5]

    def roll(self, axis, count=1):
        while count < 0:
            count += 4
        if axis == "X":
            for _ in range(count):
                self.top, self.back, self.bottom, self.front = self.front, self.top, self.back, self.bottom
        elif axis == "Y":
            for _ in range(count):
                self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        elif axis == "Z":
            for _ in range(count):
                self.front, self.left, self.back, self.right = self.right, self.front, self.left, self.back
        elif axis == "N":
            self.roll("X", 1)
        elif axis == "W":
            self.roll("Y", -1)
        elif axis == "S":
            self.roll("X", -1)
        elif axis == "E":
            self.roll("Y", 1)


def is_identical(d1, d2):
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return True
        d2.roll("Z")
    d2.roll("X")
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return True
        d2.roll("Y")
    d2.roll("X")
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return True
        d2.roll("Z")
    d2.roll("X")
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return True
        d2.roll("Y")
    d2.roll("X")
    d2.roll("Y")
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return True
        d2.roll("X")
    d2.roll("Y", 2)
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return True
        d2.roll("X")
    return False


from itertools import combinations
N = int(input())
D = [Dice([int(c) for c in input().split()]) for _ in range(N)]
for d1, d2 in combinations(D, 2):
    if is_identical(d1, d2):
        print("No")
        exit(0)
print("Yes")

Submission status: Accepted

Solution code:
def move(dice, order):
  if order == "E":
    temp = dice[0]
    dice[0] = dice[3]
    dice[3] = dice[5]
    dice[5] = dice[2]
    dice[2] = temp
  elif order == "N":
    temp = dice[0]
    dice[0] = dice[1]
    dice[1] = dice[5]
    dice[5] = dice[4]
    dice[4] = temp
  elif order == "S":
    temp = dice[0]
    dice[0] = dice[4]
    dice[4] = dice[5]
    dice[5] = dice[1]
    dice[1] = temp
  elif order == "W":
    temp = dice[0]
    dice[0] = dice[2]
    dice[2] = dice[5]
    dice[5] = dice[3]
    dice[3] = temp
  else:
    pass
  return dice

def roll(dice):
  temp = dice[1]
  dice[1] = dice[2]
  dice[2] = dice[4]
  dice[4] = dice[3]
  dice[3] = temp
  return dice

def judge(dice1, dice2):
  flag = True
  for i in range(6):
    if dice1[i] != dice2[i]:
      flag = False
      break
  return flag

def aresame(dice1, dice2):
  mvdice = dice2
  cnt = 0
  
  while True:
    mvdice = move(mvdice, "E")
    cnt += 1
    if dice1[0] == mvdice[0]:
      rolldice = mvdice
      cntroll = 0
      while True:
        rolldice = roll(rolldice)
        cntroll += 1
        if judge(dice1, rolldice) == True:
          return True
        if cntroll == 4:
          break
    if cnt == 4:
      break

  mvdice = dice2
  cnt = 0
    
  while True:
    mvdice = move(mvdice, "N")
    cnt += 1
    if dice1[0] == mvdice[0]:
      rolldice = mvdice
      cntroll = 0
      while True:
        rolldice = roll(rolldice)
        cntroll += 1
        if judge(dice1, rolldice) == True:
          return True
        if cntroll == 4:
          break
    if cnt == 4:
      break

  return False


import sys

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

for i in range(n):
  for j in range(i+1, n):
    if aresame(saikoro[i], saikoro[j]) == True:
      print("No")
      sys.exit()
      
print("Yes")

Submission status: Accepted

Solution code:
class Dice():
  def __init__ (self):
    # 1:ue 2:syomen 3:migi 4:hidari 5:oku 6:shita
    self.position = [0,0,0,0,0,0]
    self.search_result = []
  
  def setNumber (self, num):
    for i,x in enumerate(num):
      self.position[i] = x
    #print(self.position)
      
  def roll(self, roll):
    for i in range(len(roll)):
      s = roll[i:i+1]
      p = self.position
      if s == 'E':
        self.setNumber([p[3], p[1], p[0], p[5], p[4], p[2]])
      elif s == 'W':
        self.setNumber([p[2], p[1], p[5], p[0], p[4], p[3]])
      elif s == 'S':
        self.setNumber([p[4], p[0], p[2], p[3], p[5], p[1]])
      elif s == 'N':
        self.setNumber([p[1], p[5], p[2], p[3], p[0], p[4]])
      elif s == 'R':
        self.setNumber([p[0], p[2], p[4], p[1], p[3], p[5]])

  def printTop(self):
    print(self.position[0])

  def searchRight(self, a, b):
    i1 = self.position.index(a)
    i2 = self.position.index(b)
    #print("i1:" + str(i1) + " i2:" + str(i2) )
    
    # 0
    if (i1 == 1 and i2 == 2) or (i1 == 2 and i2 == 4) or (i1 == 4 and i2 == 3) or (i1 == 3 and i2 == 1):
      self.search_result.append(self.position[0])
    # 1
    elif (i1 == 0 and i2 == 3) or (i1 == 3 and i2 == 5) or (i1 == 5 and i2 == 2) or (i1 == 2 and i2 == 0):
      self.search_result.append(self.position[1])
    # 2
    elif (i1 == 0 and i2 == 1) or (i1 == 1 and i2 == 5) or (i1 == 5 and i2 == 4) or (i1 == 4 and i2 == 0):
      self.search_result.append(self.position[2])
    # 3
    elif (i1 == 1 and i2 == 0) or (i1 == 0 and i2 == 4) or (i1 == 4 and i2 == 5) or (i1 == 5 and i2 == 1):
      self.search_result.append(self.position[3])
    # 4
    elif (i1 == 0 and i2 == 2) or (i1 == 2 and i2 == 5) or (i1 == 5 and i2 == 3) or (i1 == 3 and i2 == 0):
      self.search_result.append(self.position[4])
    # 5
    elif (i1 == 2 and i2 == 1) or (i1 == 1 and i2 == 3) or (i1 == 3 and i2 == 4) or (i1 == 4 and i2 == 2):
      self.search_result.append(self.position[5])
    
  def printResult(self):
    for i in self.search_result:
      print (i)
  
  def isSame(self, d):
    for r in ["", "R", "R", "R", 
              "RE",  "R", "R", "R",
              "RE",  "R", "R", "R",
              "RE",  "R", "R", "R",
              "RS",  "R", "R", "R",
              "RNN", "R", "R", "R"]:
      self.roll(r)
      #print(self.position)
      if self.position == d.position:
        return True
    return False

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

for i in range(n):
  n = list(int(x) for x in input().split())

  d = Dice()
  d.setNumber(n)

  dices.append(d)

result = True
for i in range(len(dices)):
  if result == False:
    break

  for j in range(i+1, len(dices)):
    #print ("check:" + str(i) + "," + str(j))
    if dices[i].isSame(dices[j]):
      result = False
      break

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

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,my_label):
        self.top,self.front,self.right,self.left,self.back,self.bottom = [int(x) for x in my_label]

    def Roll(self,i):
        if i == 0:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.right, self.front, self.bottom, self.top, self.back, self.left
        
        if i == 1:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.left, self.front, self.top, self.bottom, self.back, self.right
        
        if i == 2:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.back, self.top, self.right, self.left, self.bottom, self.front
            
        if i == 3:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.front, self.bottom, self.right, self.left, self.top, self.back

    def Open(self):
        print(self.top)

def CheckData(data,top,front):
    for i in range(len(data)):
        if(data[i][0] == top and data[i][1] == front):
            print(data[i][2])
            break
            
def CheckDice(n,data):
    #同じ物が見つかったら偽にしてbreak
    
    isEqual = False
    
    for i in range(n):
        for j in range(i+1,n):
            if(data[i] == data[j]):
                isEqual = True
                break
    
    if(isEqual == True):
        print("No")
    else:
        print("Yes")
                
def MakeData(dice):
    num_data = 4 * 6 -1
    
    dataset = list()
    data = [dice.top, dice.front, dice.right]

    dataset.append(data)
    
    isOnly = True
    
    n = 0
    while 0 < num_data:
        n += 1
        if (n > 1000):
            break
            
        data = [dice.top, dice.front, dice.right]

        isOnly = True
        for i in range (len(dataset)):
            if(data == dataset[i]):
                isOnly = False
                break
        if isOnly == True:
            dataset.append(data)
            dataset.sort()
            num_data -= 1
        
        dice.Roll(int(random.random() * 4))
        
    
        
    return dataset

import random

n = int(input())

my_label = [0] * n
dice = [0] * n
data = [0] * n

for i in range(n):
    my_label = [int(x) for x in input().split(" ")]
    
    dice = Dice(my_label)
    data[i] = MakeData(dice)

CheckDice(n,data)

Submission status: Accepted

Solution code:
import random

class dice:
    def __init__(self, t, S, E):
        self.dice = list(map(int, input().split()))
        self.t = t
        self.S = S
        self.E = E
        self.now_dice()
    
    def roll(self, order):
        if order == 'E':
            self.t, self.E = self.W, self.t
        elif order == 'N':
            self.t, self.S = self.S, self.g
        elif order == 'S':
            self.t, self.S = self.N, self.t
        elif order == 'W':
            self.t, self.E = self.E, self.g
        self.now_dice()
    
    def now_dice(self):
        self.N = 7 - self.S
        self.g = 7 - self.t
        self.W = 7 - self.E
        self.now = [self.t, self.S, self.E, self.N, self.W, self.g]
        return self.now

if __name__ == '__main__':
    num = int(input())
    dice_1 = dice(1, 2, 3)
    direc = ['N', 'E', 'W', 'S']
    x = 0
    for _ in range(num-1):
        dice_2 = dice(1, 2, 3)
        for __ in range(1200):
            random.shuffle(direc)
            dice_2.roll(direc[0])
            if [dice_1.dice[dice_1.now[v]-1] for v in range(6)] == [dice_2.dice[dice_2.now[v]-1] for v in range(6)]:
                x += 1
                break
    if x >= 1:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
def sgn(a, b):
    return int(a*b/abs(a*b))

class Dice:
    def __init__(self, numbers):
        self.numbers_dict = {1:numbers[0], 2:numbers[1], 3:numbers[2], -3:numbers[3], -2:numbers[4], -1:numbers[5]}
        self.numbers_ver_dict = {numbers[0]:1, numbers[1]:2,numbers[2]:3,numbers[3]:-3, numbers[4]:-2,numbers[5]:-1}

    # a:top, b:front
    def show_right(self, a, b):
        var_a = self.numbers_ver_dict[a]
        var_b = self.numbers_ver_dict[b]
        if abs(var_a) == 1:
            if abs(var_b) == 2:
                return self.numbers_dict[sgn(var_a,var_b)*3]
            else:
                return self.numbers_dict[-sgn(var_a,var_b)*2]
        elif abs(var_a) == 2:
            if abs(var_b) == 1:
                return self.numbers_dict[-sgn(var_a, var_b)*3]
            else:
                return self.numbers_dict[sgn(var_a,var_b)]
        else:
            if abs(var_b) == 1:
                return self.numbers_dict[sgn(var_a, var_b)*2]
            else:
                return self.numbers_dict[-sgn(var_a,var_b)]

    def exam_equal(self, dice):
        for key in dice.numbers_ver_dict:
            if key not in self.numbers_ver_dict:
                return False
        exam_tuple = ((examin_list[0], examin_list[1]), (examin_list[0], examin_list[2]), (examin_list[0], examin_list[4]),
        (examin_list[0], examin_list[3]), (examin_list[1], examin_list[5]))
        for num in exam_tuple:
            if dice1.show_right(num[0], num[1]) != dice.show_right(num[0], num[1]):
                return False
        return True


if __name__ == '__main__':
    n = int(input())
    examin_list = list(map(int, input().split()))
    dice1 = Dice(examin_list)
    dice = []
    for i in range(n-1):
        dice.append(Dice(list(map(int, input().split()))))
    diff_flag = False
    for d in dice:
        if dice1.exam_equal(d):
            print('No')
            diff_flag = True
            break
    if not diff_flag:
        print('Yes')

Submission status: Accepted

Solution code:
transforms = []
for i, sides in enumerate(((3,1,2,4),(2,0,3,5),(4,0,1,5),(1,0,4,5),(3,0,2,5),(2,1,3,4))):
	for j in range(4):
		r = sides[j:] + sides[:j]
		transforms.append((i, r[1], r[2], r[0], r[3], 5-i))

possibilities = set()
for _ in range(int(input())):
	die = input().split()
	new_possibilities = {tuple(die[t] for t in transform) for transform in transforms}
	if new_possibilities.intersection(possibilities):
		print('No')
		break
	possibilities.update(new_possibilities)
else:
	print('Yes')

Submission status: Accepted

Solution code:
buff = "NNNNWNNNWNNNENNNENNNWNNN"

class Dice:
        num =[ -1 for x in range(6) ]
        def roll(self, d):
                if   d == "N":
                        b = self.num[0]
                        self.num[0] = self.num[1]
                        self.num[1] = self.num[5]
                        self.num[5] = self.num[4]
                        self.num[4] = b
                elif d == "S":
                        b = self.num[0]
                        self.num[0] = self.num[4]
                        self.num[4] = self.num[5]
                        self.num[5] = self.num[1]
                        self.num[1] = b
                elif d == "W":
                        b = self.num[3]
                        self.num[3] = self.num[0]
                        self.num[0] = self.num[2]
                        self.num[2] = self.num[5]
                        self.num[5] = b
                elif d == "E":
                        b = self.num[3]
                        self.num[3] = self.num[5]
                        self.num[5] = self.num[2]
                        self.num[2] = self.num[0]
                        self.num[0] = b
        
        def __init__(self, lst):
                self.num = lst
        
        def print_num(self, m):
                #print(self.num[m])
                return self.num[m]
        
        def return_lst(self):
                return self.num

def isSameDice(D1, D2):
        for d in buff:
                D1.roll(d)
                if D1.return_lst() == D2.return_lst():
                        return True
        return False

N = int(input())
dices = []

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

for i in range(N):
        for j in range(i + 1, N):
                if isSameDice(dices[i], dices[j]):
                        print("No")
                        exit()

print("Yes")

Submission status: Accepted

Solution code:
def rotate(id, l)->list:
    dir = ['S', '', 'WS', 'ES', 'SS', 'N']
    for o in dir[id]:
        l = [ l[int(k)] for k in list(s[o])]
    return l 

def search(j, i):
    lj = a[j]
    li = a[i]
    if len(set(lj) ^ set(li)) == 0: 
        at = 0
        for l in range(6): 
            if lj.count(lj[l]) == 1: 
                at = l
                break
        bt = li.index(lj[at]) 
        lj = rotate(at, lj)
        li = rotate(bt, li)
        for o in 'EEEE':
            lj = [ lj[int(k)] for k in list(s[o]) ]
            if li == lj: return True
    else: return False

s = {'E': '310542', 'W': '215043', 'S': '402351', 'N': '152304'}  # 東西南北
a = []
n = int(input())
i = 0
while i < n:
    a.append(list(map(int, input().split())))
    j = 0
    while j <= i-1: 
        if search(j, i): 
            print('No')
            i = n
            break 
        j+=1
    if i == n-1: print('Yes')
    i+=1

Submission status: Accepted

Solution code:
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 set(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 kaiten(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]
 
        if loc == 'E':
            self.set(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.set(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.set(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.set(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
 
 
    def tansaku(self,top_num,front_num):
 
        self.save = [i for i in range(6)]
        for i in range(len(self.number)):
            self.save[i] = self.number[i]
 
        ret = -1;
 
        for i in range(len(self.order)):
            self.kaiten(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[i]
 
        return ret;
 
    def hyouka(self,b):
        for i in range(len(self.order)):
            self.kaiten(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != b.number[k]: 
                    FLG = False
                    break
            if FLG == True:
                return True
        
        return False
        
 
 
N = int(input())
D = []

for i in range(N):
    table = list(map(int,input().split()))
    dice = Dice()
    dice.set(table[0], table[1], table[2], table[3], table[4], table[5])
    D.append(dice)
    
FLG = True

for i in range(N-1):
    for k in range(i+1,N):
        if D[i].hyouka(D[k]) == True:
            FLG = False
            break

if FLG == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import random
class Dice:
    def __init__(self,surfaceNum):
        self.surface = surfaceNum
        
    def east(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[3], self.surface[0], self.surface[2], self.surface[5]
    def west(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[2], self.surface[5], self.surface[3], self.surface[0]
    def south(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[4], self.surface[0], self.surface[1], self.surface[5]
    def north(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[1], self.surface[5], self.surface[4], self.surface[0]
        
    def printTopSurface(self):
        print(self.surface[0])  
    def printRight(self):
        print(self.surface[2])

diceNum = int(input())
rollCommandList = ["E", "W", "S", "N"]
counter = 1
answer = [0]
surfaceNum = list()
dice = list()
for i in range(diceNum):
    surfaceNum = [int(i) for i in input().split()]
    dice.append(Dice(surfaceNum))
for i in range(diceNum-1):
    for j in range(i+1,diceNum):
        counter = 0
        while True:    
            rollCommand = random.choice(rollCommandList)
            if rollCommand == "E":
                dice[j].east()
            if rollCommand == "W":
                dice[j].west()
            if rollCommand == "S":
                dice[j].south()
            if rollCommand == "N":
                dice[j].north()
            if counter == 100:
                answer.append('Yes')
                #print('{}, {}'.format(i, j))
                break        
            if dice[i].surface == dice[j].surface:
                answer.append('No')
                #print('{}, {}'.format(i, j))
                break
            counter += 1
if answer.count('No') > 0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]
        self.z = [p[1], p[2], p[4], p[3]]
    def roll(self, c):
        if c == 'y':
            self.y.append(self.y.pop(0))
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
            self.z[0] = self.y[1]
            self.z[2] = self.y[3]
        elif c == 'x':
            self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]
            self.z[1] = self.x[1]
            self.z[3] = self.x[3]
        elif c == 'z':
            self.z.append(self.z.pop(0))
            self.x[1] = self.z[1]
            self.x[3] = self.z[3]
            self.y[1] = self.z[0]
            self.y[3] = self.z[2]
    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]
    def same(self, other):
        for _ in range(4):
            if self == other:
                return True
            other.roll('x')
            for _ in range(4):
                if self == other:
                    return True
                other.roll('y')
                for _ in range(4):
                    if self == other:
                        return True
                    other.roll('z')
        return False
    def __eq__(self, other):
        for i in range(1,7):
            if (self.num(i) != other.num(i)):
                return False
        return True



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


yes = all([not dices[0].same(other) for other in dices[1:]])
print('Yes' if yes else 'No')

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]
        self.z = [p[1], p[2], p[4], p[3]]
    def roll(self, c):
        if c == 'y':
            self.y.append(self.y.pop(0))
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
            self.z[0] = self.y[1]
            self.z[2] = self.y[3]
        elif c == 'x':
            self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]
            self.z[1] = self.x[1]
            self.z[3] = self.x[3]
        elif c == 'z':
            self.z.append(self.z.pop(0))
            self.x[1] = self.z[1]
            self.x[3] = self.z[3]
            self.y[1] = self.z[0]
            self.y[3] = self.z[2]
    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]
    def same(self, other):
        for _ in range(4):
            if self == other:
                return True
            other.roll('x')
            for _ in range(4):
                if self == other:
                    return True
                other.roll('y')
                for _ in range(4):
                    if self == other:
                        return True
                    other.roll('z')
        return False
    def __eq__(self, other):
        for i in range(1,7):
            if (self.num(i) != other.num(i)):
                return False
        return True

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

yes = all([not dices[0].same(other) for other in dices[1:]])
print('Yes' if yes else 'No')