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):
class Dice(object):
    def __init__(self, nums):
        from collections import deque
        self.ns = deque([nums[4], nums[0], nums[1]])
        self.we = deque([nums[3], nums[0], nums[2]])
        self.bk = deque([nums[5]])

    def __str__(self):
        return str({"ns": self.ns, "we": self.we, "bk": self.bk})

    def operation(self, o):
        if o == "N":
            self.n()
        elif o == "S":
            self.s()
        elif o == "W":
            self.w()
        elif o == "E":
            self.e()
        else:
            raise BaseException("invalid", o)

    def n(self):
        self.ns.append(self.bk.popleft())
        self.bk.append(self.ns.popleft())
        self.we[1] = self.ns[1]

    def s(self):
        self.ns.appendleft(self.bk.pop())
        self.bk.appendleft(self.ns.pop())
        self.we[1] = self.ns[1]

    def w(self):
        self.we.append(self.bk.popleft())
        self.bk.append(self.we.popleft())
        self.ns[1] = self.we[1]

    def e(self):
        self.we.appendleft(self.bk.pop())
        self.bk.appendleft(self.we.pop())
        self.ns[1] = self.we[1]

    def rotate_right(self):
        tmp = self.ns
        tmp.reverse()
        self.ns = self.we
        self.we = tmp

    def fit_top_s(self, top, s):
        if not (top in self.ns or top in self.we or top in self.bk) or not (
                s in self.ns or s in self.we or s in self.bk):
            return False
        while self.get_top() != top:
            if top in self.ns:
                self.n()
            elif top in self.we:
                self.w()
            else:
                self.n()
                self.n()
        count = 0
        while self.get_s() != s and count < 4:
            self.rotate_right()
            count += 1
        if count == 4:
            return False
        else:
            return True

    def get_top(self):
        return self.ns[1]

    def get_s(self):
        return self.ns[2]

    def get_e(self):
        return self.we[2]


def resolve():
    n = int(input())
    chk = {}
    for i in range(n):
        nums = [int(i) for i in input().split()]
        key = "-".join([str(i) for i in sorted(nums)])
        if key in chk.keys():
            chk[key]["nums"].append(nums)
            chk[key]["count"] += 1
        else:
            chk[key] = {}
            chk[key]["nums"] = [nums]
            chk[key]["count"] = 1
    for value in chk.values():
        if value["count"] > 1:
            dc = Dice(value["nums"][0])
            top = dc.get_top()
            s = dc.get_s()
            chks = {str(dc)}
            for num in value["nums"][1:]:
                dc = Dice(num)
                dc.fit_top_s(top, s)
                chks.add(str(dc))
            if len(chks) != value["count"]:
                print("No")
                return
    else:
        print("Yes")


resolve()

Solution (Python):
class Dice:
    def __init__(self, top, front, right, left, rear, bottom):
        self.top = top
        self.front = front
        self.right = right
        self.left = left
        self.rear = rear
        self.bottom = bottom
    def print(self):
        '''print top of dice'''
        print(self.top)
    def north(self):
        self.top, self.front, self.bottom, self.rear = \
            self.front, self.bottom, self.rear, self.top
    def south(self):
        self.top, self.front, self.bottom, self.rear = \
            self.rear, self.top, self.front, self.bottom
    def east(self):
        self.top, self.right, self.bottom, self.left = \
            self.left, self.top, self.right, self.bottom
    def west(self):
        self.top, self.right, self.bottom, self.left = \
            self.right, self.bottom, self.left, self.top
    def clockwise(self):
        self.front, self.right, self.rear, self.left = \
            self.right, self.rear, self.left, self.front
    def ccw(self):
        self.front, self.right, self.rear, self.left = \
            self.left, self.front, self.right, self.rear
    def __eq__(self, other):
        
        pattern = ['', 'N', 'N', 'N', 'E', 'EE']
        tmp = Dice(other.top, other.front, other.right, other.left, other.rear, other.bottom)
        for i in pattern:
            if i == 'N':
                tmp.north()
            elif i == 'E':
                tmp.east()
            elif i == 'EE':
                tmp.east()
                tmp.east()
            else:
                pass
            if self.top != tmp.top or self.bottom != tmp.bottom:
                continue
            for j in range(4):
                if self.front == tmp.front and self.right == tmp.right and \
                   self.rear == tmp.rear and self.left == tmp.left:
                    return True
                tmp.clockwise()
        return False

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

