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: Wrong Answer

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 (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["top"] == self.faces["top"] and dice1.faces["east"] == self.faces["east"]):
                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):
            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: Wrong Answer

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["top"] == self.faces["top"] and dice1.faces["east"] == self.faces["east"]):
                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: Wrong Answer

Solution code:
#-*- coding:utf-8 -*-
import sys
n = input()
rolls =[]
for x in xrange(n):
    rolls.append(raw_input().split())
def pareExist(li1,li2):
    for x in xrange(3):
        if set(rolls1pare[x]) not in map(set,rolls2pare):
            return False
    return True
#??????????????¨??????????????????????????????
#?????´????????????????????¨??????????????£???????????§??????
for l1 in xrange(n):
    for l2 in xrange(n):
        #??????????????????????????????
        #?????????????????????????????´????????????????????????????????????????????£????????????????????????
        if l1==l2:
            break
        rolls_copy = rolls
        #??¨??¨????????¢?????£????????????????????´???????????¢???3????????¨??????????¢????
        rolls1pare = [(rolls_copy[l1][0],rolls_copy[l1][5]),(rolls_copy[l1][2],rolls_copy[l1][3]),(rolls_copy[l1][1],rolls_copy[l1][4])]
        testpare = (rolls_copy[l1][0],rolls_copy[l1][5])
        testparerev = (rolls_copy[l1][5],rolls_copy[l1][0])
        rolls2pare = [(rolls_copy[l2][0],rolls_copy[l2][5]),(rolls_copy[l2][2],rolls_copy[l2][3]),(rolls_copy[l2][1],rolls_copy[l2][4])]
        # print rolls1pare
        # print rolls2pare
        #?????????????????¢???????????°?????´?????????????????????
        if not pareExist(rolls1pare,rolls2pare):
            break
        #??????????????¢????????¢??§?????´??????????????????????????????????¢????
        if testpare in rolls2pare:
            pareps = rolls2pare.index(testpare)
            revflag = False
        elif testparerev in rolls2pare:
            pareps = rolls2pare.index(testparerev)
            revflag = True
        else:
            break
        #?¬???????????????¢??\????????¨????????????????????£??????????¢????
        #??????????????????????????????
        li1 = [rolls_copy[l1][1],rolls_copy[l1][2],rolls_copy[l1][4],rolls_copy[l1][3]]
        # print pareps
        if pareps==0:
            if revflag:
                tmp = rolls_copy[l2][2]
                rolls_copy[l2][2] = rolls_copy[l2][3]
                rolls_copy[l2][3] = tmp
            li2 = [rolls_copy[l2][1],rolls_copy[l2][2],rolls_copy[l2][4],rolls_copy[l2][3]]
        elif pareps==1:
            if revflag:
                tmp = rolls_copy[l2][1]
                rolls_copy[l2][1] = rolls_copy[l2][4]
                rolls_copy[l2][4] = tmp
            li2 = [rolls_copy[l2][0],rolls_copy[l2][1],rolls_copy[l2][5],rolls_copy[l2][4]]
        elif pareps==2:
            if revflag:
                tmp = rolls_copy[l2][0]
                rolls_copy[l2][0] = rolls_copy[l2][5]
                rolls_copy[l2][5] = tmp
            li2 = [rolls_copy[l2][0],rolls_copy[l2][3],rolls_copy[l2][5],rolls_copy[l2][2]]
        else:
            break
        #?????????????????´?¢????
        print li1
        print li2
        i=0
        j=li2.index(li1[0])
        matchflag = True#else??\??£???????????´?????????
        for x in xrange(4):
            # print "%s : %s"%(li1[i],li2[j])
            if li1[i]==li2[j]:
                j+=1
                i+=1
            else:
                matchflag =False
                break
            if i>3:
                i=0
            if j>3:
                j=0
        if matchflag:
            print "No"
            sys.exit(0)
print "Yes"

Submission status: Wrong Answer

