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: Runtime Error

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 = 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 g else "No")

Submission status: Runtime Error

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

?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°????????????????????????????????????
   +--+
 ???|???|
+--+--+--+--+
|???|???|???|???|
+--+--+--+--+
 ???|???|
   +--+

"""

class Dice:
    T = 0
    S = 1
    E = 2
    W = 3
    N = 4
    B = 5

    """ ????????????????????? """
    def __init__(self):
        """ ????????????????????? """
        self.side = [1, 2, 3, 4, 5, 6]
        self.top = 0

    def setDice(self, arr):
        """ ??¢?????????????????? """
        self.side = arr[0:6]

    def Turn(self, dir):
        """ ?????????????????¢?????? """
        s = self.side

        if dir == "N":     # ????????¢??????
            #    Top 0     South 1   East 2    West 3    North 4   Bottom 5
            t = [s[Dice.S],s[Dice.B],s[Dice.E],s[Dice.W],s[Dice.T],s[Dice.N]]
        elif dir == "S": # ????????¢??????
            t = [s[Dice.N],s[Dice.T],s[Dice.E],s[Dice.W],s[Dice.B],s[Dice.S]]
        elif dir == "E": # ??±?????¢??????
            t = [s[Dice.W],s[Dice.S],s[Dice.T],s[Dice.B],s[Dice.N],s[Dice.E]]
        elif dir == "W": # ?\??????¢??????
            t = [s[Dice.E],s[Dice.S],s[Dice.B],s[Dice.T],s[Dice.N],s[Dice.W]]
        elif dir == "L": # ???????????¢
            t = [s[Dice.T],s[Dice.W],s[Dice.S],s[Dice.N],s[Dice.E],s[Dice.B]]
        elif dir == "R": # ???????????¢
            t = [s[Dice.T],s[Dice.E],s[Dice.N],s[Dice.S],s[Dice.W],s[Dice.B]]

        self.side = t
#        print("{0} T0:{1} S1:{2} W2:{3} E3:{4} N4:{5} B5:{6} ".format(dir, self.side[0],self.side[1], self.side[2],self.side[3], self.side[4],self.side[5]))

    def Search(self, tval, sval, dir):
    """ ?????¢??¨?????¢???????????????????????????????????¢??????????????? """
    
#        print("{0} T0:{1} S1:{2} W2:{3} E3:{4} N4:{5} B5:{6} ".format(dir, self.side[0],self.side[1], self.side[2],self.side[3], self.side[4],self.side[5]))
    
        if self.side[Dice.E] == tval:
            self.Turn("W")
        elif self.side[Dice.W] == tval:
            self.Turn("E")
        elif self.side[Dice.N] == tval:
            self.Turn("S")
        elif self.side[Dice.S] == tval:
            self.Turn("N")
        elif self.side[Dice.B] == tval:
            self.Turn("N")
            self.Turn("N")

        for i in range(3): # ?????¢?????????????????????????????§????????????
            if self.side[Dice.S] == sval:
                break
            self.Turn("L")
            
        return self.side[dir]

# ?????????
d = []
num = int(input().strip())

for i in range(num): # ??????????????????
    tmp = Dice()
    tmp.setDice(list(map(int,input().strip().split())))
    d.append(tmp)

ret = "Yes"

for i in range(num-1):
    for j in range(i + 1,num):
        v1 = d[i].Search(d[i].side[Dice.T], d[i].side[Dice.S], Dice.E)
        v2 = d[j].Search(d[i].side[Dice.T], d[i].side[Dice.S], Dice.E)
#        print("{0}/{1} V1={2} V2={3}".format(i,j,v1,v2))
        if v1 == v2:
            ret = "No"
            break
    if ret == "No":
        break

print(ret)

Submission status: Runtime Error

Solution code:
class Dice():
    def __init__(self,ary):
        self.top = ary[0]
        self.south = ary[1]
        self.east = ary[2]
        self.west = ary[3]
        self.north = ary[4]
        self.bottom = ary[5]

    def get_top(self):
        return self.top

    def rotate_north(self):
        self.top,self.south,self.north,self.bottom = self.south,self.bottom,self.top,self.north
    
    def rotate_south(self):
        self.top,self.south,self.north,self.bottom = self.north,self.top,self.bottom,self.south

    def rotate_west(self):
        self.top,self.west,self.bottom,self.east = self.east,self.top,self.west,self.bottom

    def rotate_east(self):
        self.top,self.west,self.bottom,self.east = self.west,self.bottom,self.east,self.top

    def rotate_horizon(self):
        self.south,self.east,self.north,self.west = self.west,self.south,self.east,self.north

    def get_east(self):
        return self.east

q = int(input())
dice1 = Dice(list(map(int,input().split())))
for i in range(q-1):
    dice2 = Dice(list(map(int,input().split())))
    h=""
    for i in range(4):
        dice2.rotate_west()
        if dice1.top == dice2.top:
            for _ in range(4):
                dice2.rotate_horizon()
                if dice1.south == dice2.south:
                    if dice1.east == dice2.east and dice1.west == dice2.west:
                        h = True
    for _ in range(4):
        dice2.rotate_north()
        if dice1.top == dice2.top:
            for m in range(4):
                dice2.rotate_horizon()
                if dice1.south == dice2.south:
                    if dice1.east == dice2.east and dice1.west == dice2.west:
                        h = True
    if h:
        continue
    else:
        h="No"
        break
print(h="Yes")

Submission status: Runtime Error

Solution code:
class Checker:
    d = {
        1: { 2: (3,4,5,6), 3: (5,2,4,6), 4: (2,5,3,6), 5: (4,3,2,6) },
        2: { 1: (4,3,6,5), 3: (1,6,4,5), 4: (6,1,3,5), 6: (3,4,1,5) },
        3: { 1: (2,5,6,4), 2: (6,1,5,4), 5: (1,6,2,4), 6: (5,2,1,4) },
        4: { 1: (5,2,6,3), 2: (1,6,5,3), 5: (6,1,2,3), 6: (2,5,1,3) },
        5: { 1: (3,4,6,2), 3: (6,1,4,2), 4: (1,6,3,2), 6: (4,3,1,2) },
        6: { 2: (4,3,5,1), 3: (2,5,4,1), 4: (5,2,3,1), 5: (3,4,2,1) }
        }

    def __init__(self, s):
        l = s.split()
        self.tbl = {}
        for c,i in zip(l, range(1,7)):
            if c in self.tbl:
                self.tbl[c].append(i)
            else:
                self.tbl[c] = [i]
        self.pip = dict(zip(range(1,7), l))

    def __call__(self, s):
        l = s.split()
        for i0 in self.tbl[l[0]]:
            for i1 in self.tbl[l[1]]:
                if i1 in self.d[i0]:
                    for i,j in zip(self.d[i0][i1], range(2,6)):
                        if self.pip[i] != l[j]:
                            break
                    else:
                        return True
        return False

def g():
    n = int(input()) - 1
    c = Checker(input())
    for _ in range(n):
        yield c(input())

if any(g()):
    print("No")
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
import random


class Dice(object):
    def __init__(self):
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6

    def __init__(self, faces):
        self.t = faces[0]
        self.s = faces[1]
        self.e = faces[2]
        self.w = faces[3]
        self.n = faces[4]
        self.b = faces[5]

    def roll(self, direct):
        if direct == 0:
            self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
        elif direct == 1:
            self.t, self.w, self.b, self.e = self.e, self.t, self.w, self.b
        elif direct == 2:
            self.n, self.w, self.s, self.e = self.w, self.s, self.e, self.n

    def is_equal(self, dice):
        if self.t == dice.t and self.s == dice.s and self.e == dice.e and self.w == dice.w and self.n == dice.n and self.b == dice.b:
            return True
        else:
            return False

n = int(input())
dice_list = []
flag = True
for _ in range(n):
    faces = list(map(int, input().split()))
    dice_list.append(Dice(faces1))

    if n == 0:
        continue

    dice_a, dice_b = dice_list[0], dice_list[-1]

    for i in range(10000):
        dice_b.roll(random.randint(0, 3))
        if dice_a.is_equal(dice_b):
            break
        if i + 1 == 10000:
            flag = False

    if not flag:
        break

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
for k in range(n):
 b=a[k];b[3],b[4]=b[4],b[3]
t=0
for i in range(n-1):
 d=a[i]
 for j in range(i+1,n):
  e=a[j]
  for p in('012345','152043','215304','302541','410352','514320'):
   f=[d[int(k)]for k in p]
   if f[0]==e[0]and f[5]==e[5]:
    f=f[1:5]*2
    [t=1 for k in range(4)if f[k:k+4]==e[1:5]]
print(('Yes','No')[t])

Submission status: Runtime Error

Solution code:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
for k in range(n):
 b=a[k];b[3],b[4]=b[4],b[3]
t=0
while 1:
 try:
  for i in range(n-1):
   d=a[i]
   for j in range(i+1,n):
    e=a[j]
    for p in('012345','152043','215304','302541','410352','514320'):
     f=[d[int(k)]for k in p]
     if f[0]==e[0]and f[5]==e[5]:
      f=f[1:5]*2
      for k in range(4):
       if f[k:k+4]==e[1:5]:t=1;raise Exception
 finally:
  print(('Yes','No')[t])

Submission status: Runtime Error

Solution code:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
for k in range(n):
b=a[k];b[3],b[4]=b[4],b[3]
def f():
 for i in range(n-1):
  d=a[i]
  for j in range(i+1,n):
   e=a[j]
   for p in('012345','152043','215304','302541','410352','514320'):
    f=[d[int(k)]for k in p]
    if f[0]==e[0]and f[5]==e[5]:
     f=f[1:5]*2
     for k in range(4):
      if f[k:k+4]==e[1:5]:return 'No'
 return 'Yes'
print(f())

Submission status: Runtime Error

Solution code:
def g():
 from itertools import*
 n=int(input())
 a=[input().split()for _ in[0]*n]
 for b in a:
  b[3:5]=b[4],b[3]
 for d,e in combinations(a,2):
  for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
   f=[d[i]for i in p]
   if f[0]==e[0]and f[5]==e[5]:
    f=f[1:5]*2
    for k in range(4):
     if f[k:k+4]==e[1:5]:return'No'
 return'Yes'
print(g())

Submission status: Runtime Error

Solution code:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.a=[[t,f,r,l,b,u]]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d,n):
        self.a[n]=[self.a[n][i] for i in self.direction[d]]
        self.t = self.a[0]
        self.f = self.a[1]
        self.r = self.a[2]
        self.l = self.a[3]
        self.b = self.a[4]
        self.u = self.a[5]
n=int(input())
for i in range(n):
    if i==0:
        t,f,r,l,b,u = map(int, input().split())
        dice = Dice(t, f, r, l, b, u)
    else:
        a = list(map(int, input().split()))
        dice.a.append(a)
s='SSSWEEE'
w='YYYY'
ans='Yes'
for u in range(n-1):
    for t in range(u+1,n):
        for j in s:
            for r in w:
                if dice.a[t]==dice.a[u]:
                    ans='No'
                    break
                dice.roll(r,t)
            else:
                dice.roll(j,t)
                continue
            break
        else:
            continue
        break
    else:
        continue
    break
print(ans)

Submission status: Runtime Error

Solution code:

ans=chk=0
a=[0,2,5,3]
b=[0,1,5,4]
c=[1,2,4,3]
 
def sortdice(dice1,dice2,p,q,r):
    for i in range(4):
        dice1[p[0]],dice1[p[1]],dice1[p[2]],dice1[p[3]]=dice1[p[1]],dice1[p[2]],dice1[p[3]],dice1[p[0]]
        for j in range(4):
            dice1[q[0]],dice1[q[1]],dice1[q[2]],dice1[q[3]]=dice1[q[1]],dice1[q[2]],dice1[q[3]],dice1[q[0]]
            for k in range(4):
                dice1[r[0]],dice1[r[1]],dice1[r[2]],dice1[r[3]]=dice1[r[1]],dice1[r[2]],dice1[r[3]],dice1[r[0]]
                if dice1==dice2:
                    print 'Yes'
                    exit()
    return 0
  
l1=map(int,raw_input().split())
l2=map(int,raw_input().split())
sortdice(l1,l2,a,b,c)
print 'No'

Submission status: Runtime Error

Solution code:
class Dice:
    def __init__(self, a1, a2, a3, a4, a5, a6):
        # サイコロを縦横にたどると書いてある数字(index1は真上、index3は真下の数字)
        self.face = [a1, a2, a3, a4, a5, a6]
        self.v = [a5, a1, a2, a6] # 縦方向
        self.h = [a4, a1, a3, a6] # 横方向
        self.det = 1
        # print(self.v, self.h)

    # サイコロの上面の数字を表示
    def top(self):
        return self.v[1]

    # サイコロを北方向に倒す
    def north(self):
        newV = [self.v[1], self.v[2], self.v[3], self.v[0]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    # サイコロを南方向に倒す
    def south(self):
        newV = [self.v[3], self.v[0], self.v[1], self.v[2]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    # サイコロを東方向に倒す
    def east(self):
        newH = [self.h[3], self.h[0], self.h[1], self.h[2]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

    # サイコロを西方向に倒す
    def west(self):
        newH = [self.h[1], self.h[2], self.h[3], self.h[0]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

diceAmount = int(input())
dices = []
for i in range(diceAmount):
    d = [int(j) for j in input().rstrip().split()]
    dice = Dice(d[0], d[1], d[2], d[3], d[4], d[5])
    dices.append(dice)
Dice IV
import random
match = 0
diceCount = 1
while match == 0 and diceCount < diceAmount:
    for d2 in range(1, diceAmount):
        # print(d2)
        i = 0
        while match == 0 and i < 24:
            j = random.randint(0, 3)
            if j == 0:
                dices[d2].north()
            elif j == 1:
                dices[d2].south()
            elif j == 2:
                dices[d2].east()
            elif j == 3:
                dices[d2].west()
            for d1 in range(d2):
                if (dices[d1].v == dices[d2].v and dices[d1].h == dices[d2].h):
                    match += 1
                    # print('一致')
            i += 1
    diceCount += 1
if match >= 1:
    print('No')
else:
    print('Yes')

Submission status: WA: Presentation Error

Solution code:
class Dice():
    def __init__(self,ary):
        self.top = ary[0]
        self.south = ary[1]
        self.east = ary[2]
        self.west = ary[3]
        self.north = ary[4]
        self.bottom = ary[5]

    def get_top(self):
        return self.top

    def rotate_north(self):
        self.top,self.south,self.north,self.bottom = self.south,self.bottom,self.top,self.north
    
    def rotate_south(self):
        self.top,self.south,self.north,self.bottom = self.north,self.top,self.bottom,self.south

    def rotate_west(self):
        self.top,self.west,self.bottom,self.east = self.east,self.top,self.west,self.bottom

    def rotate_east(self):
        self.top,self.west,self.bottom,self.east = self.west,self.bottom,self.east,self.top

    def rotate_horizon(self):
        self.south,self.east,self.north,self.west = self.west,self.south,self.east,self.north

    def get_east(self):
        return self.east

q = int(input())
dice1 = Dice(list(map(int,input().split())))
for i in range(q-1):
    dice2 = Dice(list(map(int,input().split())))
    h=""

    for i in range(4):
        dice2.rotate_west()
        if dice1.top == dice2.top:
            for _ in range(4):
                dice2.rotate_horizon()
                if dice1.south == dice2.south:
                    if dice1.east == dice2.east and dice1.west == dice2.west:
                        h = "Yes"
    for _ in range(4):
        dice2.rotate_north()
        if dice1.top == dice2.top:
            for m in range(4):
                dice2.rotate_horizon()
                if dice1.south == dice2.south:
                    if dice1.east == dice2.east and dice1.west == dice2.west:
                        h = "Yes"
    if h:
        continue
    else:
        print("No")
        break
print(h)