for i in range(n-1):
    for j in range(i+1, n):
        if dice[i] == dice[j]:
            print('No')
            break
    else:
        continue
    break
else:
    print('Yes')

Solution (Python):
class Dice():
    directions = "EEENEEENEEESEEESEEENEEEN"

    def __init__(self, lst):
        self.top = lst[0]
        self.front = lst[1]
        self.right = lst[2]
        self.left = lst[3]
        self.back = lst[4]
        self.bottom = lst[5]

    def rotate(self, direction):
        if direction == "E":
            self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        if direction == "N":
            self.top, self.back, self.bottom, self.front = self.front, self.top, self.back, self.bottom
        if direction == "S":
            self.top, self.front, self.bottom, self.back = self.back, self.top, self.front, self.bottom
        if direction == "W":
            self.top, self.left, self.bottom, self.right = self.right, self.top, self.left, self.bottom

    def fit_top_front(self, num_top, num_front):
        for direction in Dice.directions:
            if self.top == num_top and self.front == num_front:
                break
            self.rotate(direction)

    def fit_all(self, dice):
        for direction in Dice.directions:
            if self.top == dice.top and self.front == dice.front and self.right == dice.right and self.left == dice.left and self.back == dice.back and self.bottom == dice.bottom:
                return True
            self.rotate(direction)
        return False


def compare(lst, dice):
    for direction in Dice.directions:
        if lst[0] == dice.top and lst[1] == dice.front and lst[2] == dice.right and lst[3] == dice.left and lst[4] == dice.back and lst[5] == dice.bottom:
            return True
        dice.rotate(direction)
    return False


def main():
    num_dices = int(input())  
    dices = []  
    dices.append(list(map(int, input().split())))  
    for _ in range(num_dices - 1):
        label_dice = list(map(int, input().split()))
        dice = Dice(label_dice)
        for i in range(len(dices)):
            result = compare(dices[i], dice)
            if result == True:
                print("No")
                return 0
        dices.append(label_dice)
    print("Yes")


if __name__ == "__main__":
    main()

Solution (Python):
class _Dice:
    
    def __init__(self, nums):
        self.nums = list(nums)
        
    @property
    def top(self):
        return self.nums[0]
        
    def _shift(self, *pairs):
        for pair in pairs:
            num = self.nums[pair[0]]
            self.nums[pair[0]] = self.nums[pair[1]]
            self.nums[pair[1]] = num
            
    def get_matches(self, num):
        return [i for i, m in enumerate(self.nums) if m == num]
            
    def go(self, opes:str):
        for ope in opes:
            if ope == "N":
                self.go_north()
            elif ope == "E":
                self.go_east()
            elif ope == "W":
                self.go_west()
            else:
                self.go_south()
                
    def go_top(self, index):
        
        if index == 1:
            self.go_north()
        elif index == 2:
            self.go_west()
        elif index == 3:
            self.go_east()
        elif index == 4:
            self.go_south()
        elif index == 5:
            self.go_north()
            self.go_north()
            
    def go_ahead(self, index):

        if index == 2:
            self.go_cw()
        elif index == 4:
            self.go_cw()
            self.go_cw()
        elif index == 3:
            self.go_ccw()
            
        
    def go_north(self):
        self._shift((0, 1), (1, 5), (5, 4))
        
    def go_east(self):
        self._shift((0, 3), (3, 5), (5, 2))
        
    def go_west(self):
        self._shift((0, 2), (2, 5), (5, 3))
        
    def go_south(self):
        self._shift((0, 4), (4, 5), (5, 1))
        
    def go_ccw(self):
        self._shift((3, 4), (4, 2), (2, 1))
        
    def go_cw(self):
        self._shift((3, 1), (1, 2), (2, 4))
        
        