Solution code:
class Dice():

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

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def rotate(self):
        self.change([1, 4, 2, 5, 3, 6])

    def change(self, convert):
        num = []
        for i in range(6):
            num.append(self.label[convert[i] - 1])
        self.label = num

    def is_same_dice(self, another_dice):
        for i in range(6):
            if i % 2 == 0:
                self.north()
            else:
                self.west()
            for j in range(4):
                self.rotate()
                if self.label == another_dice:
                    return True
        return False


def main():
    dices = []
    n = int(input())
    for i in range(n):
        dices.append(Dice([int(x) for x in input().split()]))

    flag = False
    for i in range(n):
        j = i + 1
        while j < n:
            if dices[i].is_same_dice(dices[j]):
                flag = True
                break
            j += 1

    if flag:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# ?????????????????¨????????????
class Dice(object):
	def __init__(self, L=[1, 2, 3, 4, 5, 6]):
		# ????????¶???
		self.dice = (L[1], L[4]), (L[2], L[3]), (L[0], L[5]) # x, y, z
		self.ax = [[0, False], [1, False], [2, False]]
		self.axmap = [0, 1, 2]
		self.mm = {"N": (0, 2), "S": (2, 0), "E": (1, 2), "W": (2, 1), "R": (0, 1), "L": (1, 0)}

	def rotate(self, dir):
		def rot(k, r):
			t = self.axmap[r]
			self.axmap[k], self.axmap[r] = t, self.axmap[k]
			self.ax[t][1] = not self.ax[t][1]

		rot(*self.mm[dir])

	def front(self): return self.value(0, True)
	def rear(self): return self.value(0, False)
	def right(self): return self.value(1, True)
	def left(self): return self.value(1, False)
	def top(self): return self.value(2, True)
	def bottom(self): return self.value(2, False)
	def value(self, ax, d):
		a = self.ax[self.axmap[ax]]
		return self.dice[a[0]][a[1] if d else not a[1]]

	def __eq__(self, dice):
		def tf(p, f, d):
			for _ in range(4):
				if p==f(): break
				dice.rotate(d)
		p = self.top()
		f = dice.top
		tf(p, f, "N")
		if p!=f(): tf(p, f, "E")
		
		p = self.front()
		f = dice.front
		tf(p, f, "R")
		return self.left()==dice.left()

if __name__=="__main__":
	dices = []
	n = int(input())
	for _ in range(n):
		dice = Dice(input().split())
		for d in dices:
			if dice==d:
				print("No")
				exit(0)
		dices.append(dice)
	print("Yes")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# ?????????????????¨????????????
class Dice(object):
	def __init__(self, L=[1, 2, 3, 4, 5, 6]):
		# ????????¶???
		self.dice = (L[1], L[4]), (L[2], L[3]), (L[0], L[5]) # x, y, z
		self.ax = [[0, False], [1, False], [2, False]]
		self.axmap = [0, 1, 2]
		self.mm = {"N": (0, 2), "S": (2, 0), "E": (1, 2), "W": (2, 1), "R": (0, 1), "L": (1, 0)}

	def rotate(self, dir):
		def rot(k, r):
			t = self.axmap[r]
			self.axmap[k], self.axmap[r] = t, self.axmap[k]
			self.ax[t][1] = not self.ax[t][1]

		rot(*self.mm[dir])

	def front(self): return self.value(0, True)
	def rear(self): return self.value(0, False)
	def right(self): return self.value(1, True)
	def left(self): return self.value(1, False)
	def top(self): return self.value(2, True)
	def bottom(self): return self.value(2, False)
	def value(self, ax, d):
		a = self.ax[self.axmap[ax]]
		return self.dice[a[0]][a[1] if d else not a[1]]

	def __eq__(self, dice):
		def tf(p, f, d):
			for _ in range(4):
				if p==f(): break
				dice.rotate(d)
		p = self.top()
		f = dice.top
		tf(p, f, "N")
		if p!=f(): tf(p, f, "E")
		
		p = self.front()
		f = dice.front
		tf(p, f, "R")
		for i in range(3):
			for b in (True, False):
				if self.value(i, b)!=dice.value(i, b):
					return False
		return True

