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:
def main_1_11_A():
    values = list(map(int, input().split()))
    query = input()

    dice = Dice(values)
    for d in query:
        dice.roll(d)


def main_1_11_B():
    values = list(map(int, input().split()))
    n = int(input())

    for _ in range(n):
        t_value, s_value = map(int, input().split())

        print(_B(values, t_value, s_value))


def main_1_11_C():
    values_1 = list(map(int, input().split()))
    values_2 = list(map(int, input().split()))

    dice1 = Dice(values_1)
    dices = (
        make_dices(values_2) +
        list(map(lambda dice: rot_n(dice, 1), make_dices(values_2))) +
        list(map(lambda dice: rot_n(dice, 2), make_dices(values_2))) +
        list(map(lambda dice: rot_n(dice, 3), make_dices(values_2)))
    )
    for dice in dices:
        for d in ("E" * 4 + "W" * 4 + "S" * 4 + "N" * 4):
            dice.roll(d)
            if eq_dice(dice1, dice):
                print("Yes")
                return

    print("No")


def main_1_11_D():
    n = int(input())
    values_list = [
        list(map(int, input().split()))
        for _ in range(n)
    ]

    # N * N * (6 * 4) * (4 * 4)
    for i in range(n):
        dice1 = Dice(values_list[i])
        for j in range(i + 1, n):
            values_2 = values_list[j]

            dices = (
                make_dices(values_2) +
                list(map(lambda dice: rot_n(dice, 1), make_dices(values_2))) +
                list(map(lambda dice: rot_n(dice, 2), make_dices(values_2))) +
                list(map(lambda dice: rot_n(dice, 3), make_dices(values_2)))
            )
            for dice in dices:
                for d in ("E" * 4 + "W" * 4 + "S" * 4 + "N" * 4):
                    dice.roll(d)
                    if eq_dice(dice1, dice):
                        print("No")
                        return

    print("Yes")


def eq_dice(d1, d2):
    return (
        d1.top_value == d2.top_value and
        d1.bottom_value == d2.bottom_value and
        d1.north_value == d2.north_value and
        d1.south_value == d2.south_value and
        d1.west_value == d2.west_value and
        d1.east_value == d2.east_value
    )


def rot_n(dice, n):
    for _ in range(n):
        dice.roll("N").roll("E").roll("S")
    return dice


def make_dices(values):
    # ?????¢???TOP?????????
    return [
        Dice(values),
        Dice(values).roll("N"),
        Dice(values).roll("N").roll("N"),
        Dice(values).roll("N").roll("N").roll("N"),
        Dice(values).roll("E"),
        Dice(values).roll("W"),
    ]


def _B(values, t_value, s_value):
    """
    ????????¢?????????????????¨??????
    ??´??¢???????????¢?????????????????§???????????????????????¨?????????
    ??????????????????????????¢???????¢??????????
    """
    dices = (
        make_dices(values) +
        list(map(lambda dice: rot_n(dice, 1), make_dices(values))) +
        list(map(lambda dice: rot_n(dice, 2), make_dices(values))) +
        list(map(lambda dice: rot_n(dice, 3), make_dices(values)))
    )
    for dice in dices:
        for d in ("E" * 4 + "W" * 4 + "S" * 4 + "N" * 4):
            dice.roll(d)
            if (dice.top_value, dice.south_value) == (t_value, s_value):
                return dice.east_value


class Dice:

    def __init__(self, values):
        self.values = values
        # top, bottom, direction 4
        self.t = 1
        self.b = 6
        self.w = 4
        self.e = 3
        self.n = 5
        self.s = 2

    def __repr__(self):
        labels = {
            "t": self.t,
            "b": self.b,
            "w": self.w,
            "e": self.e,
            "n": self.n,
            "s": self.s,
        }
        return "<%s (%s, %s)>" % (self.__class__, self.values, labels)

    def roll(self, direction):
        if direction == "E":
            after_lables = self.t, self.b, self.e, self.w
            self.e, self.w, self.b, self.t = after_lables
        elif direction == "W":
            after_lables = self.t, self.b, self.e, self.w
            self.w, self.e, self.t, self.b = after_lables
        elif direction == "S":
            after_lables = self.t, self.b, self.n, self.s
            self.s, self.n, self.t, self.b = after_lables
        elif direction == "N":
            after_lables = self.t, self.b, self.n, self.s
            self.n, self.s, self.b, self.t = after_lables

        return self

    @property
    def bottom_value(self):
        return self.values[self.b - 1]

    @property
    def north_value(self):
        return self.values[self.n - 1]

    @property
    def west_value(self):
        return self.values[self.w - 1]

    @property
    def top_value(self):
        return self.values[self.t - 1]

    @property
    def south_value(self):
        return self.values[self.s - 1]

    @property
    def east_value(self):
        return self.values[self.e - 1]