class Dice(_Dice):
    
    @classmethod
    def isequal(cls, a:_Dice, b:_Dice):
                
        a_clone = a.nums.copy()
        for top in a.get_matches(b.nums[0]):
            a.go_top(top)
            a_top_clone = a.nums.copy()
            for ahead in a.get_matches(b.nums[1]):
                a.go_ahead(ahead)
                
                for i, j in zip(a.nums, b.nums):
                    if i != j:
                        break
                else:
                    return True
                
                a.nums = a_top_clone.copy()
                
            a.nums = a_clone.copy()
            
        else:
            return False
        
def check(dices):
    for i, dice_A in enumerate(dices):
        if i == len(dices) - 1:
            break
        
        for dice_B in dices[i + 1:]:
            if Dice.isequal(dice_A, dice_B):
                return False
        
    return True
        

count = int(input())
dices = [Dice(map(int, input().split())) for _ in range(count)]
print("Yes" if check(dices) else "No")

Solution (Python):
class Dice():
    def __init__(self):
        self.nums = list(range(6))
        self.work = list(range(6))

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

    def rotate(self, cmd):
        for i in range(6):
            
            self.work[i] = self.nums[i]

        if cmd == 'N':
            self.set_nums(self.work[1], self.work[5], self.work[2], self.work[3], self.work[0], self.work[4])
        elif cmd == 'S':
            self.set_nums(self.work[4], self.work[0], self.work[2], self.work[3], self.work[5], self.work[1]),
        elif cmd == 'E':
            self.set_nums(self.work[3], self.work[1], self.work[0], self.work[5], self.work[4], self.work[2])
        else:
            self.set_nums(self.work[2], self.work[1], self.work[5], self.work[0], self.work[4], self.work[3])

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

    def right(self, top, front):
        
        if top == 1:
            return [3,5,2,4][front-2]
        elif top == 6:
            return [4,2,5,3][front-2]
        elif top == 2:
            
            return [4,0,1,6,0,3][front-1]
        elif top == 5:
            
            return [3,0,6,1,0,4][front-1]
        elif top == 3:
            
            return [2,6,0,0,1,5][front-1]
        elif top == 4:
            
            return [5,1,0,0,6,2][front-1]
        else:
            pass

    def rolls(self):
        
        return [self.nums[i] for i in range(6)]


import random


n = int(input())
nums = [[int(arg) for arg in input().split()] for _ in range(n)]
dices = [Dice() for _ in range(n)]
for i in range(n):
    dices[i].set_nums(*nums[i])

master_roll = dices.pop(0).rolls()
results = []
for dice in dices:
    for i in range(1000):
        cmd = ['N', 'S', 'E', 'W'][random.randint(0,3)]
        dice.rotate(cmd)
        dice_roll = dice.rolls()
        if all([master_roll[i] == dice_roll[i] for i in range(6)]):
            results.append(0)
            break
print('Yes' if len(results) == 0 else 'No')

Solution (Python):
import itertools
import copy

class Dice:
    def __init__(self,d1,d2,d3,d4,d5,d6):
        self.dice = [d1,d2,d3,d4,d5,d6]
    def turn(self,dir):
        if dir == 'S':
            self.dice = [self.dice[4],self.dice[0],self.dice[2],self.dice[3],self.dice[5],self.dice[1]]
        if dir == 'N':
            self.dice = [self.dice[1],self.dice[5],self.dice[2],self.dice[3],self.dice[0],self.dice[4]]
        if dir == 'W':
            self.dice = [self.dice[2],self.dice[1],self.dice[5],self.dice[0],self.dice[4],self.dice[3]]
        if dir == 'E':
            self.dice = [self.dice[3],self.dice[1],self.dice[0],self.dice[5],self.dice[4],self.dice[2]]


def check_1_column(dice1,dice2):
    '''
    input:Diceクラスを2つ読み込む
    output:Dice1を4回縦回転して、Dice2と一致するようであれば1を返す。一致しなければ、0を返す。
    '''
    for b in range(4):
        if dice1.dice[0] == dice2.dice[0] and dice1.dice[1] == dice2.dice[1] and dice1.dice[2] == dice2.dice[2] and dice1.dice[3] == dice2.dice[3] and dice1.dice[4] == dice2.dice[4] and dice1.dice[5] == dice2.dice[5]:
            return 1
        dice1.turn('N')
    return 0

