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

"""
Spyderエディタ

これは一時的なスクリプトファイルです
"""

class Dice():
    
    
    
    

    
    
    
    
    
    def __init__(self, nums):
        self.pos = nums
    
    def rot_E(self):
        e = self.pos
        self.pos = [e[3], e[1], e[0], e[5], e[4], e[2]]

    def rot_W(self):
        e = self.pos
        self.pos = [e[2], e[1], e[5], e[0], e[4], e[3]]

    def rot_S(self):
        e = self.pos
        self.pos = [e[4], e[0], e[2], e[3], e[5], e[1]]

    def rot_N(self):
        e = self.pos
        self.pos = [e[1], e[5], e[2], e[3], e[0], e[4]]
        
    def rot_CW(self):
        e = self.pos
        self.pos = [e[0], e[2], e[4], e[1], e[3], e[5]]

    def rot_CCW(self):
        e = self.pos
        self.pos = [e[0], e[3], e[1], e[4], e[2], e[5]]

    def rot_180(self):
        self.rot_CW()
        self.rot_N()
        self.rot_W()

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

    def face(self):
        return self.pos[1]

    def right(self, tf=None):
        

        if tf == None:
            print(self.pos[2])
            return

        t = self.pos.index(tf[0])  
        f = self.pos.index(tf[1])  
        
        
        dr = [(1,2,4,3),(0,3,5,2),(0,1,5,4),(0,4,5,1),(0,2,5,3),(1,3,4,2)]
        r = (dr[t].index(f) + 1) % 4
        print(self.pos[dr[t][r]])
        return

    def left(self):
        print(self.pos[3])
        return

    def back(self):
        print(self.pos[4])
        return

    def bottom(self):
        print(self.pos[5])
        return

    def fit_top(self,x):
        if x == 0:
            self.rot_S()
            self.rot_S()
        if x == 1:
            self.rot_N()
        if x == 3:
            self.rot_axis()
            self.rot_axis()
        if x == 4:
            self.rot_S()
        if x == 5:
            self.rot_axis()
            self.rot_axis()
            self.rot_axis()

    def check(self, d):
        f = False
        
        
        def rotate4():
            nonlocal f
            for _ in range(4):
                if self.pos == d.pos:
                    f = True
                self.rot_CW()

        rotate4()
        
        d.rot_N()
        rotate4()
        d.rot_S()
        
        d.rot_W()
        rotate4()
        d.rot_E()
        
        d.rot_S()
        rotate4()
        d.rot_N()
        
        d.rot_E()
        rotate4()
        d.rot_W()
        
        d.rot_S()
        d.rot_S()
        rotate4()
        
        return f
    
    
    def position(self, x):
        return self.pos.index(x)
    





def main():

    f = False

    n = int(input())
    
    ds = []
    for i in range(n):
        dt = Dice([int(x) for x in input().split()])
        ds.append(dt)
    
        for j in range(i):
            if dt.check(ds[j]):
                f = True

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

def main2():
    d1 = Dice([6, 2, 4, 3, 5, 1])
    d2 = Dice([6, 5, 4, 3, 2, 1])    
    d3 = Dice([1,2,3,4,5,6])
    print(d1.check(d2))
    print(d1.check(d3))
    print(d2.check(d3))
    
main()

Solution (Python):
class dice():
    def __init__(self,labels):
        self.l=labels
    def check(self,d2):
        l1=self.l
        for a in range(4):
            l1[1],l1[2],l1[3],l1[4]=l1[2],l1[4],l1[1],l1[3]
            for b in range(4):
                l1[0],l1[3],l1[2],l1[5]=l1[2],l1[0],l1[5],l1[3]
                for c in range(4):
                    l1[0],l1[1],l1[5],l1[4]=l1[4],l1[0],l1[1],l1[5]
                    if l1==d2.l:
                        return True
                        break
"""
a=dice([int(i) for i in input().split()])
b=dice([int(i) for i in input().split()])
print("Yes" if a.check(b) else "No")

"""
l=[]
n=int(input())
for _ in range(n):
    l.append(dice([int(i) for i in input().split()]))
han=False
for x in range(n-1):
    for i in range(x+1,n):
        if l[x].check(l[i]):
            han=True
            break
print("No" if han else "Yes")

Solution (Python):
class Dice:
    def __init__(self, lst):
        self.a = lst[0]
        self.b = lst[1]
        self.c = lst[2]
        self.d = lst[3]
        self.e = lst[4]
        self.f = lst[5]
        
    def roll(self, orders):
        for order in orders:
            if order=='W':
                tmp = self.a
                self.a = self.c
                self.c = self.f
                self.f = self.d
                self.d = tmp
            elif order=='E':
                tmp = self.a
                self.a = self.d
                self.d = self.f
                self.f = self.c
                self.c = tmp
            elif order=='S':
                tmp = self.a
                self.a = self.e
                self.e = self.f
                self.f = self.b
                self.b = tmp
            elif order=='N':
                tmp = self.a
                self.a = self.b
                self.b = self.f
                self.f = self.e
                self.e = tmp


    
    def equal(self, dice_):
        if (self.a==dice_.a and
            self.b==dice_.b and
            self.c==dice_.c and
            self.d==dice_.d and
            self.e==dice_.e and
            self.f==dice_.f
           ):
            return True
        else:
            return False
       
            
import random
import itertools
if __name__ == '__main__':
    n = int(input())
    lsts = [[int(x) for x in input().split()] for _ in range(n)]
    ans = 'Yes'
    for lst in itertools.combinations(lsts, 2):
        dice1 = Dice(lst[0])
        dice2 = Dice(lst[1])
        for direction in 'EEENEEENEEESEEESEEENEEEN':
            if dice1.equal(dice2):
                ans='No'
                break
            else:
                dice1.roll(direction)
    print(ans)

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

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

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

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

Solution (Python):

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

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

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

Solution (Python):
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)
    
    
    def min2num(self):
        return min(self.d2,self.d3,self.d4,self.d5,self.d6)
    
    
    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")

Solution (Python):
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


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 equals(self,another):

        ret = False;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return ret



num_dice = int(input())
DICE = []

for i in range(num_dice):
    table = list(map(int,input().split()))
    tmp_dice = Dice()
    tmp_dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])
    DICE.append(tmp_dice)

FLG = True

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


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

Solution (Python):

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

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

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

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