Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

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



Sample input:
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1


Sample output:
No

Submission status: Accepted

Solution code:
# coding=utf-8
from itertools import combinations


class Dice(object):

    def __init__(self, list_):
        self.label = list_

    def getLabel(self, i):
        return self.label[i - 1]

    def _rotateS(self):
        self.label = [self.getLabel(i) for i in [5, 1, 3, 4, 6, 2]]

    def _rotateN(self):
        self.label = [self.getLabel(i) for i in [2, 6, 3, 4, 1, 5]]

    def _rotateE(self):
        self.label = [self.getLabel(i) for i in [4, 2, 1, 6, 5, 3]]

    def _rotateW(self):
        self.label = [self.getLabel(i) for i in [3, 2, 6, 1, 5, 4]]

    def _spinPos(self):
        self.label = [self.getLabel(i) for i in [1, 4, 2, 5, 3, 6]]

    def _spinNeg(self):
        self.label = [self.getLabel(i) for i in [1, 3, 5, 2, 4, 6]]

    def rotate(self, rotates):
        for r in rotates:
            if r == 'S':
                self._rotateS()
            elif r == 'N':
                self._rotateN()
            elif r == 'E':
                self._rotateE()
            elif r == 'W':
                self._rotateW()
            elif r == 'T':
                self._spinPos()
            elif r == 'B':
                self._spinNeg()

    def matchTopFront(self, top, front):
        try:
            iTop = self.label.index(top) + 1
            topRot = {1: '', 2: 'N', 3: 'W', 4: 'E', 5: 'S', 6: 'SS'}
            self.rotate(topRot[iTop])

            iFront = self.label.index(front) + 1
            frontRot = {2: '', 3: 'B', 4: 'T', 5: 'TT'}
            self.rotate(frontRot[iFront])
            return True
        except KeyError:
            return False

    def copy(self):
        return Dice(self.label[:])

    def _equalWithOverlap(self, other):
        # ?????¢???????????¢?????\????????§6????????????
        for rs in ['', 'S', 'N', 'E', 'W', 'SS']:
            tmp = self.copy()
            for r in rs:
                tmp.rotate(r)
            # ?????¢????????¢????????§??????
            top = tmp.getLabel(1) == other.getLabel(1)
            bottom = tmp.getLabel(6) == other.getLabel(6)
            # ??´??¢?????????????????????????????????????????¢??????????????????????????´??????????????°??????
            # top and bottom ???False??????????????????????????????????????§?????¢??°?????????

            def _side():
                result, n = False, 3
                while not result and n > 0:
                    if tmp.label[1:5] == other.label[1:5]:
                        result = True
                    else:
                        tmp.rotate('T')
                        n -= 1
                return result

            if top and bottom and _side():
                return True
        else:
            return False

    def __eq__(self, other):
        # ????????????????????????????????´?????????????????´???
        if set(self.label) != set(other.label):
            return False
        # ???????????????????????´???
        elif len(self.label) == len(set(self.label)):
                if other.matchTopFront(self.getLabel(1), self.getLabel(2)):
                    return True if self.label == other.label else False
                else:
                    return False
        # ???????????????????????´???
        else:
            return True if self._equalWithOverlap(other) else False


def main():
    n = input()
    faces = [map(int, raw_input().split()) for _ in xrange(n)]
    for f1, f2 in combinations(faces, 2):
        if f1 == f2 or Dice(f1) == Dice(f2):
            print 'No'
            break
    else:
        print 'Yes'


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding=utf-8
from itertools import combinations