def check_all(dice1,dice2):

    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('N')
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    return 0


n = int(input())
input_dice = []
for a in range(n):
    temp = list(map(int,input().split()))
    temp_class = Dice(temp[0],temp[1],temp[2],temp[3],temp[4],temp[5])
    input_dice.append(temp_class)



flag = 0
for a in itertools.combinations(input_dice,2):
    temp1 = copy.copy(a[0])
    temp2 = copy.copy(a[1])
    flag += check_all(temp1,temp2)
if flag == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
class diceClass:
	def __init__(self, valuelist):
		self.valuelist = valuelist
		self.t = valuelist[0]
		self.b = valuelist[5]
		self.n = valuelist[4]
		self.s = valuelist[1]
		self.e = valuelist[2]
		self.w = valuelist[3]

	def print(self):
		print('t={0}, b={1}, n={2}, s={3}, w={4}, e={5}'.format(self.t, self.b, self.n, self.s, self.e, self.w))

	def throw(self, direction):
		
		if direction == 'N':
			self.t, self.s, self.b, self.n = self.s, self.b, self.n, self.t
		elif direction == 'S':
			self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
		elif direction == 'W':
			self.t, self.e, self.b, self.w = self.e, self.b, self.w, self.t
		elif direction == 'E':
			self.t, self.e, self.b, self.w = self.w, self.t, self.e, self.b

def compare(lst1, lst2):
	for i in lst1:
		if lst2.count(i) != 1:
			return False
	return True

n = int(input())
dirinput = 'WWWWSWWWWSWWWWSWWWWWSWWWWSSWWWW'
classes = []
for i in range(0,n):
	arrinput = list(map(int, input().split()))
	dice = diceClass(arrinput)
	dicresult = []
	for s in dirinput:
		dice.throw(s)
		if dicresult.count([[dice.t, dice.s], dice.e]) == 0:
			dicresult.append([[dice.t, dice.s], dice.e])
	classes.append(dicresult)

for i in range(0, len(classes)-1):
	for j in range(i+1,len(classes)):
		if compare(classes[i],classes[j]) == True:
			print('No')
			exit(0)

print('Yes')

Solution (Python):
class Dice:
  __table =[[0,1,2,3,4,5],[0,2,4,1,3,5],[0,4,3,2,1,5],[0,3,1,4,2,5],
            [1,5,2,3,0,4],[1,2,0,5,3,4],[1,0,3,2,5,4],[1,3,5,0,2,4],
            [2,5,4,1,0,3],[2,4,0,5,1,3],[2,0,1,4,5,3],[2,1,5,0,4,3],
            [3,5,1,4,0,2],[3,1,0,5,4,2],[3,0,4,1,5,2],[3,4,5,0,1,2],
            [4,2,5,0,3,1],[4,5,3,2,0,1],[4,3,0,5,2,1],[4,0,2,3,5,1],
            [5,1,3,2,4,0],[5,3,4,1,2,0],[5,4,2,3,1,0],[5,2,1,4,3,0]]
  __another = []
  def __init__(self,dice):
    self.dice = dice
    for t in self.__table:
      a = []
      for v in t:
        a.append(dice[v])      
      self.__another.append(a)
      
  def output(self):
    print(self.dice[0])
    
  def right_dise(self,a,b):
    for t in self.__another:
      if t[0] == a and t[1] == b:
        return t[2]

  def comparison(self,dice):
    result = 0
    for table_temp in self.__another:
      table_temp = ''.join(map(str,table_temp))
      dice = ''.join(map(str,dice))
      if table_temp == dice:
        print('Yes')
        result = 1
        break
    if result == 0:
      print('No')
  
  def comparison2(self,dice):
    for table_temp in self.__another:
      table_temp = ''.join(map(str,table_temp))
      dice = ''.join(map(str,dice))
      if table_temp == dice:
        return 1
    return 0

  def move(self,str):
    if str == 'N':
      temp = self.dice[0]
      self.dice[0] = self.dice[1]
      self.dice[1] = self.dice[5]
      self.dice[5] = self.dice[4]
      self.dice[4] = temp
    elif str == 'S':
      temp = self.dice[0]
      self.dice[0] = self.dice[4]
      self.dice[4] = self.dice[5]
      self.dice[5] = self.dice[1]
      self.dice[1] = temp
    elif str == 'E':
      temp = self.dice[0]
      self.dice[0] = self.dice[3]
      self.dice[3] = self.dice[5]
      self.dice[5] = self.dice[2]
      self.dice[2] = temp
    elif str == 'W':
      temp = self.dice[0]
      self.dice[0] = self.dice[2]
      self.dice[2] = self.dice[5]
      self.dice[5] = self.dice[3]
      self.dice[3] = temp      
  
