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: import sys
  import itertools
  
  
  class Dice(object):
      def __init__(self, faces: list):
          self.list_sn = [faces[5], faces[4], faces[0], faces[1]]  # 6,5,1,2
          self.list_we = [faces[5], faces[2], faces[0], faces[3]]  # 6,5,1,2
  
      def _roll_positive(self, list_a: list, list_b: list) -> list:
          list_a = list_a[1:] + list_a[0:1]  # Roll one unit in the positive direction.
          list_b[0] = list_a[0]  # Change the bottom face.
          list_b[2] = list_a[2]  # Change the top face.
          return [list_a, list_b]
  
      def _roll_negative(self, list_a: list, list_b: list) -> list:
          list_a = list_a[3:] + list_a[0:3]
          list_b[0] = list_a[0]  # Change the bottom face.
          list_b[2] = list_a[2]  # Change the top face.
          return [list_a, list_b]
  
      def roll(self, direction: str):
          if "N" == direction:
              self.list_sn, self.list_we = self._roll_positive(self.list_sn, self.list_we)
          elif "S" == direction:
              self.list_sn, self.list_we = self._roll_negative(self.list_sn, self.list_we)
          elif "E" == direction:
              self.list_we, self.list_sn = self._roll_positive(self.list_we, self.list_sn)
          else:
              self.list_we, self.list_sn = self._roll_negative(self.list_we, self.list_sn)
  
  
  if __name__ == "__main__":
      dice_num = int(input())
      dice_list = [
          Dice(list(map(lambda x: int(x), input().split()))) for _ in range(dice_num)
      ]
  
      for Dice_a, Dice_b in itertools.combinations(dice_list, 2):
          for command in "NNNNWNNNWNNNENNNENNNWNNN":  # Check all patterns.
              Dice_b.roll(command)
              if Dice_a.list_sn == Dice_b.list_sn and Dice_a.list_we == Dice_b.list_we:
                  print("No")  # Some pair is identical.
                  sys.exit()
      print("Yes")  # All dices are different.
  
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"}]