class Dice(object):

    def __init__(self, list_):
        self.label = list_

    def getLabel(self, i):
        return self.label[i - 1]

    def _rotateS(self):
        self.label = [self.getLabel(i) for i in [5, 1, 3, 4, 6, 2]]

    def _rotateN(self):
        self.label = [self.getLabel(i) for i in [2, 6, 3, 4, 1, 5]]

    def _rotateE(self):
        self.label = [self.getLabel(i) for i in [4, 2, 1, 6, 5, 3]]

    def _rotateW(self):
        self.label = [self.getLabel(i) for i in [3, 2, 6, 1, 5, 4]]

    def _spinPos(self):
        self.label = [self.getLabel(i) for i in [1, 4, 2, 5, 3, 6]]

    def _spinNeg(self):
        self.label = [self.getLabel(i) for i in [1, 3, 5, 2, 4, 6]]

    def rotate(self, rotates):
        for r in rotates:
            if r == 'S':
                self._rotateS()
            elif r == 'N':
                self._rotateN()
            elif r == 'E':
                self._rotateE()
            elif r == 'W':
                self._rotateW()
            elif r == 'T':
                self._spinPos()
            elif r == 'B':
                self._spinNeg()

    def matchTopFront(self, top, front):
        iTop = self.label.index(top) + 1
        topRot = {1: '', 2: 'N', 3: 'W', 4: 'E', 5: 'S', 6: 'SS'}
        self.rotate(topRot[iTop])

        iFront = self.label.index(front) + 1
        frontRot = {2: '', 3: 'B', 4: 'T', 5: 'TT'}
        # top, front ???????????´???????????¢??????????????´??????iFront???1???6?????????
        try:
            self.rotate(frontRot[iFront])
            return True
        except KeyError:
            return False

    def copy(self):
        return Dice(self.label[:])

    def _equalWithoutOverlap(self, other):
        if other.matchTopFront(self.getLabel(1), self.getLabel(2)):
            return True if self.label == other.label else False
        else:
            return False

    def _equalWithOverlap(self, other):
        # ?????¢???????????¢?????\????????§6????????????
        for rs in ['', 'S', 'N', 'E', 'W', 'SS']:
            tmp = self.copy()
            for r in rs:
                tmp.rotate(r)
            # ?????¢????????¢????????§??????
            top = tmp.getLabel(1) == other.getLabel(1)
            bottom = tmp.getLabel(6) == other.getLabel(6)

            # ??´??¢?????????????????????????????????????????¢??????????????????????????´??????????????°??????
            # top and bottom ???False??????????????????????????????????????§?????¢??°?????????
            def _side():
                result, n = False, 3
                while not result and n > 0:
                    if tmp.label[1:5] == other.label[1:5]:
                        result = True
                    else:
                        tmp.rotate('T')
                        n -= 1
                return result

            if top and bottom and _side():
                return True
        else:
            return False

    def __eq__(self, other):
        # ????????????????????????????????´?????????????????´???
        if set(self.label) != set(other.label):
            return False
        # ???????????????????????´???
        elif len(self.label) == len(set(self.label)):
            return self._equalWithoutOverlap(other)
        # ???????????????????????´???
        else:
            return self._equalWithOverlap(other)


def main():
    n = input()
    faces = [map(int, raw_input().split()) for _ in xrange(n)]
    for f1, f2 in combinations(faces, 2):
        if f1 == f2 or Dice(f1) == Dice(f2):
            print 'No'
            break
    else:
        print 'Yes'


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def rotate(self):
        self.faces = (self.faces[0], self.faces[2], self.faces[4],
                      self.faces[1], self.faces[3], self.faces[5])

    def number(self, face_id):
        return self.faces[face_id - 1]

    def issame(self, other_dice):
        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_north()

        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_east()
        return False

dice_list = []
n = int(input())
for i in range(n):
    dice_list.append(Dice([int(a) for a in input().split()]))

res = "Yes"
for i in range(n):
    for j in range(i + 1, n):
        if dice_list[i].issame(dice_list[j]):
            res = "No"
            break
print(res)

Submission status: Accepted

