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:
    def __init__(self, nums):
        self.top    = nums[0]
        self.front  = nums[1]
        self.right  = nums[2]
        self.left   = nums[3]
        self.back   = nums[4]
        self.bottom = nums[5]

    def toN(self):
        tmp = self.top
        self.top = self.front
        self.front = self.bottom
        self.bottom = self.back
        self.back = tmp

    def toS(self):
        tmp = self.top
        self.top = self.back
        self.back = self.bottom
        self.bottom = self.front
        self.front = tmp

    def toE(self):
        tmp = self.top
        self.top = self.left
        self.left = self.bottom
        self.bottom = self.right
        self.right = tmp

    def toW(self):
        tmp = self.top
        self.top = self.right
        self.right = self.bottom
        self.bottom = self.left
        self.left = tmp

    def moveTo(self, ds):
        for d in ds:
            if   d == 'N':
                self.toN()
            if d == 'S':
                self.toS()
            if d == 'E':
                self.toE()
            if d == 'W':
                self.toW()

    def getTop(self):
        return self.top

    def getBottom(self):
        return self.bottom

    def getFront(self):
        return self.front

    def getBack(self):
        return self.back

    def getLeft(self):
        return self.left

    def getRight(self):
        return self.right

    def __eq__(self, other):
        if self.top != other.top:
            return False
        if self.bottom != other.bottom:
            return False
        if self.front != other.front:
            return False
        if self.back != other.back:
            return False
        if self.left != other.left:
            return False
        if self.right != other.right:
            return False

        return True

def moveTo(dice, top, front):
    if dice.getFront() != front:
        if   dice.getTop()    == front:
            dice.moveTo("S")
        elif dice.getBottom() == front:
            dice.moveTo("N")
        elif dice.getBack()   == front:
            dice.moveTo("NN")
        elif dice.getLeft()   == front:
            dice.moveTo("ES")
        elif dice.getRight()  == front:
            dice.moveTo("WS")

    if dice.getTop() != top:
        if   dice.getBottom() == top:
            dice.moveTo("EE")
        elif dice.getLeft()   == top:
            dice.moveTo("E")
        elif dice.getRight()  == top:
            dice.moveTo("W")

    return dice

def equalDice(dice1, dice2):
    dice2 = moveTo(dice2, dice1.getTop(), dice1.getFront())
    return dice1 == dice2

def main():
    n = int(input())
    dice1 = Dice(input().split())

    ans = "Yes"
    for _ in range(n-1):
        dice2 = Dice(input().split())

        if equalDice(dice1, dice2):
            ans = "No"
            break

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
class Dice:
  def __init__(self, top=1, front=2, left=4, right=3, back=5, bottom=6):
    self.d = {"TOP":top, "FRONT":front, "LEFT":left, "RIGHT":right, "BACK":back, "BOTTOM":bottom}

  def roll_x(self):
    self._roll("TOP", "FRONT", "BOTTOM", "BACK")
  
  def roll_y(self):
    self._roll("FRONT", "LEFT", "BACK", "RIGHT")
  
  def roll_z(self):
    self._roll("TOP", "LEFT", "BOTTOM", "RIGHT")
  
  def _roll(self, a, b, c, d):
    self.d[a], self.d[b], self.d[c], self.d[d] = \
    self.d[b], self.d[c], self.d[d], self.d[a]
  
  def all_rolls(self):
    ret = []
    for i in range(6):
      if i%2:
        self.roll_x()
      else:
        self.roll_y()
      for _ in range(4):
        self.roll_z()
        t = self.d.copy()
        ret.append(t)
    return ret

  def equivalent(self, dice):
    for i in range(6):
      if i%2:
        self.roll_x()
      else:
        self.roll_y()
      for _ in range(4):
        self.roll_z()
        t = self.d.copy()
        if t==dice.d:
          return True
    return False

n = int(input())
d = []
flag = False
for i in range(n):
  a = list(map(int, input().split()))
  d.append(Dice(a[0], a[1], a[3], a[2], a[4], a[5]))
for i in range(n):
  for j in range(i+1, n):
    if d[i].equivalent(d[j]):
      flag = True
      break
if flag:
  print("No")
else:
  print("Yes")

Solution (Python):
class Dice:
	
	def __init__(self, nums):
		self.nums = nums
		self.cU = nums[0]
		self.cS = nums[1]
		self.cE = nums[2]
		self.cW = nums[3]
		self.cN = nums[4]
		self.cD = nums[5]
	def goN(self):
		pU,pS,pN,pD = self.cU,self.cS,self.cN,self.cD
		self.cU,self.cS,self.cN,self.cD = pS,pD,pU,pN
	def goE(self):
		pU,pE,pW,pD = self.cU,self.cE,self.cW,self.cD
		self.cU,self.cE,self.cW,self.cD = pW,pU,pD,pE
	def goW(self):
		pU,pE,pW,pD = self.cU,self.cE,self.cW,self.cD
		self.cU,self.cE,self.cW,self.cD = pE,pD,pU,pW
	def goS(self):
		pU,pS,pN,pD = self.cU,self.cS,self.cN,self.cD
		self.cU,self.cS,self.cN,self.cD = pN,pU,pD,pS
	def toU(self, num):
		if self.cD == num:
			for _ in range(2): self.goN()
		elif self.cN == num: self.goS()
		elif self.cE == num: self.goW()
		elif self.cW == num: self.goE()
		elif self.cS == num: self.goN()
	def right(self, num):
		if self.cN == num: return self.cW
		elif self.cE == num: return self.cN
		elif self.cW == num: return self.cS
		elif self.cS == num: return self.cE
		else: raise 
	def equals(self, dice):
		"""?????????????????¨????????????????????¢????????????????????§??¨???"""
		for i in self.nums:
			if dice.nums.count(i) == 1:
				self.toU(i)
				dice.toU(i)
				break
		if self.cU == dice.cU and self.cD == dice.cD:
			nesw1 = ''.join(list(map(str, [self.cN,self.cE,self.cS,self.cW])))
			nesw1 += nesw1
			nesw2 = ''.join(list(map(str, [dice.cN,dice.cE,dice.cS,dice.cW])))
			if nesw1.count(nesw2) > 0: return True
			else: return False
		else: return False
dice = [Dice(list(map(int, input().split(' ')))) for _ in range(int(input()))]
pre = None
rslt = True
for die in dice:
	if pre == None: 
		pre = die
		continue
	if pre.equals(die):
		rslt = False
		break
if rslt: print('Yes')
else: print('No')