if __name__=="__main__":
	dices = []
	n = int(input())
	for _ in range(n):
		dice = Dice(input().split())
		for d in dices:
			if dice==d:
				print("No")
				exit(0)
		dices.append(dice)
	print("Yes")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# ?????????????????¨????????????
class Dice(object):
	def __init__(self, L=[1, 2, 3, 4, 5, 6]):
		# ????????¶???
		self.dice = (L[1], L[4]), (L[2], L[3]), (L[0], L[5]) # x, y, z
		self.ax = [[0, False], [1, False], [2, False]]
		self.axmap = [0, 1, 2]
		self.mm = {"N": (0, 2), "S": (2, 0), "E": (1, 2), "W": (2, 1), "R": (0, 1), "L": (1, 0)}

	def rotate(self, dir):
		def rot(k, r):
			t = self.axmap[r]
			self.axmap[k], self.axmap[r] = t, self.axmap[k]
			self.ax[t][1] = not self.ax[t][1]

		rot(*self.mm[dir])
	
	def reverse(self, ax):
		self.ax[ax][1] = not self.ax[ax][1]
		rev = [(1, 2), (2, 0), (0, 1)][ax]
		self.axmap[rev[1]], self.axmap[rev[0]] = self.axmap[rev[0]], self.axmap[rev[1]]

	def front(self): return self.value(0, True)
	def rear(self): return self.value(0, False)
	def right(self): return self.value(1, True)
	def left(self): return self.value(1, False)
	def top(self): return self.value(2, True)
	def bottom(self): return self.value(2, False)
	def value(self, ax, d):
		a = self.ax[self.axmap[ax]]
		return self.dice[a[0]][a[1] if d else not a[1]]

	def __eq__(self, dice):
		#???????????????????????????????¢??????????
		# z???????????§????????????????????´??????????????????????????°?????????????????§NG
		# ????????\?????????z????????????????????¢??§?????´????????????????????§????????¢??????????????´??????????????°NG
		# z???????????´?????????
		idx = -1
		for i, ax in enumerate(self.dice):
			if dice.top() in ax and dice.bottom() in ax:
				idx = i
				# i = 0 = x => 0, 2 ?????????
				# i = 1 = y => 1, 2 ?????????
				# i = 2 = z => ????????????????????±?????????
				if i != 2:
					self.reverse((i+1)%2)
				break

		if idx==-1:
			return False
		
		# z(2)?????????????¢????
		if self.top() != dice.top():
			self.reverse(2)

		# x, y???????¢????
		for _ in range(4):
			r = 0
			for x in range(2):
				for b in (True, False):
					if self.value(x, b) != dice.value(x, b):
						break
					else:
						r += 1

				if r<2:
					break

			if r==4:
				return True
			else:
				self.rotate("R")

		return False

if __name__=="__main__":
	n = int(input())
	differed = True
	dices = [Dice(input().split())]
	for _ in range(1, n):
		dice = Dice(input().split())
		for d in dices:
			if differed and dice==d:
				differed = False
		dices.append(dice)
	print("Yes" if differed else "No")

Submission status: Wrong Answer