if __name__ == "__main__":
    # main_1_11_A()
    # main_1_11_B()
    # main_1_11_C()
    main_1_11_D()

Submission status: Accepted

Solution code:
dice = [
	[1, 2, 4, 3, 5],
	[5, 2, 0, 3, 4],
	[1, 5, 4, 0, 3],
	[1, 0, 4, 5, 2],
	[0, 2, 5, 3, 1],
	[1, 3, 4, 2, 0]
]

def getRound(D, top):
	result = []
	for index in dice[top]:
		result.append(D[index])
	return result

def compareRound(l1, l2):
	if l1[4] != l2[4]:
		return False
	elif l1[0] not in l2:
		return False
	offset = l2.index(l1[0])
	
	for i in range(4):
		if l1[i] != l2[(i+offset)%4]:
			return False
	return True

def compare(D1, D2, i1):
	if D1[i1] not in D2:
		return False
	i2 = D2.index(D1[i1])
	return compareRound(getRound(D1, i1), getRound(D2, i2))

def isSame(D1, D2):
	for i in range(6):
		if compare(D1, D2, i):
			return True
	return False

def isAllDifferent(DList, n):
	for i in range(n-1):
		for j in range(i+1, n):
			if isSame(DList[i], DList[j]):
				return False
	return True

n = int(input())
DList = []
for i in range(n):
	DList.append(input().split(" "))


if isAllDifferent(DList, n):
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
from itertools import*
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 d,e in list(combinations(a,2)):
 for i in range(6):
  m=('012345','152043','215304','302541','410352','514320')[i]
  f=[d[int(k)]for k in m]
  if f[0]==e[0]and f[5]==e[5]:
   f=f[1:5]*2
   for j in range(4):
    if f[j:j+4]==e[1:5]:t=1
print(('Yes','No')[t==1])

Submission status: Accepted

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

    def get_nums(self):
        return {self.t, self.s, self.e, self.w, self.n, self.b}

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

    if n == 0:
        continue

    dice_a = dice_list[-1]
    for i in range(len(dice_list) - 1):
        dice_b = dice_list[i]

        if (dice_a.get_nums() == dice_b.get_nums()):
            for i in range(1000):
                dice_b.roll(random.randint(0, 3))
                if dice_a.is_equal(dice_b):
                    flag = True
                    break

        flag_list.append(flag)

if any(flag_list):
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
mask = {
    'N': (1, 5, 2, 3, 0, 4),
    'R': (0, 2, 4, 1, 3, 5)
    }


def isIdentifyDice(dice, dice2):
    find = False

    for i in range(4):

        for j in range(4):
            if dice == dice2:
                find = True
                break
            dice = [dice[x] for x in mask['R']]

        if dice == dice2:
            find = True
            break
        dice = [dice[x] for x in mask['N']]

    dice = [dice[x] for x in mask['R']]
    dice = [dice[x] for x in mask['N']]
    for j in range(4):
        if dice == dice2:
            find = True
            break
        dice = [dice[x] for x in mask['R']]

    dice = [dice[x] for x in mask['N']]
    dice = [dice[x] for x in mask['N']]
    for j in range(4):
        if dice == dice2:
            find = True
            break
        dice = [dice[x] for x in mask['R']]

    return find


n = int(input())
dt = list(map(int, input().split()))

chk = True
for i in range(n - 1):
    dc = list(map(int, input().split()))
    chk = not isIdentifyDice(dc, dt)
    if not chk:
        break

print("Yes" if chk else "No")

Submission status: Accepted

