Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Dice IV

 Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.

Input

  In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.

Output

  Print "Yes" if given dices are all different, otherwise "No" in a line.

Constraints

$2 \leq n \leq 100$

$0 \leq $ the integer assigned to a face $ \leq 100$

Sample Input 1

3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1

Sample Output 1

No

Sample Input 2 

3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6

Sample Output 2

Yes



Sample input:
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1


Sample output:
No

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.face = {'head':1, 'tail':4, 'left':3, 'right':2, 'above':0, 'below':5}
    
    def roll(self, ch):
        dice = self.dice
        face = self.face
        if ch == 'S':
            tmp = dice[face['head']]
            dice[face['head']] = dice[face['above']]
            dice[face['above']] = dice[face['tail']]
            dice[face['tail']] = dice[face['below']]
            dice[face['below']] = tmp
        elif ch == 'N':
            tmp = dice[face['head']]
            dice[face['head']] = dice[face['below']]
            dice[face['below']] = dice[face['tail']]
            dice[face['tail']] = dice[face['above']]
            dice[face['above']] = tmp
        elif ch == 'W':
            tmp = dice[face['left']]
            dice[face['left']] = dice[face['above']]
            dice[face['above']] = dice[face['right']]
            dice[face['right']] = dice[face['below']]
            dice[face['below']] = tmp
        else:
            tmp = dice[face['left']]
            dice[face['left']] = dice[face['below']]
            dice[face['below']] = dice[face['right']]
            dice[face['right']] = dice[face['above']]
            dice[face['above']] = tmp

    def top(self):
        dice = self.dice
        face = self.face
        return dice[face['above']]
    
    def find_right(self, a, b):
        dice = self.dice
        face = self.face
        order = 'NNNNWNNNWNNNENNNENNNWNNN'
        for ch in order:
            self.roll(ch)
            if dice[face['above']] == a and dice[face['head']] == b:
                break
        return dice[face['right']]

    def equal(self, dice2):
        dice = self.dice
        dice2 = dice2.dice
        tag = False
        order = 'NNNNWNNNWNNNENNNENNNWNNN'
        for ch in order:
            self.roll(ch)
            flag = True
            for i in range(6):
                if dice[i] != dice2[i]:
                    flag = False
                    break
            if flag:
                tag = flag
                break
        return tag

n = int(input())
dices = []
for i in range(n):
    dices.append(Dice([*map(int, input().split())]))
flag = True
for i in range(n):
    if flag != True:
        break
    for j in range(i):
        if dices[i].equal(dices[j]):
            flag = False
            break
print(['No', 'Yes'][flag])

Submission status: Accepted

Solution code:
roll_dict = dict(E = (3, 1, 0, 5, 4, 2), W = (2, 1, 5, 0, 4, 3), S = (4, 0, 2, 3, 5, 1), N = (1, 5, 2, 3, 0, 4))

def judge_dice(dice1s, dice2):
  for i in range(6):
    if dice1s[i][0] == dice2[0] and dice1s[i][5] == dice2[5]:
      str_dice1 = "".join(map(str, dice1s[i]))
      str_dice2 = "".join(map(str, dice2))

      side1 = str_dice1[1:3]+str_dice1[4]+str_dice1[3]
      side1 += side1
      side2 = str_dice2[1:3]+str_dice2[4]+str_dice2[3]
      return side2 in side1
      break
  return False

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

dice1s = []
dice1s.append(dices[0])
judges = [False for i in range(n - 1)]

for i in "EWSN":
  dice = dice1s[0]
  new_dice = []
  for j in range(6):
    new_dice.append(dice[ roll_dict[i][j] ])
  dice1s.append(new_dice)

dice = dice1s[1]
new_dice = []
for i in range(6):
  new_dice.append(dice[ roll_dict["E"][i] ])
dice1s.append(new_dice)

for i in range(n - 1):
  judges[i] = judge_dice(dice1s, dices[i + 1])

if True in judges:
  print("No")
else:
  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:
from copy import deepcopy