Solution code:
class Dice(list):
    def __init__(self, l):
        super().__init__(l)

    def roll(self, command):
        # /  0
        # / 3124
        # /  5
        if command == 'N':
            self[0], self[1], self[5], self[4] = self[1], self[5], self[4], self[0]
        elif command == 'S':
            self[0], self[1], self[5], self[4] = self[4], self[0], self[1], self[5]
        elif command == 'W':
            self[0], self[3], self[5], self[2] = self[2], self[0], self[3], self[5]
        elif command == 'E':
            self[0], self[3], self[5], self[2] = self[3], self[5], self[2], self[0]

    def right_spin(self, repeat=1):
        for _ in range(repeat):
            self[3], self[1], self[2], self[4] = self[1], self[2], self[4], self[3]

    def _fix_position(self):
        self._min_num_to_top()
        self._min_side_num_to_front()

    def _min_num_to_top(self):
        min_idx = self.index(min(self))
        if min_idx == 0:
            pass
        elif min_idx == 1:
            self.roll('N')
        elif min_idx == 2:
            self.roll('W')
        elif min_idx == 3:
            self.roll('E')
        elif min_idx == 4:
            self.roll('S')
        elif min_idx == 5:
            self.roll('N')
            self.roll('N')

    def _min_side_num_to_front(self):
        idx = self.index(min(self[3], self[1], self[2], self[4]))
        if idx == 1:
            pass
        elif idx == 2:
            self.right_spin(1)
        elif idx == 3:
            self.right_spin(3)
        elif idx == 4:
            self.right_spin(2)

    def __hash__(self):
        self._fix_position()
        return tuple(self).__hash__()


if __name__ == '__main__':
    n = int(input())
    dices = set(Dice(map(int, input().split())) for _ in range(n))
    print('Yes' if n == len(dices) else 'No')

Submission status: Accepted

Solution code:
class Dice(list):
    def __init__(self, *args):
        super().__init__(*args)
        tmp = self[::]
        self._fix_position()
        self.hash = hash(tuple(self))
        self[::] = tmp

    def roll(self, command):
        if command == 'N':
            self[0], self[1], self[5], self[4] = self[1], self[5], self[4], self[0]
        elif command == 'S':
            self[0], self[1], self[5], self[4] = self[4], self[0], self[1], self[5]
        elif command == 'W':
            self[0], self[3], self[5], self[2] = self[2], self[0], self[3], self[5]
        elif command == 'E':
            self[0], self[3], self[5], self[2] = self[3], self[5], self[2], self[0]

    def spin(self, repeat=1):
        for _ in range(repeat):
            self[3], self[1], self[2], self[4] = self[1], self[2], self[4], self[3]

    def _fix_position(self):
        self._min_num_to_top()
        self._min_side_num_to_front()

    def _min_num_to_top(self):
        idx = self.index(min(self))
        if idx == 0:
            pass
        elif idx == 1:
            self.roll('N')
        elif idx == 2:
            self.roll('W')
        elif idx == 3:
            self.roll('E')
        elif idx == 4:
            self.roll('S')
        elif idx == 5:
            self.roll('N')
            self.roll('N')

    def _min_side_num_to_front(self):
        idx = self.index(min(self[3], self[1], self[2], self[4]))
        if idx == 1:
            pass
        elif idx == 2:
            self.spin(1)
        elif idx == 3:
            self.spin(3)
        elif idx == 4:
            self.spin(2)

    def __hash__(self):
        return self.hash

    def __eq__(self, other):
        return hash(self) == hash(other)


def solve():
    n = int(input())
    dices = set(Dice(map(int, input().split())) for _ in range(n))
    return 'Yes' if n == len(dices) else 'No'


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
class Dice(list):
    def __init__(self, *args):
        super().__init__(*args)

    def roll(self, command):
        if command == 'N':
            self[0], self[1], self[5], self[4] = self[1], self[5], self[4], self[0]
        elif command == 'S':
            self[0], self[1], self[5], self[4] = self[4], self[0], self[1], self[5]
        elif command == 'W':
            self[0], self[3], self[5], self[2] = self[2], self[0], self[3], self[5]
        elif command == 'E':
            self[0], self[3], self[5], self[2] = self[3], self[5], self[2], self[0]

    def spin(self, repeat=1):
        for _ in range(repeat):
            self[3], self[1], self[2], self[4] = self[1], self[2], self[4], self[3]

    def _fix_position(self):
        self._min_num_to_top()
        self._min_side_num_to_front()

    def _min_num_to_top(self):
        idx = self.index(min(self))
        if idx == 0:
            pass
        elif idx == 1:
            self.roll('N')
        elif idx == 2:
            self.roll('W')
        elif idx == 3:
            self.roll('E')
        elif idx == 4:
            self.roll('S')
        elif idx == 5:
            self.roll('N')
            self.roll('N')

    def _min_side_num_to_front(self):
        idx = self.index(min(self[3], self[1], self[2], self[4]))
        if idx == 1:
            pass
        elif idx == 2:
            self.spin(1)
        elif idx == 3:
            self.spin(3)
        elif idx == 4:
            self.spin(2)

    def __hash__(self):
        self._fix_position()
        return hash(tuple(self))

    def __eq__(self, other):
        return hash(self) == hash(other)