num = int(input())
di1 = list(map(int,input().split()))
di = Dice(di1)
result = 0
for _ in range(num-1):
  di2 = list(map(int,input().split()))
  result += di.comparison2(di2)
  
if result > 0:
  print('No')
else:
  print('Yes')

Solution (Python):
import math
import itertools
import sys

class Dice:
  def __init__(self, int_array):
    self.numbers = int_array
    self.faces = {}
    self.faces['top'] = self.numbers[0]
    self.faces['back'] = self.numbers[1]
    self.faces['right'] = self.numbers[2]
    self.faces['left'] = self.numbers[3]
    self.faces['front'] = self.numbers[4]
    self.faces['bottom'] = self.numbers[5]

  def getNum(self, n):
    return self.numbers[n-1]

  def getFace(self, f):
    return self.faces[f]

  def getRightFace(self, t, b):
    top = self.faces['top']
    back = self.faces['back']
    right = self.faces['right']
    left = self.faces['left']
    front = self.faces['front']
    bottom = self.faces['bottom']

    if t == self.getNum(2):
      self.rotate('N')

    elif t == self.getNum(4):
      self.rotate('E')

    elif t == self.getNum(5):
      self.rotate('S')

    elif t == self.getNum(3):
      self.rotate('W')

    elif t == self.getNum(6):
      for _ in range(2):
        self.rotate('N')

    while self.getFace('back') != b:
      self.rotate('R')

    result = self.getFace('right')
      
    self.faces['top'] = top
    self.faces['back'] = back
    self.faces['right'] = right
    self.faces['left'] = left
    self.faces['front'] = front
    self.faces['bottom'] = bottom

    return result

  def rotate(self, direction):
    if direction == 'N': 
      top = self.getFace('top') 

      self.faces['top'] = self.faces['back']
      self.faces['back'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['front']
      self.faces['front'] = top
      
    elif direction == 'E': 
      top = self.faces['top'] 

      self.faces['top'] = self.faces['left']
      self.faces['left'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['right']
      self.faces['right'] = top
      
    elif direction == 'S': 
      top = self.faces['top'] 

      self.faces['top'] = self.faces['front']
      self.faces['front'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['back']
      self.faces['back'] = top
      
    elif direction == 'W': 
      top = self.faces['top'] 

      self.faces['top'] = self.faces['right']
      self.faces['right'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['left']
      self.faces['left'] = top
      
    elif direction == 'R': 
      back = self.faces['back'] 

      self.faces['back'] = self.faces['left']
      self.faces['left'] = self.faces['front']
      self.faces['front'] = self.faces['right']
      self.faces['right'] = back
      
    elif direction == 'L': 
      back = self.faces['back'] 

      self.faces['back'] = self.faces['right']
      self.faces['right'] = self.faces['front']
      self.faces['front'] = self.faces['left']
      self.faces['left'] = back

def isSameDice(dice_1, dice_2):
  faces = ['top', 'back', 'right', 'left', 'front', 'bottom']

  for _ in range(4):
    for _ in range(4):
      flag = True

      for face in faces:
        if dice_1.getFace(face) != dice_2.getFace(face):
          flag = False
          break

      if flag:
        return True
      dice_1.rotate('R')

    dice_1.rotate('N')

  dice_1.rotate('E')
  for _ in range(4):
    flag = True

    for face in faces:
      if dice_1.getFace(face) != dice_2.getFace(face):
        flag = False
        break

    if flag:
      return True
    dice_1.rotate('R')

  for _ in range(2):
    dice_1.rotate('W')
  for _ in range(4):
    flag = True

    for face in faces:
      if dice_1.getFace(face) != dice_2.getFace(face):
        flag = False
        break

    if flag:
      return True
    dice_1.rotate('R')

  return False
      
def main():
  n = int(input())
  dices = [list(map(int, input().split())) for _ in range(n)]

  existSame = False

  for c in itertools.combinations(dices, 2):
    if isSameDice(Dice(c[0]), Dice(c[1])):
      existSame = True
      break

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

if __name__ == '__main__':
  main()

Solution (Python):
def f():
 for c in range(n):
  for d in a[c+1:]:
   for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
    if[d[p[0]],d[p[5]]]==a[c][::5]:
     b=[d[i]for i in p[1:5]]*2
     for k in range(4):
      if b[k:k+4]==a[c][1:5]:return"No"
 return"Yes"
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:b[3:5]=b[4],b[3]
print(f())

Solution (Python):
D = [
    (1, 5, 2, 3, 0, 4), 
    (3, 1, 0, 5, 4, 2), 
    (4, 0, 2, 3, 5, 1), 
    (2, 1, 5, 0, 4, 3), 
]

N = int(input())
L = [None]*N
for i in range(N):
    *L[i], = map(int, input().split())

p = (0, 0, 0, 1, 1, 2, 2, 3)
ok = 1
for i in range(N):
    Li = L[i]
    for j in range(i+1, N):
        Lj = L[j]
        for k in range(24):
            if Li == Lj:
                ok = 0
            Lj[:] = (Lj[e] for e in D[p[k%8]])
print("Yes" if ok else "No")

Solution (Python):
def roll_e(d):
    w = []
    w = d
    d[0], d[1], d[2], d[3], d[4], d[5] = w[3], w[1], w[0], w[5], w[4], w[2]
    return d

def roll_s(d):
    w = []
    w = d
    d[0], d[1], d[2], d[3], d[4], d[5] = w[4], w[0], w[2], w[3], w[5], w[1]
    return d

def dice_judge(d1, d2):
    no_flag = 0

    i = 0
    while d1[1] != d2[1]:
        if i == 7:
            no_flag = 1
            break
        elif i == 4:
            d2 = roll_e(d2)
        d2 = roll_s(d2)
        i += 1

    i = 0
    while d1[0] != d2[0] and no_flag == 0:
        if i == 4:
            break
        d2 = roll_e(d2)
        i += 1

    if d1 == d2:
        return True
    else:
        return False

n = int(input())
d = []
no_flag = 0

i = 0
while n > i:
    d.append(input().split())
    i += 1
i, j = 0, 0
while n-1 > i:
    j = i + 1
    while n > j:
        if dice_judge(d[i], d[j]):
            no_flag = 1
        j += 1
    i += 1

if no_flag == 0:
    print("Yes")
elif no_flag == 1:
    print("No")

Solution (Python):
n = int(input())
dices = [list(map(int,input().split(" "))) for i in range(n)]
check = []
count = 0
eq = 0
for i in range(n):
    check.append(dices[i])
d= []

def move(x):
    
    if x == 0:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[1],d[5],d[2],d[3],d[0],d[4]
    
    elif x == 1:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[2],d[1],d[5],d[0],d[4],d[3]

    
    elif x == 2:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[3],d[1],d[0],d[5],d[4],d[2]
    
    elif x == 3:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[4],d[0],d[2],d[3],d[5],d[1]


    elif x == 4:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[0],d[1],d[2],d[3],d[4],d[5]

    elif x == 5:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[5],d[4],d[2],d[3],d[1],d[0]



    elif x == 6:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[0],d[2],d[4],d[1],d[3],d[5]


for i in range(6):
    d.append(dices[0][i])

for i in range(n-1):
    del check[0]
    for j in range(6):
        d[0],d[1],d[2],d[3],d[4],d[5] = dices[i][0],dices[i][1],dices[i][2],dices[i][3],dices[i][4],dices[i][5]
        move(j)
        for k in range(4):
            count += 1
            move(6)
            if d in check:
                eq = 1

                
            




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

Solution (Python):
class Dice:
    
    keys = [ 
        "top", 
        "front", 
        "right", 
        "left", 
        "back", 
        "bottom"
        ]
    keys_for_top = [
            ["front", "right", "back", "left", "bottom"],
            ["bottom", "right", "top", "left", "back"],
            ["bottom", "back", "top", "front", "left"],
            ["bottom", "front", "top", "back", "right"],
            ["bottom", "left", "top", "right", "front"],
            ["front", "left", "back", "right", "top"]
        ]

    def __init__(self, eye1, eye2, eye3, eye4, eye5, eye6):
        self.__eyes = {
            "top": eye1,
            "front": eye2,
            "right": eye3,
            "left": eye4,
            "back": eye5,
            "bottom": eye6
        }

    def set_eyes(self, eye1, eye2, eye3, eye4, eye5, eye6):
        self.__eyes["top"] = eye1
        self.__eyes["front"] = eye2
        self.__eyes["right"] = eye3
        self.__eyes["left"] = eye4
        self.__eyes["back"] = eye5
        self.__eyes["bottom"] = eye6
    
    def get_eyes(self, key):
        return self.__eyes[key]

    def N(self):
        self.set_eyes(
            self.get_eyes("front"),
            self.get_eyes("bottom"),
            self.get_eyes("right"),
            self.get_eyes("left"),
            self.get_eyes("top"),
            self.get_eyes("back")
            )
    def S(self):
        self.set_eyes(
            self.get_eyes("back"),
            self.get_eyes("top"),
            self.get_eyes("right"),
            self.get_eyes("left"),
            self.get_eyes("bottom"),
            self.get_eyes("front")
            )
        
    def E(self):
        self.set_eyes(
            self.get_eyes("left"),
            self.get_eyes("front"),
            self.get_eyes("top"),
            self.get_eyes("bottom"),
            self.get_eyes("back"),
            self.get_eyes("right")
            )
        
    def W(self):
        self.set_eyes(
            self.get_eyes("right"),
            self.get_eyes("front"),
            self.get_eyes("bottom"),
            self.get_eyes("top"),
            self.get_eyes("back"),
            self.get_eyes("left")
            )
    
    def print_top(self):
        print(self.get_eyes("top"))

    def guess_right_from_top_front(self, top, front):
        key_top = None
        key_front = None
        
        for key in Dice.keys:
            if top == self.get_eyes(key):
                key_top = key
            if front == self.get_eyes(key):
                key_front = key
        

        for i in range(6):
            if key_top == Dice.keys[i]:
                for j in range(4):
                    if key_front == Dice.keys_for_top[i][j]:
                        return Dice.keys_for_top[i][(j + 1) % 4]
        return False

    @classmethod
    def generate_all_states(cls, dice):
        dices = []
        for i in range(6):
            for j in range(4):
                dices.append(cls(
                    dice.get_eyes(Dice.keys[i]),
                    dice.get_eyes(Dice.keys_for_top[i][j]),
                    dice.get_eyes(Dice.keys_for_top[i][(j + 1) % 4]),
                    dice.get_eyes(Dice.keys_for_top[i][(j + 3) % 4]),
                    dice.get_eyes(Dice.keys_for_top[i][(j + 2) % 4]),
                    dice.get_eyes(Dice.keys_for_top[i][4])
                    ))
        return dices
    
    @classmethod
    def is_same_states(cls, dice1, dice2):
        for i in range(6):
            if dice1.get_eyes(Dice.keys[i]) != dice2.get_eyes(Dice.keys[i]):
                return False
        return True
    
    @classmethod
    def is_same_dices(cls, dice1, dice2):
        all_states_dice2 = Dice.generate_all_states(dice2)
        for i in range(24):
            if Dice.is_same_states(dice1, all_states_dice2[i]):
                return True
        return False   

n = int(input())
dices = []
for i in range(n):
    e1, e2, e3, e4, e5, e6 = map(int, input().split())
    dices.append(Dice(e1, e2, e3, e4, e5, e6))

for i in range(n):
    for j in range(i+1, n):
        if Dice.is_same_dices(dices[i], dices[j]):
            print("No")
            quit()
print("Yes")