Solution code:
class Dice(object):
    """Dice Class

    """

    def __init__(self, numbers):
        """

        Args:
            numbers:
        """
        self.numbers_inverse = {numbers[0]: 1, numbers[1]: 2, numbers[2]: 3, numbers[3]: 4, numbers[4]: 5,
                                numbers[5]: 6}
        self.numbers = {1: numbers[0], 2: numbers[1], 3: numbers[2], 4: numbers[3], 5: numbers[4], 6: numbers[5]}

        self.vertical = [self.numbers[1], self.numbers[2], self.numbers[6], self.numbers[5]]
        self.horizontal = [self.numbers[4], self.numbers[1], self.numbers[3], self.numbers[6]]

    def roll_dice(self, str):
        """

        Args:
            str: move direction

        Returns:

        """
        for s in str:
            if s == 'N':
                self.move_north()
            elif s == 'S':
                self.move_south()
            elif s == 'W':
                self.move_west()
            elif s == 'E':
                self.move_east()

    def set_top(self, value):
        """
        Args:
            value: target_value
        """
        counter = 0
        while counter < 4:
            if self.vertical[0] == value:
                self.map_values()
                return
            else:
                self.roll_dice("S")
            counter += 1
        counter = 0
        while counter < 4:
            if self.vertical[0] == value:
                self.map_values()
                return
            else:
                self.roll_dice("W")
            counter += 1

    def set_front(self, value):
        """
        Args:
            value: target value
        """
        counter = 0
        while counter < 4:
            if self.vertical[1] == value:
                self.map_values()
                return
            else:
                self.roll_dice("SWN")
            counter += 1

    def move_south(self):
        """move this dice towered north
        """
        self.vertical = (self.vertical * 2)[3:7]
        self.horizontal[1] = self.vertical[0]
        self.horizontal[3] = self.vertical[2]
        self.map_values()

    def move_north(self):
        """move this dice towered south
        """
        self.vertical = (self.vertical * 2)[1:5]
        self.horizontal[1] = self.vertical[0]
        self.horizontal[3] = self.vertical[2]
        self.map_values()

    def move_east(self):
        """move this dice towered east
        """
        self.horizontal = (self.horizontal * 2)[3:7]
        self.vertical[0] = self.horizontal[1]
        self.vertical[2] = self.horizontal[3]
        self.map_values()

    def move_west(self):
        """move this dice towered west
        """
        self.horizontal = (self.horizontal * 2)[1:5]
        self.vertical[0] = self.horizontal[1]
        self.vertical[2] = self.horizontal[3]
        self.map_values()

    def map_values(self):
        self.numbers[1] = self.vertical[0]
        self.numbers[2] = self.vertical[1]
        self.numbers[3] = self.horizontal[2]
        self.numbers[4] = self.horizontal[0]
        self.numbers[5] = self.vertical[3]
        self.numbers[6] = self.vertical[2]

    def get_top(self):
        return self.vertical[0]


def is_same(dice1, dice2):
    """compare two dices

    Args:
        dice1: dice1
        dice2: dice2

    Returns:
        Bool (whether dice1 is equals to be dice2 or not)
    """
    flag = False
    if dice1.numbers == dice2.numbers:
        flag = True
    elif set(dice1.numbers_inverse.keys()) == set(dice2.numbers_inverse.keys()):
        flag = False
    else:
        for i in range(6):
            dice1.set_top(i + 1)
            for j in xrange(4):
                dice1.roll_dice("SWN")
                if dice1.numbers == dice2.numbers:
                    flag = True
            dice1.roll_dice("S")

    return flag


dice_number = int(raw_input())
dices = []
counter = 0
while counter < dice_number:
    dices.append(Dice([int(x) for x in raw_input().split()]))
    counter += 1

ans = 0
for i in range(dice_number - 1):
    if ans > 0:
        break
    for j in range(i + 1, dice_number):
        ans += int(is_same(dices[i], dices[j]))
        if ans > 0:
            print("No")
            break

if ans == 0:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

dice = [[0 for i in range(6)] for j in range(n)]
for i in range(n):
    dice[i] = map(int, raw_input().split())
 
def rolling(inst, dice):
    if inst == 'E':
        dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
    elif inst == 'W':
        dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
    elif inst == 'N':
        dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
    elif inst == 'S':
        dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
 
count = 0
def dice_matching(dice1, dice2):
    if dice1[1] == dice2[1]:
        for i in range(3):
            if dice1 == dice2:
                return 1
                break
            rolling('E', dice2)
        return 0
    else:
        return 0

count = 0
flag = 0
for i in range(n):
    for j in range(i+1, n):
        if dice_matching(dice[i], dice[j]) == 1:
            flag = 1
            print 'No'
            break
        else:
            if count < 3:
                rolling('N', dice[j])
                count += 1
            elif 6 > count and count >= 3:
                rolling('E', dice[j])
                count += 1
if flag == 0:
    print 'Yes'

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

dice = [[0 for i in range(6)] for j in range(n)]
for i in range(n):
    dice[i] = map(int, raw_input().split())
 
def rolling(inst, dice):
    if inst == 'E':
        dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
    elif inst == 'W':
        dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
    elif inst == 'N':
        dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
    elif inst == 'S':
        dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
 