if __name__ == '__main__':
    n = int(input())
    dices = set(Dice(map(int, input().split())) for _ in range(n))
    print('Yes' if n == len(dices) else 'No')

Submission status: Accepted

Solution code:
import random

class Dice:
  def __init__(self, list = map(str, range(1, 7))):
    self.top = list[0]
    self.front = list[1]
    self.right = list[2]
    self.left = list[3]
    self.back = list[4]
    self.bottom = list[5]

    self.dic = {}
    for i in xrange(6):
      if list[i] in self.dic:
        self.dic[list[i]] += 1
      else:
        self.dic[list[i]] = 1

  def print_all(self):
    print "top = " + self.top + ", front = " + self.front + ", right = " + self.right + ", left = " + self.left + ", back = " + self.back + ", bottom = " + self.bottom

  def roll_N(self):
    temp = self.top
    self.top = self.front
    self.front = self.bottom
    self.bottom = self.back
    self.back = temp

  def roll_S(self):
    temp = self.top
    self.top = self.back
    self.back = self.bottom
    self.bottom = self.front
    self.front = temp

  def roll_W(self):
    temp = self.top
    self.top = self.right
    self.right = self.bottom
    self.bottom = self.left
    self.left = temp

  def roll_E(self):
    temp = self.top
    self.top = self.left
    self.left = self.bottom
    self.bottom = self.right
    self.right = temp

  def roll_C(self):
    temp = self.front
    self.front = self.right
    self.right = self.back
    self.back = self.left
    self.left = temp

  def random_roll(self):
    ram = random.randint(1, 4)
    if ram == 1:
      self.roll_E()
    elif ram == 2:
      self.roll_N()
    elif ram == 3:
      self.roll_S()
    else:
      self.roll_W()

  def getDifference(self, dice):
    same_list = []
    different_list = []
    if self.top == dice.top:
      same_list.append("top")
    else:
      different_list.append("top")
    if self.front == dice.front:
      same_list.append("front")
    else:
      different_list.append("front")
    if self.left == dice.left:
      same_list.append("left")
    else:
      different_list.append("left")
    if self.back == dice.back:
      same_list.append("back")
    else:
      different_list.append("back")
    if self.right == dice.right:
      same_list.append("right")
    else:
      different_list.append("right")
    if self.bottom == dice.bottom:
      same_list.append("bottom")
    else:
      different_list.append("bottom")

    result_list = [same_list, different_list]
    return result_list

  def getList(self):
    list = [self.top, self.front, self.right, self.left, self.back, self.bottom]
    return list

def print_dices():
  print "first dice: "
  first_dice.print_all()
  print "second dice: "
  second_dice.print_all()
  # print first_dice.dic

line = "#######################################"


def judgeDices(first_dice, second_dice):
  flag = False
  num = 0
  debug = 0
  while num < 4:
    # debug += 1
    # if debug > 10:
    #   break
    # print line

    dic1_keys = first_dice.dic.keys()
    # print dic1_keys
    for i in xrange(len(dic1_keys)):
      # print "i = " + str(i) + "key = " + dic1_keys[i]
      # print second_dice.dic
      if not (dic1_keys[i] in second_dice.dic):
        # print "test"
        num = 4
        break
      elif first_dice.dic[dic1_keys[i]] != second_dice.dic[dic1_keys[i]]:
        num = 4
        break

    if num >=4:
      # print ("go?")
      break

    for i in xrange(len(dic1_keys)):
      if first_dice.dic[dic1_keys[i]] == 6 or first_dice.dic[dic1_keys[i]] == 5:
        num = 4
        flag = True
        break

    # print_dices()
    if num >=4:
      break

    diferece = first_dice.getDifference(second_dice)
    # print diferece

    same_num = len(diferece[0])
    if same_num == 6:
      break
    elif same_num == 5:
      num = 4
      break

    if "front" in diferece[0] or "back" in diferece[0]:
      first_dice.roll_W()
      num += 1
    elif "left" in diferece[0] or "right" in diferece[0]:
      first_dice.roll_S()
      num += 1
    elif "top" in diferece[0] or "bottom" in diferece[0]:
      first_dice.roll_C()
      num += 1
    else:
      first_dice.random_roll()

  if flag == True:
    return True
  elif num == 4:
    return False
  else:
    return True