class Dice():

    def __init__(self):
        self.E = [4,2,1,6,5,3]
        self.N = [2,6,3,4,1,5]
        self.S = [5,1,3,4,6,2]
        self.W = [3,2,6,1,5,4]
        self.number = list(map(int,input().split()))
        self.order = "NNNNWNNNWNNNENNNENNNWNNN"

    def rotate(self,order):
        tmp = deepcopy(self.number)
        if order == "E":
            for i in range(6):
                self.number[i] = tmp[self.E[i]-1]
        elif order == "N":
            for i in range(6):
                self.number[i] = tmp[self.N[i]-1]
        elif order == "S":
            for i in range(6):
                self.number[i] = tmp[self.S[i]-1]
        elif order == "W":
            for i in range(6):
                self.number[i] = tmp[self.W[i]-1]
    
    def sidenum(self,x,y):
        for i in self.order:
            if self.number[1] == y and self.number[0] == x:
                print(self.number[2])
                break
            else:
                self.rotate(i)
    
    def check(self,other):
        flag = False
        for i in self.order:
            self.rotate(i)
            if self.number == other.number:
                flag = True
                break
        return flag

if __name__ == "__main__":
    n = int(input())
    dices = []
    for i in range(n):
        tmp = Dice()
        dices.append(tmp)
    flag = True
    for i in range(n-1):
        for j in range(i+1,n):
            if dices[i].check(dices[j]):
                flag = False
                break
    if flag:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:

class dice:
    def __init__(self,dice):
        self.dice = dice

    def roll_n(self):
        d = self.dice
        self.dice = [d[1],d[5],d[2],d[3],d[0],d[4]]

    def roll_e(self):
        d = self.dice
        self.dice = [d[3],d[1],d[0],d[5],d[4],d[2]]

    def roll_s(self):
        d = self.dice
        self.dice = [d[4],d[0],d[2],d[3],d[5],d[1]]
    
    def roll_w(self):
        d = self.dice
        self.dice = [d[2],d[1],d[5],d[0],d[4],d[3]]

    def top(self):
        return self.dice[0]

    def roll(self,command):
        if command=='N':self.roll_n()
        if command=='E':self.roll_e()
        if command=='S':self.roll_s()
        if command=='W':self.roll_w()

    def same(self,b):
        com1 = 'SSSWSSSE'
        com2 = 'WWWW'
        for c in com1:
            if self.dice[1]==b.dice[1]:break
            if c=='E':return False
            b.roll(c)
        for c in com2:
            if self.dice==b.dice:return True
            b.roll(c)
        return False

def main():
    n = int(input())
    dices = []
    for _ in range(n):
        dices.append(dice(list(map(int,input().split()))))
    for i in range(n):
        for j in range(i+1,n):
            if dices[i].same(dices[j]):
                print('No')
                return
    print('Yes') 

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def dice(d, i, n):
    if n == 1:
        return d[i][1] + d[i][2] + d[i][4] + d[i][3]
    if n == 2:
        return d[i][0] + d[i][3] + d[i][5] + d[i][2]
    if n == 3:
        return d[i][0] + d[i][1] + d[i][5] + d[i][4]
    if n == 4:
        return d[i][0] + d[i][4] + d[i][5] + d[i][1]
    if n == 5:
        return d[i][0] + d[i][2] + d[i][5] + d[i][3]
    if n == 6:
        return d[i][1] + d[i][3] + d[i][4] + d[i][2]

answer = 'Yes'
n = int(input())
d = [0]*n
for i in range(n):
    d[i] = input().split()
    
for j in range(n-1):
    for k in range(j+1, n):
        for l in range(6):
            if d[j][0]==d[k][l] and d[j][5]==d[k][5-l] and dice(d,k,l+1)in dice(d,j,1)*2:
                answer = 'No'
                
print(answer)

Submission status: Accepted

Solution code:
import random 

def dice_move(a,s): 

    if s=="E": 

        return [a[3],a[1],a[0],a[5],a[4],a[2]] 

    elif s=="S": 

        return [a[4],a[0],a[2],a[3],a[5],a[1]] 

    elif s=="W": 

        return [a[2],a[1],a[5],a[0],a[4],a[3]] 

    elif s=="N": 

        return [a[1],a[5],a[2],a[3],a[0],a[4]] 

     

