output_description: Print "Yes" if given dices are all different, otherwise "No" in a line.
input_description: 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.
attempt: from itertools import combinations
  
  
  class Dice:
      def __init__(self, dim=list(range(1, 7))):
          self.dim = dim
  
      def roll(self, direction):
          if direction == "N":
              buff = self.dim[0]
              self.dim[0] = self.dim[1]
              self.dim[1] = self.dim[5]
              self.dim[5] = self.dim[4]
              self.dim[4] = buff
  
          if direction == "E":
              buff = self.dim[3]
              self.dim[3] = self.dim[5]
              self.dim[5] = self.dim[2]
              self.dim[2] = self.dim[0]
              self.dim[0] = buff
  
          if direction == "W":
              buff = self.dim[0]
              self.dim[0] = self.dim[2]
              self.dim[2] = self.dim[5]
              self.dim[5] = self.dim[3]
              self.dim[3] = buff
  
          if direction == "S":
              buff = self.dim[0]
              self.dim[0] = self.dim[4]
              self.dim[4] = self.dim[5]
              self.dim[5] = self.dim[1]
              self.dim[1] = buff
  
  
  def dice_ident(lsts, comb):
      for i in comb:
          D1 = Dice(lsts[i[0]])
          D2 = Dice(lsts[i[1]])
          for op in "EEENEEENEEESEEESEEENEEEN":
              if D1.dim == D2.dim:
                  return print("No")
              D1.roll(op)
      return print("Yes")
  
  
  number = int(input())
  comb = list(combinations(range(number), 2))
  lsts = []
  for i in range(number):
      lsts.append(list(map(int, input().split())))
  
  dice_ident(lsts, comb)
  
problem_description: 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.
samples: [{"input": "3\n    1 2 3 4 5 6\n    6 2 4 3 5 1\n    6 5 4 3 2 1", "output": "No"}, {"input": "3\n    1 2 3 4 5 6\n    6 5 4 3 2 1\n    5 4 3 2 1 6", "output": "Yes"}]