n = int(raw_input())
dices = []
for i in xrange(n):
  dices.append(Dice(raw_input().split(" ")))
result = False
for i in xrange(n - 1):
  for j in xrange(i + 1, n):
    first_dice = dices[i]
    second_dice = dices[j]
    # print "i = " + str(i) + ", j = " + str(j)
    # print first_dice
    # print first_dice.dic
    # print second_dice
    # print second_dice.dic
    result = judgeDices(first_dice, second_dice)
    # print result
    if result:
      break
  if result:
    break

if result:
  print "No"
else:
  print "Yes"

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

POSITIONS = ["top", "south", "east", "west", "north", "bottom"]


class Dice(object):

    def __init__(self, initial_faces):
        self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)}
        self.store_previous_faces()

    def store_previous_faces(self):
        self.previous_faces = self.faces.copy()

    def change_face(self, after, before):
        self.faces[after] = self.previous_faces[before]

    def change_faces(self, rotation):
        self.change_face(rotation[0], rotation[1])
        self.change_face(rotation[1], rotation[2])
        self.change_face(rotation[2], rotation[3])
        self.change_face(rotation[3], rotation[0])

    def roll(self, direction):
        self.store_previous_faces()
        if direction == "E":
            self.change_faces(["top", "west", "bottom", "east"])
        elif direction == "N":
            self.change_faces(["top", "south", "bottom", "north"])
        elif direction == "S":
            self.change_faces(["top", "north", "bottom", "south"])
        elif direction == "W":
            self.change_faces(["top", "east", "bottom", "west"])

    def issame(self, dice1):
        if set(self.faces.values()) != set(dice1.faces.values()):
            return False
        if (dice1.faces["south"] == self.faces["west"] or dice1.faces["south"] == self.faces["east"]):
            self.roll("E")
        while dice1.faces["south"] != self.faces["south"]:
            self.roll("N")
        for n in range(4):
            if (dice1.faces == self.faces):
                # print("Me: " + str(self.faces))
                # print("You: " + str(dice1.faces))
                return True
                break
            else:
                self.roll("W")
        else:
            return False


def isalldifferent(dices):
    n = len(dices)
    for i in range(n):
        for j in range(i + 1, n):
            # print("Dice #{} vs Dice #{}". format(i, j))
            if dices[i].issame(dices[j]):
                return False
                break
    else:
        return True


def main():
    n = int(input())
    dices = [Dice(input().split()) for i in range(n)]
    print("Yes" if isalldifferent(dices) else "No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
class Dice:
 
    def __init__(self, faces):
        self.faces = tuple(faces)
 
    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])
 
    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])
 
    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])
 
    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])
 
    def rotate(self):
        self.faces = (self.faces[0], self.faces[2], self.faces[4],
                      self.faces[1], self.faces[3], self.faces[5])
 
    def number(self, face_id):
        return self.faces[face_id - 1]
 
    def issame(self, other_dice):
        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_north()
 
        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_east()
        return False
 
dice_list = []
n = int(input())
for i in range(n):
    dice_list.append(Dice([int(a) for a in input().split()]))
 
res = "Yes"
for i in range(n):
    for j in range(i + 1, n):
        if dice_list[i].issame(dice_list[j]):
            res = "No"
            break
print(res)

Submission status: Accepted