n=int(input()) 

a=[list(map(int,input().split())) for _ in range(n)] 

h=("N","W","S","E") 

judge=[True]*n 

cnt=0 

for i in range(30000): 

    num=random.randrange(4) 

    a[0]=dice_move(a[0],h[num]) 

    for i in range(1,n): 

        if judge[i] and a[0]==a[i]: 

            cnt+=1 

            judge[i]=False 

print("Yes" if cnt==0 else "No")

Submission status: Accepted

Solution code:
class Dice():
    
    #入力
    def __init__(self,d1,d2,d3,d4,d5,d6):
        self.d1=d1
        self.d2=d2
        self.d3=d3
        self.d4=d4
        self.d5=d5
        self.d6=d6
    
    #回転
    def roll(self,c):
        if c=='N':
            self.d1,self.d5,self.d6,self.d2=self.d2,self.d1,self.d5,self.d6
        elif c=='S':
            self.d1,self.d5,self.d6,self.d2=self.d5,self.d6,self.d2,self.d1
        elif c=='E':
            self.d1,self.d3,self.d6,self.d4=self.d4,self.d1,self.d3,self.d6
        elif c=='W':
            self.d1,self.d3,self.d6,self.d4=self.d3,self.d6,self.d4,self.d1
        elif c=='R':
            self.d2,self.d3,self.d5,self.d4=self.d4,self.d2,self.d3,self.d5
        elif c=='L':
            self.d2,self.d3,self.d5,self.d4=self.d3,self.d5,self.d4,self.d2
    
    #上の面に来る最小値
    def minnum(self):
        return min(self.d1,self.d2,self.d3,self.d4,self.d5,self.d6)
    
    #前の面に来る2つめに小さい値
    def min2num(self):
        return min(self.d2,self.d3,self.d4,self.d5,self.d6)
    
    #2つめが下の面に来るときに前の面に来る3番目に小さい値
    def min3num(self):
        return min(self.d2,self.d3,self.d4,self.d5)
    
    #回転動作    
    def rolling(self):
        m=self.minnum()
        if m==self.d3:
            self.roll('W')
        elif m==self.d6:
            self.roll('E')
            self.roll('E')
        elif m==self.d4:
            self.roll('E')
        elif m==self.d2:
            self.roll('N')
        elif m==self.d5:
            self.roll('S')
        m=self.min2num()
        if m==self.d3:
            self.roll('L')
        elif m==self.d5:
            self.roll('L')
            self.roll('L')
        elif m==self.d4:
            self.roll('R')
        elif m==self.d6:
            m=self.min3num()
            if m==self.d3:
                self.roll('L')
            elif m==self.d5:
                self.roll('L')
                self.roll('L')
            elif m==self.d4:
                self.roll('R')
    
    #値をリストで返す        
    def returnlist(self):
        l=[self.d1,self.d2,self.d3,self.d4,self.d5,self.d6]
        return l


n=int(input())
check=True
l=[]

#ダイスの入力
for i in range(n):
    a,b,c,d,e,f=map(int,input().split())
    D=Dice(a,b,c,d,e,f)
    D.rolling()
    
    #今までのダイスと比較
    for dice in l:
        if dice==D.returnlist():
            check=False
    
    #リストに追加        
    l.append(D.returnlist())
    
if check:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = "NNNNWNNNWNNNENNNENNNWNNN"

    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5

    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == "E":
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == "N":
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == "S":
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == "W":
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
    
    def query(self,top_num,front_num):
        self.save_data =[i for i in range(6)]

        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        ret = -1
        
        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break

        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]
        
        return ret
    def get_Top(self):
        return self.number[0]
    
    def equals(self,another):
        ret = False
        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG =False
                    break
            if FLG :
                return True
        return ret
        
N = int(input())
DICE =[]
for i in range(N):
    
    table = list(map(int,input().split()))
    tmp_dice =Dice()
    tmp_dice.setNumber(table[0],table[1],table[2],table[3],table[4],table[5])
    DICE.append(tmp_dice)
FLG = True

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

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

Submission status: Accepted

Solution code:
import itertools