def dice_matching(dice1, dice2):
    if dice1[1] == dice2[1]:
        for i in range(3):
            if dice1 == dice2:
                return 1
                break
            rolling('E', dice2)
        return 0
    else:
        return 0

count = 0
flag = 0
for i in range(n):
    for j in range(i+1, n):
        if dice_matching(dice[i], dice[j]) == 1:
            flag = 1
            print 'No'
            break
    else:
        if count < 3:
            rolling('N', dice[j])
            count += 1
        elif 7 > count and count >= 3:
            if count == 3:
                rolling('E', dice[j])
            rolling('N', dice[j])
            count += 1
if flag == 0:
    print 'Yes'

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

dice = [[0 for i in range(6)] for j in range(n)]
for i in range(n):
    dice[i] = map(int, raw_input().split())
 
def rolling(inst, dice):
    if inst == 'E':
        dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
    elif inst == 'W':
        dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
    elif inst == 'N':
        dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
    elif inst == 'S':
        dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
 
def dice_matching(dice1, dice2):
    if dice1[1] == dice2[1]:
        for i in range(4):
            if dice1 == dice2:
                return 1
                break
            rolling('E', dice2)
        return 0
    else:
        return 0

count = 0
flag = 0
for i in range(n):
    for j in range(i+1, n):
        if dice_matching(dice[i], dice[j]) == 1:
            flag = 1
            print 'No'
            break
    else:
        if count < 3:
            rolling('N', dice[j])
            count += 1
        elif 7 > count and count >= 3:
            if count == 3:
                rolling('E', dice[j])
            rolling('N', dice[j])
            count += 1
if flag == 0:
    print 'Yes'

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

dice = [[0 for i in range(6)] for j in range(n)]
for i in range(n):
    dice[i] = map(int, raw_input().split())
 
def rolling(inst, dice):
    if inst == 'E':
        dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
    elif inst == 'W':
        dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
    elif inst == 'N':
        dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
    elif inst == 'S':
        dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
 
count = 0
def dice_matching(dice1, dice2):
    if dice1[1] == dice2[1]:
        for i in range(4):
            if dice1 == dice2:
                return 1
                break
            rolling('E', dice2)
        return 0
    else:
        return 0
        
count = 0
flag = 0
for i in range(n):
    for j in range(i+1, n):
        if dice_matching(dice[i], dice[j]) == 1:
            flag = 1
            print 'No'
            break
    else:
        if count < 3:
            rolling('N', dice[j])
            count += 1
        elif 7 > count and count >= 3:
            if count == 3:
                rolling('E', dice[j])
            rolling('N', dice[j])
            count += 1
if flag == 0:
    print 'Yes'

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

dice = [[0 for i in range(6)] for j in range(n)]
for i in range(n):
    dice[i] = map(int, raw_input().split())
 
def rolling(inst, dice):
    if inst == 'E':
        dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
    elif inst == 'W':
        dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
    elif inst == 'N':
        dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
    elif inst == 'S':
        dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
 
def dice_matching(dice1, dice2):
    if dice1[1] == dice2[1]:
        for i in range(4):
            if dice1 == dice2:
                return 1
                break
            rolling('E', dice2)
        return 0
    else:
        return 0
        
count = 0
flag = 0
for i in range(n):
    for j in range(i+1, n):
        while(1):
            if dice_matching(dice[i], dice[j]) == 1:
                flag = 1
                print 'No'
                break
            else:
                if count < 3:
                    rolling('N', dice[j])
                    count += 1
                elif 7 > count and count >= 3:
                    if count == 3:
                        rolling('E', dice[j])
                    rolling('N', dice[j])
                    count += 1
                else:
                    break
if flag == 0:
    print 'Yes'

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

dice = [[0 for i in range(6)] for j in range(n)]
for i in range(n):
    dice[i] = map(int, raw_input().split())
 
def rolling(inst, dice):
    if inst == 'E':
        dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
    elif inst == 'W':
        dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
    elif inst == 'N':
        dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
    elif inst == 'S':
        dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
 