Solution code:
class dice:
    def __init__(self, li = [0] * 6):
        self.men = [0] + li
    def move0(self, a, b, c, d):
        self.men[a], self.men[b], self.men[c], self.men[d] = self.men[b], self.men[c], self.men[d], self.men[a]
    def move(self, h):
        if h == "N":
            self.move0(1, 2, 6, 5)
        elif h == "S":
            self.move0(1, 5, 6, 2)
        elif h == "W":
            self.move0(1, 3, 6, 4)
        elif h == "E":
            self.move0(1, 4, 6, 3)
        elif h == "O":
            self.men[1], self.men[6], self.men[2], self.men[5] = self.men[6], self.men[1], self.men[5], self.men[2]
        elif h == "L":
            self.move0(2, 3, 5, 4)
        elif h == "R":
            self.move0(2, 4, 5, 3)
        elif h == "B":
            self.men[3], self.men[4], self.men[2], self.men[5] = self.men[4], self.men[3], self.men[5], self.men[2]
        else:
            print("▲err")
    def move2(self, a, b):
        if self.men[1] != a:
            for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]:
                if self.men[i] == a:
                    self.move(s)
                    break
        if self.men[2] != b:
            if b == self.men[3]:
                self.move("L")
            elif b == self.men[4]:
                self.move("R")
            else:
                self.move("B")
n = int(input())
cnt = 0
ans = set()
for _ in range(n):
    li = list(map(int, input().split()))
    SET = set()
    for i in range(6):
        saikoro3 = dice(li)
        if i:
            saikoro3.move("_SWENO"[i])
        SET.add(tuple(saikoro3.men))
        for _ in range(3):
            saikoro3.move("L")
            SET.add(tuple(saikoro3.men))
    ans |= SET
    cnt += len(SET)
print("Yes" if len(ans) == cnt else "No")

Submission status: Accepted

Solution code:
from itertools import*
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
lst=list(combinations(a,2))
for d,e in lst:
 for i in range(6):
  m=('012345','152043','215304','302541','410352','514320')[i]
  f=[d[int(k)]for k in m]
  if f[0]==e[0]and f[5]==e[5]:
   f=f[1:5]*2
   for j in range(4):
    if f[j:j+4]==e[1:5]:t=1
print(('Yes','No')[t==1])

Submission status: Accepted

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
    for k in range(4):
     if f[k:k+4]==e[1:5]:t=1
print(('Yes','No')[t])

Submission status: Accepted

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]
  if d==e:t=1;break
  for p in('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
print(('Yes','No')[t])

Submission status: Accepted

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):
 if t==1:break
 d=a[i]
 for j in range(i+1,n):
  if t==1:break
  e=a[j]
  for p in('012345','152043','215304','302541','410352','514320'):
   if t==1:break
   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;break
print(('Yes','No')[t])

Submission status: Accepted

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 1
 return 0
print(('Yes','No')[f()])

Submission status: Accepted

Solution code:
import sys
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]
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]:print('No');sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
for i in range(n-1):
 d=a[i][:];d[3],d[4]=d[4],d[3]
 for j in range(i+1,n):
  e=a[j][:];e[3],e[4]=e[4],e[3]
  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]:print('No');sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
def f():
 for i in range(n-1):
  d=a[i][:];d[3],d[4]=d[4],d[3]
  for j in range(i+1,n):
   e=a[j][:];e[3],e[4]=e[4],e[3]
   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 print('No')
 print('Yes')
f()

Submission status: Accepted

Solution code:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
def f():
 for i in range(n-1):
  d=a[i][:];d[3],d[4]=d[4],d[3]
  for j in range(i+1,n):
   e=a[j][:];e[3],e[4]=e[4],e[3]
   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: Accepted

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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
def f():
 for i in range(n-1):
  d=a[i][:];d[3],d[4]=d[4],d[3]
  for j in range(i+1,n):
   e=a[j][:];e[3],e[4]=e[4],e[3]
   for p in('012345','152043','215304','302541','410352','514320'):
    f=[d[int(k)]for k in p]
    if f[0]==e[0]:
     if 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: Accepted

Solution code:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
def f():
 for i in range(n-1):
  d=a[i][:];d[3],d[4]=d[4],d[3]
  for j in range(i+1,n):
   e=a[j][:];e[3],e[4]=e[4],e[3]
   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: Accepted