def get_dice():
    input_data = input().split(" ")
    items = [int(cont) for cont in input_data]
    keys = ['T', 'S', 'E', 'W', 'N', 'B']
    return dict(zip(keys, items))

def rot_dice(rot, dice):
    if rot == "N":
        keys = ['T', 'S', 'B', 'N']
        items = dice['S'], dice['B'], dice['N'], dice['T']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "S":
        keys = ['T', 'S', 'B', 'N']
        items = dice['N'], dice['T'], dice['S'], dice['B']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "E":
        keys = ['T', 'E', 'B', 'W']
        items = dice['W'], dice['T'], dice['E'], dice['B']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "W":
        keys = ['T', 'E', 'B', 'W']
        items = dice['E'], dice['B'], dice['W'], dice['T']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "R":
        keys = ['N', 'W', 'S', 'E']
        items = dice['E'], dice['N'], dice['W'], dice['S']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)
    if rot == "L":
        keys = ['N', 'W', 'S', 'E']
        items = dice['W'], dice['S'], dice['E'], dice['N']
        new_dice = dict(zip(keys, items))
        dice.update(new_dice)

def search_right_surf(conds, dice):
    a, b = conds
    a_key = [k for k, v in dice.items() if v == a]
    b_key = [k for k, v in dice.items() if v == b]
    key_list = a_key + b_key

    part_st = ''.join(key_list)

    def search(part_st):
        if part_st in "TNBST":
            return "W"

        if part_st in "TSBNT":
            return "E"

        if part_st in "TEBWT":
            return "N"

        if part_st in "TWBET":
            return "S"

        if part_st in "NESWN":
            return "B"

        if part_st in "NWSEN":
            return "T"

    target_key = search(part_st)
    print(dice[target_key])

def search_top_surf(top_surf, dice):

    dice2_surf, *_ = [k for k, v in dice.items() if v == top_surf]

    if dice2_surf == 'N':
        rot_dice("S", dice)

    if dice2_surf == 'B':
        controls = list("SS")
        for i in controls:
            rot_dice(i, dice)
    if dice2_surf == 'S':
        controls = list("N")
        for i in controls:
            rot_dice(i, dice)
    if dice2_surf == 'W':
        controls = list("E")
        for i in controls:
            rot_dice(i, dice)
    if dice2_surf == 'E':
        controls = list("W")
        for i in controls:
            rot_dice(i, dice)

def search_flont_surf(flont_surf, dice):

    dice2_surf, *_ = [k for k, v in dice.items() if v == flont_surf]

    if dice2_surf == 'E':
        controls = list("R")
        for i in controls:
            rot_dice(i, dice)

    if dice2_surf == 'S':
        controls = list("RR")
        for i in controls:
            rot_dice(i, dice)

    if dice2_surf == 'W':
        rot_dice("L", dice)

def perfect_rot_compare(dice1, dice2):

    def compare_dice(dice1, dice2):
        if dice1 == dice2:
            return True

    comb = ["N", "S", "E", "W", "R", "L"]
    tups = list()
    for i in range(6):
        tups.append(itertools.combinations(comb, i))

    if compare_dice(dice1, dice2):
        return True

    for commands in itertools.chain.from_iterable(tups):
        for command in commands:
            rot_dice(command, dice2)
            if compare_dice(dice1, dice2):
                return True
    return False

def compare_many_dices(dice_list):
    dice1 = dice_list.pop(0)
    for dice2 in dice_list:
        if perfect_rot_compare(dice1, dice2):
            return True
    return False


def q1():

    dice = get_dice()
    controls = list(input())
    for i in controls:
        rot_dice(i, dice)
    print(dice["T"])

def q2():

    dice = get_dice()
    a = input()
    repeater = int(a)

    for neee in range(repeater):
        control_input = input().split(" ")
        conds = [int(i) for i in control_input]
        search_right_surf(conds, dice)

def q3():
    dice1 = get_dice()
    dice2 = get_dice()

    if perfect_rot_compare(dice1, dice2):
        print("Yes")
    else:
        print("No")