def dice_matching(dice1, dice2):
    if dice1[1] == dice2[1]:
        for i in range(4):
            if dice1 == dice2:
                return 1
                break
            rolling('E', dice2)
        return 0
    else:
        return 0
        
flag = 0
for i in range(n):
    for j in range(i+1, n):
        count = 0
        while(1):
            if dice_matching(dice[i], dice[j]) == 1:
                flag = 1
                print 'No'
                break
            else:
                if count < 3:
                    rolling('N', dice[j])
                    count += 1
                elif 7 > count and count >= 3:
                    if count == 3:
                        rolling('E', dice[j])
                    rolling('N', dice[j])
                    count += 1
                else:
                    break
if flag == 0:
    print 'Yes'

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

dice = [[0 for i in range(6)] for j in range(n)]
for i in range(n):
    dice[i] = map(int, raw_input().split())
 
def rolling(inst, dice):
    if inst == 'E':
        dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
    elif inst == 'W':
        dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
    elif inst == 'N':
        dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
    elif inst == 'S':
        dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
 
def dice_matching(dice1, dice2):
    if dice1[1] == dice2[1]:
        for i in range(4):
            if dice1 == dice2:
                return 1
                break
            rolling('E', dice2)
        return 0
    else:
        return 0

def alldice_matching(dice1, dice2):
    count = 0
    while(1):
        if dice_matching(dice1, dice2) == 1:
            return 1
        else:
            if count < 3:
                rolling('N', dice2)
                count += 1
            elif 7 > count and count >= 3:
                if count == 3:
                    rolling('E', dice2)
                rolling('N', dice2)
                count += 1
            else:
                return 0

flag = 0
for i in range(n):
    for j in range(i+1, n):
        if alldice_matching(dice[i], dice[2]) == 1:
            flag = 1
            print "Yes"
            break
    if flag == 1:
        break
if flag == 0:
    print 'Yes'

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

dice = [[0 for i in range(6)] for j in range(n)]
for i in range(n):
    dice[i] = map(int, raw_input().split())
 
def rolling(inst, dice):
    if inst == 'E':
        dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
    elif inst == 'W':
        dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
    elif inst == 'N':
        dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
    elif inst == 'S':
        dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
 
def dice_matching(dice1, dice2):
    if dice1[1] == dice2[1]:
        for i in range(4):
            if dice1 == dice2:
                return 1
                break
            rolling('E', dice2)
        return 0
    else:
        return 0

def alldice_matching(dice1, dice2):
    count = 0
    while(1):
        if dice_matching(dice1, dice2) == 1:
            return 1
        else:
            if count < 3:
                rolling('N', dice2)
                count += 1
            elif 7 > count and count >= 3:
                if count == 3:
                    rolling('E', dice2)
                rolling('N', dice2)
                count += 1
            else:
                return 0

flag = 0
for i in range(n):
    for j in range(i+1, n):
        if alldice_matching(dice[i], dice[j]) == 1:
            flag = 1
            print "Yes"
            break
    if flag == 1:
        break
if flag == 0:
    print 'Yes'

Submission status: Wrong Answer

Solution code:
n=int(input())

class dice(object):
	def __init__(self, d):
		self.d = d

	def roll(self,com):
		a1,a2,a3,a4,a5,a6=self.d
		if com=="E":
			self.d = [a4,a2,a1,a6,a5,a3]
		elif com=="W":
			self.d = [a3,a2,a6,a1,a5,a4]
		elif com=="S":
			self.d = [a5,a1,a3,a4,a6,a2]
		elif com=="N":
			self.d = [a2,a6,a3,a4,a1,a5]

import random
ds=[]
for i in range(n):
	ds.append(dice(list(map(int,input().split()))))
flag="Yes"
for i in range(n):
	for j in range(i):
		if sorted(ds[i].d)!=sorted(ds[j].d):
			flag="No"
		else:
			c=["E","W","S","N"]
			n=0
			while n<100:
				if ds[i].d==ds[j].d:
					break 
				else:
					ds[i].roll(c[random.randint(1,2)])
				n+=1
			if n==100:
				pass
			else:
				flag="No"

print(flag)