Solution code:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
def f():
 for i in range(n-1):
  d=a[i][:];d[3],d[4]=d[4],d[3]
  for j in range(i+1,n):
   e=a[j][:];e[3],e[4]=e[4],e[3]
   for p in('012345','152043','215304','302541','410352','514320'):
    f=[d[int(k)]for k in p]
    if(f[0]==e[0])*(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: Accepted

Solution code:
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
def f():
 for i in range(n-1):
  d=a[i][:];d[3],d[4]=d[4],d[3]
  for j in range(i+1,n):
   e=a[j][:];e[3],e[4]=e[4],e[3]
   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[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: Accepted

Solution code:
n=int(input())
a=[[int(s)for s in input().split()]for _ in range(n)]
def f():
 for i in range(n-1):
  d=a[i][:];d[3],d[4]=d[4],d[3]
  for j in range(i+1,n):
   e=a[j][:];e[3],e[4]=e[4],e[3]
   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[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: Accepted

Solution code:
n=int(input())
a=[[s for s in input().split()]for _ in range(n)]
def f():
 for i in range(n-1):
  d=a[i][:];d[3],d[4]=d[4],d[3]
  for j in range(i+1,n):
   e=a[j][:];e[3],e[4]=e[4],e[3]
   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[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: Accepted

Solution code:
from itertools import*
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
def f():
 for d,e in list(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[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: Accepted

Solution code:
from itertools import*
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
def f():
 for p,q in list(combinations(a,2)):
  d=p[:];d[3],d[4]=d[4],d[3]
  e=q[:];e[3],e[4]=e[4],e[3]
  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[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: Accepted

Solution code:
from itertools import*
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 d,e in list(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[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: Accepted

Solution code:
from itertools import*
n=int(input())
a=[[s for s in 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 d,e in list(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[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: Accepted

Solution code:
from itertools import*
n=int(input())
a=[[s for s in 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 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[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: Accepted

Solution code:
from itertools import*
n=int(input())
a=[[s for s in input().split()]for _ in range(n)]
for b in a:
 b[3],b[4]=b[4],b[3]
def f():
 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[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: Accepted

Solution code:
from itertools import*
n=int(input())
a=[[s for s in input().split()]for _ in range(n)]
for b in a:
 b[3],b[4]=b[4],b[3]
def f():
 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(f())

Submission status: Accepted

Solution code:
from itertools import*
n=int(input())
a=[[s for s in input().split()]for _ in range(n)]
for b in a:
 b[3],b[4]=b[4],b[3]
def f():
 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]+f[1:5]
    for k in range(4):
     if f[k:k+4]==e[1:5]:return'No'
 return'Yes'
print(f())

Submission status: Accepted

Solution code:
from itertools import*
n=int(input())
a=[[s for s in input().split()]for _ in range(n)]
for b in a:
 b[3:5]=b[4],b[3]
def f():
 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(f())

Submission status: Accepted

Solution code:
class dice:

    def __init__(self, numlist):
        self._men = {"T": numlist[0],
                     "B": numlist[5],
                     "N": numlist[4],
                     "S": numlist[1],
                     "W": numlist[3],
                     "E": numlist[2]}

    def roll(self, direction):
        t = dict(self._men)

        if direction == "N":
            self._men["T"] = t["S"]
            self._men["B"] = t["N"]
            self._men["N"] = t["T"]
            self._men["S"] = t["B"]
        elif direction == "S":
            self._men["T"] = t["N"]
            self._men["B"] = t["S"]
            self._men["S"] = t["T"]
            self._men["N"] = t["B"]
        elif direction == "W":
            self._men["T"] = t["E"]
            self._men["B"] = t["W"]
            self._men["W"] = t["T"]
            self._men["E"] = t["B"]
        elif direction == "E":
            self._men["T"] = t["W"]
            self._men["B"] = t["E"]
            self._men["W"] = t["B"]
            self._men["E"] = t["T"]


    def clock(self):
        t = dict(self._men)
        self._men["E"] = t["N"]
        self._men["N"] = t["W"]
        self._men["W"] = t["S"]
        self._men["S"] = t["E"]


    def simpleequal(self, d2):
        if self._men == d2._men:
            return True
        else:
            return False


    def equal(self, d2):
        for _ in range(4):
            d2.roll("N")

            for _ in range(4):
                d2.clock()
                if self.simpleequal(d2):
                    return True

        d2.roll("E")
        for _ in range(4):
            d2.clock()
            if self.simpleequal(d2):
                return True


        d2.roll("E")
        d2.roll("E")
        for _ in range(4):
            d2.clock()
            if self.simpleequal(d2):
                return True



    def gettop(self):
        return self._men["T"]

def decode():
    n = int(input())
    nlists = []
    for _ in range(n):
        numlist = [int(x) for x in input().split()]
        nlists.append(numlist)

    return n, nlists


def isunique(dices):
    for i in range(n-1):
        for j in range(i+1, n):
            if dices[i].equal(dices[j]):
                return False
    return True


if __name__ == '__main__':

    n, nlists = decode()
    dices = []
    for numlist in nlists:
        dices.append(dice(numlist))

    if isunique(dices):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
import random

class Dice:
    def __init__(self, hoge):
        self.num = hoge
        self.face = {'U': 0, 'W': 3, 'E': 2, 'N': 4, 'S': 1, 'B': 5} 
    
    def move(self, direct):
        previouse = {k: v for k, v in self.face.items()}
        if direct == 'E':
            self.face['U'] = previouse['W']
            self.face['W'] = previouse['B']
            self.face['E'] = previouse['U']
            self.face['B'] = previouse['E']
        elif direct == 'W':
            self.face['U'] = previouse['E']
            self.face['W'] = previouse['U']
            self.face['E'] = previouse['B']
            self.face['B'] = previouse['W']
        elif direct == 'N':
            self.face['U'] = previouse['S']
            self.face['N'] = previouse['U']
            self.face['S'] = previouse['B']
            self.face['B'] = previouse['N']
        elif direct == 'S':
            self.face['U'] = previouse['N']
            self.face['N'] = previouse['B']
            self.face['S'] = previouse['U']
            self.face['B'] = previouse['S']
    
    def get_num(self, place):
        return self.num[self.face[place]]
    
    def getFace(self):
        for k, v in sorted(self.face.items()):
            yield self.num[v]
    
        
if __name__ == '__main__':
    num_dice = int(input())
    dice = list()
    
    for _ in range(num_dice):
        dice.append(Dice([int(x) for x in input().split()]))
        
    d = ['E', 'W', 'N', 'S']
    
    for yuki in range(1, num_dice):
        haruhi = 0
        for k in range(1000):
            c = 0
            rand_num = random.randint(0, 3)
            dice[yuki].move(d[rand_num])
        
            for v1, v2 in zip(dice[0].getFace(), dice[yuki].getFace()):
                if v1 == v2:
                    c += 1
            if c == 6:
                haruhi += 1
                break
        if haruhi:
            print ('No')
            break 
    if not haruhi:
        print ('Yes')

Submission status: Accepted

Solution code:
import random
class Dice:
    def __init__(self, num_list):
        self.top = num_list[0]
        self.dside = num_list[1]
        self.rside = num_list[2]
        self.lside = num_list[3]
        self.uside = num_list[4]
        self.bottom = num_list[5]
        self.dlist = num_list
    def north(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.dside, 
            self.bottom, self.uside, self.top)
    def east(self):
        (self.top, self.lside, self.bottom, self.rside) = (self.lside,
            self.bottom, self.rside, self.top)
    def south(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.uside, 
            self.top, self.dside, self.bottom)

n = int(input())
num = [list(map(int, input().split())) for i in range(n)]
dice = [Dice(num[i]) for i in range(n)]
for idx1, i in enumerate(dice):
    for idx2, j in enumerate(dice):
        if idx2 <= idx1 or len(set(i.dlist)^set(j.dlist)):
            continue
        elif len(set(num[0])) < 4:
            while(i.top != j.top or i.rside != j.rside
                  or i.dside != j.dside):
                mode = random.randint(0, 2)
                if mode == 0:
                    j.north()
                elif mode == 1:
                    j.east()
                else:
                    j.south()
        else:
            while(i.top != j.top or 
                 (i.rside != j.rside and i.uside != j.uside)):
                mode = random.randint(0, 2)
                if mode == 0:
                    j.north()
                elif mode == 1:
                    j.east()
                elif mode == 2:
                    j.south()
        if (i.bottom == j.bottom and i.lside == j.lside 
            and i.dside == j.dside):
            print("No")
            break
    else:
        continue
    break
else:
    print("Yes")