def q4():
    inp = input()
    dice_num = int(inp)
    dice_list = list()
    for i in range(dice_num):
        dice_list.append(get_dice())

    if compare_many_dices(dice_list):
        print("No")

    else:
        print("Yes")

q4()

Submission status: Accepted

Solution code:
def create_dice(nums):
    a, b, c, d, e, f = nums
    ver = [a, b, f, e]
    hor = [b, c, e, d]
    return Dice(ver, hor, nums)


class Dice:
    def __init__(self, v, h, r):
        self.ver = v
        self.hor = h
        self.raw = r

    def __str__(self):
        l = [self.ver[0], self.ver[1], self.hor[1],
             self.hor[3], self.ver[3], self.ver[2]]
        s = map(str, l)
        return "".join(s)

    def v2h(self):
        self.hor[0] = self.ver[1]
        self.hor[2] = self.ver[3]

    def h2v(self):
        self.ver[1] = self.hor[0]
        self.ver[3] = self.hor[2]

    def roll(self, direction):
        if direction == 'N':
            tmp1 = self.ver[0]
            tmp2 = self.ver[1:]
            self.ver = tmp2 + [tmp1]
            self.v2h()
        elif direction == 'S':
            tmp1 = self.ver[-1]
            tmp2 = self.ver[:-1]
            self.ver = [tmp1] + tmp2
            self.v2h()
        elif direction == 'E':
            tmp1 = self.hor[0]
            tmp2 = self.hor[1:]
            self.hor = tmp2 + [tmp1]
            self.h2v()
        elif direction == 'W':
            tmp1 = self.hor[-1]
            tmp2 = self.hor[:-1]
            self.hor = [tmp1] + tmp2
            self.h2v()


def match_dice(d1, d2):
    if str(d1) == str(d2):
        return True
    return False


def test(d1, d2):
    s1 = set(d1.raw)
    s2 = set(d2.raw)
    if s1 != s2:
        return False

    for v in range(2):
        if match_dice(d1, d2):
            return True

        for h in range(3):
            if match_dice(d1, d2):
                return True
            d2.roll("E")

        d2.roll("N")

    for v in range(2):
        if match_dice(d1, d2):
            return True

        for h in range(3):
            if match_dice(d1, d2):
                return True
            d2.roll("E")

        d2.roll("S")

    for v in range(2):
        if match_dice(d1, d2):
            return True

        for h in range(3):
            if match_dice(d1, d2):
                return True
            d2.roll("E")

        d2.roll("N")

    return False


def check(dices):
    for i in range(len(dices) - 1):
        for j in range(i + 1, len(dices)):
            t = test(dices[i], dices[j])
            if t:
                return True

    return False

data_count = int(input())
dices = []
for _ in range(data_count):
    s = list(map(int, input().split(" ")))
    d = create_dice(s)
    dices.append(d)

result = check(dices)
if not result:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

    def setNum(self, n0, n1, n2, n3, n4, n5):
        self.d[0], self.d[1], self.d[2], self.d[3], self.d[4], self.d[5] = (
            n0,
            n1,
            n2,
            n3,
            n4,
            n5,
        )

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

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

flag = False
for i in range(n - 1):
    for j in range(i + 1, n):
        for k in list("NNNNWNNNWNNNENNNENNNWNNN"):
            dices[i].roll(k)
            if dices[i].d == dices[j].d:
                flag = True
if flag:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import random
class Dice:
    def __init__(self,top,front,right,left,back,bottom):
        self.top, self.bottom=top,bottom
        self.right, self.left=right,left
        self.front, self.back=front,back
    def turn(self,order):
        if order=="N":
            self.top,self.front,self.bottom,self.back=self.front,self.bottom,self.back,self.top
        if order=="S":
            self.top,self.front,self.bottom,self.back=self.back,self.top,self.front,self.bottom
        if order=="E":
            self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom
        if order=="W":
            self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top
def same(a,b):
    if ((a.top,a.bottom,a.right,a.left,a.front,a.back)==(b.top,b.bottom,b.right,b.left,b.front,b.back)):
        return True
    else:
        return False
n=input()
dicelist=[]
dice=[]
for i in range(n):
    dicelist.append(map(int,raw_input().split()))