Solution code:
class Dice(object):

    def __init__(self, num):
        self.num = num

    def rotate_S(self):
        self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]]

    def rotate_N(self):
        self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]]

    def rotate_W(self):
        self.num = [self.num[2], self.num[1], self.num[5], self.num[0], self.num[4], self.num[3]]

    def rotate_E(self):
        self.num = [self.num[3], self.num[1], self.num[0], self.num[5], self.num[4], self.num[2]]

    def rotate_M(self):
        self.num = [self.num[0], self.num[2], self.num[4], self.num[1], self.num[3], self.num[5]]


def is_equal_dice(dice1, dice2):
    if len(set(dice1.num) - set(dice2.num)) != 0:
        return 0
    else:
        num = []
        for i in range(6):
            if dice1.num[0] == dice2.num[i]:
                num.append(i)
        for j in num:
            if j == 1:
                dice2.rotate_N()
            elif j == 2:
                dice2.rotate_W()
            elif j == 3:
                dice2.rotate_E()
            elif j == 4:
                dice2.rotate_S()
            elif j == 5:
                dice2.rotate_S()
                dice2.rotate_S()

            if dice1.num[5] == dice2.num[5]:
                for _ in range(4):
                    if (dice1.num[1] == dice2.num[1]) & (dice1.num[2] == dice2.num[2]) & (dice1.num[3] == dice2.num[3]):
                        return 1
                    dice1.rotate_M()
        return 0
N = input()
dice = [Dice(map(int, raw_input().split())) for _ in range(N)]
flg = False
for i in range(N):
    for j in range(i+1, N):
        if is_equal_dice(dice[i], dice[j]):
            flg = True
            break
if flg:
    print 'No'
else:
    print 'Yes'

Submission status: Accepted

Solution code:
import copy

class Dice(object):
	def __init__(self,List):
		self.face=List
		
	def n_spin(self,a_list):
		List=copy.copy(a_list)
		temp=List[0]
		List[0]=List[1]
		List[1]=List[5]
		List[5]=List[4]
		List[4]=temp
		return List
		
 	def s_spin(self,a_list):
 		List=copy.copy(a_list)
 		temp=List[0]
 		List[0]=List[4]
 		List[4]=List[5]
		List[5]=List[1]
		List[1]=temp
		return List
		
	def e_spin(self,a_list):
		List=copy.copy(a_list)
		temp=List[0]
		List[0]=List[3]
		List[3]=List[5]
		List[5]=List[2]
		List[2]=temp
		return List
		
 	def w_spin(self,a_list):
 		List = copy.copy(a_list)
 		temp=List[0]
 		List[0]=List[2]
 		List[2]=List[5]
		List[5]=List[3]
		List[3]=temp
		return List

n=input()
dice_List=[None]*n
emer=[None]*n
for a in range(n):
	dice_List[a]=Dice(map(int,raw_input().split()))
	emer[a]=copy.copy(dice_List[a].face)
judge=True
for b in range(1,n):
	face_storage=[]
	face_storage.append(emer[b])
	for c in range(24):
		face_storage.append((dice_List[b].n_spin(face_storage[c])))
		face_storage.append((dice_List[b].e_spin(face_storage[c])))
		face_storage.append((dice_List[b].w_spin(face_storage[c])))
		face_storage.append((dice_List[b].s_spin(face_storage[c])))
	for d in face_storage:
		if d==dice_List[0].face:
			judge=False
			break
if judge:
	print("Yes")
else :
	print("No")

Submission status: Accepted

Solution code:
class Dice:
    same_dice_index = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5),
                       (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4),
                       (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3),
                       (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3),
                       (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2),
                       (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
                       (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0),
                       (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0))

    def __init__(self, str_list):
        self.faces = str_list

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            for n, j in enumerate(i):
                if dice.faces[n] != self.faces[j]:
                    break
            else:
                return True
        return False

    def is_unique(self, dices_list):
        for i in dices_list:
            if self.is_same(i):
                return False
        return True

import sys

n = int(sys.stdin.readline())

dices = []

for i in range(n):
    str_list = sys.stdin.readline().split()
    new_dice = Dice(str_list)
    if not new_dice.is_unique(dices):
        print('No')
        break
    dices.append(new_dice)
else:
    print('Yes')