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: #!/usr/bin/env python3
  import sys
  import copy
  
  line = sys.stdin.readline()
  
  faces = []
  
  
  def anydup(thelist):
      seen = set()
      for x in thelist:
          if x in seen:
              return True
          seen.add(x)
      return False
  
  
  while True:
      line = sys.stdin.readline()
      if not line:
          break
      line = line.rstrip("\r\n")
      faces.append(line.split())
  
  for i in range(5):
      face = faces[-1]
      if face[0] != face[1]:
          break
      face_old = copy.deepcopy(face)
      face[0] = face_old[1]
      face[1] = face_old[5]
      face[2] = face_old[2]
      face[3] = face_old[3]
      face[4] = face_old[0]
      face[5] = face_old[4]
  else:
      face_old = copy.deepcopy(face)
      face[0] = face_old[3]
      face[1] = face_old[1]
      face[2] = face_old[0]
      face[3] = face_old[5]
      face[4] = face_old[4]
      face[5] = face_old[2]
  for i in range(5):
      if face[0] != face[1]:
          break
      face_old = copy.deepcopy(face)
      face[0] = face_old[1]
      face[1] = face_old[5]
      face[2] = face_old[2]
      face[3] = face_old[3]
      face[4] = face_old[0]
      face[5] = face_old[4]
  for i in range(5):
      if face[0] != face[1]:
          break
      face_old = copy.deepcopy(face)
      face[0] = face_old[3]
      face[1] = face_old[1]
      face[2] = face_old[0]
      face[3] = face_old[5]
      face[4] = face_old[4]
      face[5] = face_old[2]
  
  for j in range(len(faces) - 1):
      face = faces[j]
      face2 = faces[-1]
      for i in range(5):
          if face[1] == face2[1]:
              break
          face_old = copy.deepcopy(face)
          face[0] = face_old[1]
          face[1] = face_old[5]
          face[2] = face_old[2]
          face[3] = face_old[3]
          face[4] = face_old[0]
          face[5] = face_old[4]
      else:
          face_old = copy.deepcopy(face)
          face[0] = face_old[3]
          face[1] = face_old[1]
          face[2] = face_old[0]
          face[3] = face_old[5]
          face[4] = face_old[4]
          face[5] = face_old[2]
      for i in range(5):
          if face[1] == face2[1]:
              break
          face_old = copy.deepcopy(face)
          face[0] = face_old[1]
          face[1] = face_old[5]
          face[2] = face_old[2]
          face[3] = face_old[3]
          face[4] = face_old[0]
          face[5] = face_old[4]
      for i in range(5):
          if face[0] == face2[0]:
              break
          face_old = copy.deepcopy(face)
          face[0] = face_old[3]
          face[1] = face_old[1]
          face[2] = face_old[0]
          face[3] = face_old[5]
          face[4] = face_old[4]
          face[5] = face_old[2]
  
  # for f in faces:
  #    print(f)
  
  if any(faces.count(x) > 1 for x in faces):
      print("No")
  else:
      print("Yes")
  
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"}]