for i in range(n):
    dice.append(Dice(dicelist[i][0],dicelist[i][1],dicelist[i][2],dicelist[i][3],dicelist[i][4],dicelist[i][5]))
flg=0
for i in range(1,n):
    if flg==1:
        break
    for j in range(1000):
        if flg==1:
            break
        d="NSWE"[random.randint(0,3)]
        dice[i].turn(d)
        for k in range(i):
            if same(dice[k],dice[i]):
                print "No"
                flg=1
                break
if flg==0:
    print "Yes"

Submission status: Accepted

Solution code:
import copy


def move(lon, lat, news):
    target, other, pop_index, insert_index = lon, lat, 0, 3
    if news == "E" or news == "W":
        target, other = lat, lon
    if news == "S" or news == "W":
        pop_index, insert_index = 3, 0
    target.insert(insert_index, target.pop(pop_index))
    other[0], other[2] = target[0], target[2]


def set_upper(lon, lat, upper):
    news = "N" if upper in lon else "E"
    while lon[0] != upper:
        move(lon, lat, news)


def rotate(lon, lat, com):
    if com == "R":
        lon[1], lat[1], lon[3], lat[3] = lat[3], lon[1], lat[1], lon[3]
    elif com == "L":
        lon[1], lat[1], lon[3], lat[3] = lat[1], lon[3], lat[3], lon[1]


def compare(val1, val2):
    lon2, lat2 = copy.copy(longitude), copy.copy(latitude)
    for u in range(6):
        set_upper(lon2, lat2, u)
        for f in range(4):
            rotate(lon2, lat2, "R")
            if False not in map(lambda x1, x2: val1[x1] == val2[x2], longitude + latitude, lon2 + lat2):
                return True
    return False


longitude = [0, 1, 5, 4]
latitude = [0, 3, 5, 2]
# values = input().split()
# newses = input()
# for c in newses:
#     move(longitude, latitude, c)
# print(values[longitude[0]])

# values = input().split()
# n = int(input())
# for i in range(n):
#     x, y = map(lambda z: values.index(z), input().split())
#     lon_work, lat_work = copy.copy(longitude), copy.copy(latitude)
#     set_upper(lon_work, lat_work, x)
#     while y != lon_work[1]:
#         rotate(lon_work, lat_work, "R")
#     print(values[lat_work[3]])

# values1 = input().split()
# values2 = input().split()
# print("Yes" if compare(values1, values2) else "No")

values = []
n = int(input())
for i in range(n):
    values.append(input().split())
value1, *tail = values
while tail:
    for value2 in tail:
        if compare(value1, value2):
            print("No")
            exit()
    head, *tail = tail
print("Yes")

Submission status: Accepted

Solution code:
import random

class dice:
    def __init__(self, nums=[0]*6):
        self.top = nums[0]
        self.front = nums[1]
        self.right = nums[2]
        self.left  = nums[3]
        self.back = nums[4]
        self.bottom = nums[5]
    
    def set_nums(self, nums):
        self.top = nums[0]
        self.front = nums[1]
        self.right = nums[2]
        self.left  = nums[3]
        self.back = nums[4]
        self.bottom = nums[5]
    
    def roll(self, dr):
        if dr==0:#North
            self.top, self.front, self.bottom, self.back = self.front, self.bottom, self.back, self.top
        elif dr==1:#South
            self.top, self.front, self.bottom, self.back = self.back, self.top, self.front, self.bottom
        elif dr==2:#West
            self.top, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.top
        elif dr==3:#East
            self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        
    def check_same(self, d2):
        if (self.top == d2.top and self.right == d2.right and self.bottom == d2.bottom and self.left == d2.left and self.front == d2.front and self.back == d2.back):
            return True
        else:
            return False
    
    def check(self, d2):
        trial = 0
        while trial<100:
            if self.check_same(d2):
                return True
            else:
                self.roll(random.randint(0,3))
                trial += 1
        return False

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

flg = 0
for i in range(n):
    if flg:
        break
    for j in range(i+1,n):
        if ds[i].check(ds[j]):
            flg = 1

if flg:
    print('No')
else:
    print('Yes')