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:
import itertools
class dice():
    def __init__(self,number):
        self.number = number
 
    def korokoro(self,com):
        if com == 'E':
            self.number = [self.number[i] for i in [3,1,0,5,4,2]]
        if com == 'S':
            self.number = [self.number[i] for i in [4,0,2,3,5,1]]
        if com == 'N':
            self.number = [self.number[i] for i in [1,5,2,3,0,4]]
        if com == 'W':
            self.number = [self.number[i] for i in [2,1,5,0,4,3]]
def checker(d1,d2):
    for com in 'EEEENEEEENEEEENEEEENWSEEEENNEEEE':
        d1.korokoro(com)
        if d1.number == d2.number:
            ans = 'Yes'
            break
        else:
            ans = 'No'
    return ans
n = int(input())
saikoro = {}
for _ in range(n):
    saikoro[_] = dice([int(x) for x in input().split()])
l = list(itertools.combinations(saikoro.keys(),2))
for __ in l:
    test1 = saikoro[__[0]]
    test2 = saikoro[__[1]]
    if checker(test1,test2) == 'Yes':
        answer = 'No'
        break
    else:
        answer = 'Yes'
print(answer)

Submission status: Accepted

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

import sys

side = ((2-1, 3-1, 5-1, 4-1), (6-1, 3-1, 1-1, 4-1), (1-1, 2-1, 6-1, 5-1),
        (1-1, 5-1, 6-1, 2-1), (1-1, 3-1, 6-1, 4-1), (5-1, 3-1, 2-1, 4-1))

def check_rotate(face1, face2, f2_index):
    f1_bot = face1[5]
    if face2[5-f2_index] != f1_bot:
        return False
    f2_side_index = side[f2_index] * 2
    f2_side = [face2[f2_side_index[i]] for i in range(len(f2_side_index))]
    f1_side = [face1[i] for i in (2-1, 3-1, 5-1, 4-1)]
    # print(f1_side, f2_side)

    for i in range(4):
        if f1_side == f2_side[i:i+4]:
            return True

    return False

def check_ident(face1, face2):
    # print('Comparing:', face1, face2, file=sys.stderr)
    f1_top = face1[0]
    for index in range(len(face2)):
        if face2[index] == f1_top:
            if check_rotate(face1, face2, index):
                return True

    return False


def check_faces(faces, n):
    for x in range(n-1):
        for y in range(x+1, n):
            if check_ident(faces[x], faces[y]):
                print('No')
                return
    print('Yes')
    return

n = int(sys.stdin.readline())
faces = list()
for i in range(n):
    faces.append(sys.stdin.readline().split())

check_faces(faces, n)

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.buff = [n for n in dice]
        self.t = dice[0]
        self.s = dice[1]
        self.e = dice[2]
        self.w = dice[3]
        self.n = dice[4]
        self.b = dice[5]
    def east(self):
        self.dice[0] = self.buff[3]
        self.dice[2] = self.buff[0]
        self.dice[5] = self.buff[2]
        self.dice[3] = self.buff[5]
        self.buff = [n for n in self.dice]
    def west(self):
        self.dice[0] = self.buff[2]
        self.dice[2] = self.buff[5]
        self.dice[5] = self.buff[3]
        self.dice[3] = self.buff[0]
        self.buff = [n for n in self.dice]
    def north(self):
        self.dice[0] = self.buff[1]
        self.dice[1] = self.buff[5]
        self.dice[5] = self.buff[4]
        self.dice[4] = self.buff[0]
        self.buff = [n for n in self.dice]
    def south(self):
        self.dice[0] = self.buff[4]
        self.dice[1] = self.buff[0]
        self.dice[5] = self.buff[1]
        self.dice[4] = self.buff[5]
        self.buff = [n for n in self.dice]
    def spin(self):
        self.dice[1] = self.buff[3]
        self.dice[2] = self.buff[1]
        self.dice[4] = self.buff[2]
        self.dice[3] = self.buff[4]
        self.buff = [n for n in self.dice]
    def to_be_the_same_direction(self, anotherDice):
        if self.t == anotherDice.t:
            pass
        elif self.t == anotherDice.e:
            anotherDice.west()
        elif self.t == anotherDice.w:
            anotherDice.east()
        elif self.t == anotherDice.n:
            anotherDice.south()
        elif self.t == anotherDice.s:
            anotherDice.north()
        else:
            anotherDice.north()
            anotherDice.north()
    def isSameDice(self, anotherDice):
        if  self.dice[0] == anotherDice.dice[0] and \
            self.dice[1] == anotherDice.dice[1] and \
            self.dice[2] == anotherDice.dice[2] and \
            self.dice[3] == anotherDice.dice[3] and \
            self.dice[4] == anotherDice.dice[4] and \
            self.dice[5] == anotherDice.dice[5]:
                return True
        return False
    def compare(self, anotherDice):
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()

        self.north()
        self.west()
        self.west()
        self.to_be_the_same_direction(anotherDice)
        for k in range(4):
            if self.isSameDice(anotherDice):
                return True
            else:
                self.spin()
        return False

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

flag = True
for i in range(n):
    for j in range(i+1, n):
        if dices[i].compare(dices[j]):
            flag = False

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

Submission status: Accepted

Solution code:
class Dice:
    """サイコロを操作するクラス"""
    def __init__(self, num):
        self.num = num
    def roll_north(self):
        tmp = self.num[:]
        self.num[0] = tmp[1]
        self.num[1] = tmp[5]
        self.num[4] = tmp[0]
        self.num[5] = tmp[4]
    def roll_east(self):
        tmp = self.num[:]
        self.num[0] = tmp[3]
        self.num[2] = tmp[0]
        self.num[3] = tmp[5]
        self.num[5] = tmp[2]
    def roll_right(self):
        tmp = self.num[:]
        self.num[1] = tmp[3]
        self.num[2] = tmp[1]
        self.num[3] = tmp[4]
        self.num[4] = tmp[2]
    def is_same(self, dice):
        flg = False
        for i in range(20):
            if flg == True:
                break
            self.roll_north()
            for k in range(20):
                if flg == True:
                    break
                self.roll_east()
                for l in range(20):
                    self.roll_right()
                    if dice == self.num:
                        flg = True
                        break
        return flg
    def print_dice(self):
        print(self.num)

dices = []
diff = True # 全部のdiceが異なるかどうか
for i in range(int(input())):
    dices.append(Dice(list(map(int, input().split()))))
for i in dices[1:]:
    diff = diff and not(dices[0].is_same(i.num))
if diff:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:

class Dice:
    def __init__(self, v1, v2, v3, v4, v5, v6):
        self.faces = [(v1, v6), (v2, v5), (v3, v4)]

    def rotate_left(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(top, rgt, bck, fnt, lft, btm)

    def rotate_right(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(top, lft, fnt, bck, rgt, btm)

    def turn_back(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(fnt, btm, rgt, lft, top, bck)

    def turn_front(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(bck, top, rgt, lft, btm, fnt)

    def turn_right(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(lft, fnt, top, btm, bck, rgt)

    def turn_left(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(rgt, fnt, btm, top, bck, lft)

    def __hash__(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return hash(frozenset((frozenset((top, btm)),
                               frozenset((fnt, bck)),
                               frozenset((rgt, lft)))))

    def __str__(self):
        return "<{}>".format(",".join([str(t) for t in self.faces]))

    def __eq__(self, other):
        def equals(d1, d2):
            return d1.faces == d2.faces

        (top, btm) = self.faces[0]
        if (top, btm) in other.faces:
            return (equals(self, other)
                    or equals(self.rotate_right(), other)
                    or equals(self.rotate_left(), other)
                    or equals(self.turn_right(), other)
                    or equals(self.turn_front(), other)
                    or equals(self.rotate_left().rotate_left(), other)
                    or equals(self.turn_back().rotate_left(), other)
                    or equals(self.turn_front().rotate_right(), other)
                    or equals(self.turn_right().rotate_left(), other)
                    or equals(self.turn_left().rotate_right(), other)
                    or equals(self.turn_right().turn_back().turn_back(),
                              other)
                    or equals(self.turn_front().turn_right().turn_right(),
                              other))
        elif (btm, top) in other.faces:
            return self.turn_front().turn_front() == other
        else:
            return False


def run():
    count = int(input())
    dices = set()

    for _ in range(count):
        dice = Dice(*[int(i) for i in input().split()])
        if dice in dices:
            print("No")
            break
        dices.add(dice)
    else:
        print("Yes")


if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
p = [(-1, 2, 4, 1, 3, -1), (3, -1, 0, 5, -1, 2), (1, 5, -1, -1, 0, 4),
(4, 0, -1, -1, 5, 1), (2, -1, 5, 0, -1, 3), (-1, 3, 1, 4, 2, -1)]

def is_equal(d, a):
  ts = [i for i, x in enumerate(d) if x == a[0]]
  fs = [i for i, x in enumerate(d) if x == a[1]]
  b = 0
  for t in ts:
    for f in fs:
      if t == f: continue
      r = p[t][f]
      if r == -1: continue
      l = [d[t], d[f], d[r], d[5-r], d[5-f], d[5-t]]
      if a == l: b += 1; break
  return 1 if b > 0 else 0

l = []
b = 0
for _ in range(int(input())):
  l += [input().split()]
for i in range(0, len(l)):
  for j in range(i+1, len(l)):
    b += is_equal(l[i], l[j])
    if b > 0: break
print("No") if b > 0 else print("Yes")

Submission status: Accepted

Solution code:
class Dice4():
    def check(self,dice,n):
        count=0
        for i in range(n):
            for j in range(n):
                if i != j:
                    for k in range(4):#縦回転
                        dice[i][0],dice[i][1],dice[i][5],dice[i][4]=dice[i][4],dice[i][0],dice[i][1],dice[i][5]
                        for l in range(4):#横回転
                            dice[i][0],dice[i][2],dice[i][5],dice[i][3]=dice[i][3],dice[i][0],dice[i][2],dice[i][5]
                            for m in range(4):#ひねり
                                dice[i][1],dice[i][2],dice[i][4],dice[i][3]=dice[i][2],dice[i][4],dice[i][3],dice[i][1]
                                if dice[i] == dice[j]:
                                    count+=1
        return count

#Dice3
Dice=[]
n = int(input())
for i in range(n):
    Dice.append([int(i) for i in input().split()])
dc4 = Dice4()
counter = dc4.check(Dice,n)
if counter == 0:
    print('Yes')
else :
    print('No')

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
      
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d
        self.dic={"W":0,"S":1,"E":2,"N":3}
  
    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[way]
  
        if(way==0):
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way==1:
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way==2:
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c
    def get_nums(self):   
        return {self.u,self.w,self.s,self.e,self.n,self.w,self.d}
 
def mk_dice():
    u,s,e,w,n,d=map(int,input().split())
    return Dice(u,w,s,e,n,d)
  
import random
q=int(input())
dice_col=[]
ans=True
for j in range(q):
    dice_b=mk_dice()
    for dice in dice_col:
        if(dice.get_nums()==dice_b.get_nums()):
            for i in range (1000):
                dice.rot(random.randint(0,2))
                if(dice.u==dice_b.u and dice.d==dice_b.d and dice.w==dice_b.w and dice.s==dice_b.s and dice.e==dice_b.e and dice.n==dice_b.n):
                    ans=False
        if ~ans:
            break
    dice_col.append(dice_b)
  
if ans:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
class Dice:
    TOP, SOUTH, EAST, WEST, NORTH, BOTTOM = 0, 1, 2, 3, 4, 5
    def __init__(self, d):
        self.dice = d[:]
        self.top = d[0]
        self.south = d[1]
        self.east = d[2]
        self.west = d[3]
        self.north = d[4]
        self.bottom = d[5]

    def __eq__(self, other):
        a = self.permutations()
        a.sort()

        d2 = Dice(other.dice)
        b = d2.permutations()
        b.sort()

        return a == b

    def permutations(self):
        copy = self.dice[:]
        perm = []
        for d in [(), ("S"), ("N"), ("E"), ("W"), ("W", "W")]:
            t = Dice(copy)
            for m in d:
                t.move(m)

            perm.append(t.dice[:])
            for i in range(3):
                t.move("R")
                perm.append(t.dice[:])

        return perm
        
    def set_top_front(self, top, front):
        for i, n in enumerate(self.dice):
            if n == top:
                if i == Dice.TOP: pass
                elif i == Dice.SOUTH: self.move("N")
                elif i == Dice.EAST: self.move("W")
                elif i == Dice.WEST: self.move("E")
                elif i == Dice.NORTH: self.move("S")
                elif i == Dice.BOTTOM:
                    self.move("S")
                    self.move("S")

                break
        else:
            return False
        
        for i, n in enumerate(self.dice):
            if n == front:
                if i == Dice.TOP: return False
                elif i == Dice.SOUTH: pass
                elif i == Dice.EAST: self.move("R")
                elif i == Dice.WEST: self.move("L")
                elif i == Dice.NORTH:
                    self.move("R")
                    self.move("R")
                elif i == Dice.BOTTOM: return False

                break
        else:
            return False

        return True
        
    def move(self, d):
        if d == "N":
            self.move_north()
        elif d == "W":
            self.move_west()
        elif d == "S":
            self.move_south()
        elif d == "E":
            self.move_east()
        elif d == "R":
            self.move_right()
        elif d == "L":
            self.move_left()

        self.dice = [
            self.top,
            self.south,
            self.east,
            self.west,
            self.north,
            self.bottom,
        ]

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

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

    def move_north(self):
        self.top, self.south, self.bottom, self.north \
            = self.south, self.bottom, self.north, self.top

    def move_south(self):
        self.top, self.south, self.bottom, self.north \
            = self.north, self.top, self.south, self.bottom

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

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

if __name__ == "__main__":

    def ne_all():
        import re
        n = int(input().strip())
        dices = []
        for i in range(n):
            nums = [int(n) for n in re.split(r"\s+", input().strip())]
            current = Dice(nums)
            for d in dices:
                if current == d:
                    return False
            dices.append(current)
        else:
            return True

    if ne_all():
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
def north(list):
    List = []
    List.append(list[1])
    List.append(list[5])
    List.append(list[2])
    List.append(list[3])
    List.append(list[0])
    List.append(list[4])
    return List

def west(list):
    List = []
    List.append(list[2])
    List.append(list[1])
    List.append(list[5])
    List.append(list[0])
    List.append(list[4])
    List.append(list[3])
    return List
    
def south(list):
    List = []
    List.append(list[4])
    List.append(list[0])
    List.append(list[2])
    List.append(list[3])
    List.append(list[5])
    List.append(list[1])
    return List

def east(list):
    List = []
    List.append(list[3])
    List.append(list[1])
    List.append(list[0])
    List.append(list[5])
    List.append(list[4])
    List.append(list[2])
    return List

def sort123(DD):
    D = [DD]
    for i in range(0, 3):
        D.append(north(D[i]))
        D.append(south(west(D[0])))
        D.append(south(east(D[0])))
    for i in range(6):
        for j in range(3):
            if j == 0:
                D.append(east(D[i + j]))
            else:
                D.append(east(D[5 + 3 * i + j]))
    D.sort()
    return D[0]

n = int(input())
dice = []
for i in range(n):
    dice.append(sort123(list(map(int, input().split()))))
key = 0
for i in range(0, len(dice)):
    if key == 1: break
    for j in range(i + 1, len(dice)):
        if dice[i] == dice[j]:
            print('No')
            key = 1
            break
if key == 0:
    print('Yes')

Submission status: Accepted

Solution code:
#! python3
# dice_iv.py

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

    def rotate(self, ope):
        if ope == 'S':
            self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
        elif ope == 'N':
            self.top, self.south, self.bottom, self.north = self.south, self.bottom, self.north, self.top
        elif ope == 'E':
            self.top, self.west, self.bottom, self.east = self.west, self.bottom, self.east, self.top
        elif ope == 'W':
            self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top
        elif ope == 'R': # clockwise
            self.south, self.east, self.north, self.west = self.east, self.north, self.west, self.south
        elif ope == 'L': # reversed clockwise
            self.south, self.east, self.north, self.west = self.west, self.north, self.east, self.south
        else:
            pass

    def get_surfaces(self):
        return [self.top, self.south, self.east, self.north, self.west, self.bottom]

def is_same_dice(dc1, dc2):
    judged = False
    if len((dc1.get_surfaces() and dc2.get_surfaces())) == 6:
        opes = ['', 'S', 'E', 'S', 'E', 'S']
        for op in opes:
            dc2.rotate(op)
            for i in range(4):
                if dc1.get_surfaces() == dc2.get_surfaces():
                    judged = True
                    break
                dc2.rotate('R')
            if judged: break
    return judged

n = int(input())
dices = [dice([int(x) for x in input().split(' ')]) for i in range(n)]

judged = True
for i in range(n-1):
    for j in range(i+1, n):
        if is_same_dice(dices[i], dices[j]):
            judged = False

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

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]
t=0
for d,e in combinations(a,2):
 for p in('012345','152043','215304','302541','410352','514320'):
  f=[d[int(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]:t=1
print(['Yes','No'][t])

Submission status: Accepted

Solution code:
from itertools import*
def g():
 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]
 t=0
 for d,e in combinations(a,2):
  for p in('012345','152043','215304','302541','410352','514320'):
   f=[d[int(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]:t=1
 print(['Yes','No'][t])
g()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def f():
 for c in range(n):
  for d in a[c+1:]:
   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[::5]==a[c][::5]:
     f=f[1:5]*2
     for k in range(4):
      if f[k:k+4]==a[c][1:5]:return"No"
 return"Yes"
b=0
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:b[3:5]=b[4],b[3]
print(f())

Submission status: Accepted

Solution code:
def f():
 for c in range(n):
  for d in a[c+1:]:
   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[::5]==a[c][::5]:
     f=f[1:5]*2
     for k in range(4):
      if f[k:k+4]==a[c][1:5]:return"No"
 return"Yes"
import sys
b=0
n=int(input())
a=[e.split()for e in sys.stdin]
for b in a:b[3:5]=b[4],b[3]
print(f())

Submission status: Accepted

Solution code:
def f():
 for c in range(n):
  for d in a[c+1:]:
   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]):
    if[d[p[0]],d[p[5]]]==a[c][::5]:
     f=[d[i]for i in p[1:5]]*2
     for k in range(4):
      if f[k:k+4]==a[c][1:5]:return"No"
 return"Yes"
b=0
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:b[3:5]=b[4],b[3]
print(f())

Submission status: Accepted

Solution code:
def f():
 for c in range(n):
  for d in a[c+1:]:
   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]):
    if[d[p[0]],d[p[5]]]==a[c][::5]:
     f=[d[i]for i in p[1:5]]*2
     for k in range(4):
      if f[k:k+4]==a[c][1:5]:return"No"
 return"Yes"
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:b[3:5]=b[4],b[3]
print(f())

Submission status: Accepted

Solution code:
def f():
 for c in range(n):
  for d in a[c+1:]:
   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]):
    if[d[p[0]],d[p[5]]]==a[c][::5]:
     b=[d[i]for i in p[1:5]]*2
     for k in range(4):
      if b[k:k+4]==a[c][1:5]:return"No"
 return"Yes"
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:b[3:5]=b[4],b[3]
print(f())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


class Dice:
    def __init__(self, n):
        self.upper    = n[0]
        self.backward = n[1]
        self.right    = n[2]
        self.left     = n[3]
        self.ahead    = n[4]
        self.bottom   = n[5]

    def __eq__(self, other):
        return self.upper == other.upper and self.backward == other.backward and self.right == other.right \
               and self.left == other.left and self.ahead == other.ahead and self.bottom == other.bottom

    def roll_north(self):
        self.upper, self.ahead, self.bottom, self.backward = self.backward, self.upper, self.ahead, self.bottom

    def roll_south(self):
        self.upper, self.ahead, self.bottom, self.backward = self.ahead, self.bottom, self.backward, self.upper

    def roll_east(self):
        self.upper, self.right, self.bottom, self.left = self.left, self.upper, self.right, self.bottom

    def roll_west(self):
        self.upper, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.upper

    def roll_side(self):
        self.ahead, self.right, self.backward, self.left = self.left, self.ahead, self.right, self.backward


def match_dice(dice1, dice2):
    for i in range(4):
        dice1.roll_north()

        for j in range(4):
            dice1.roll_east()

            for k in range(4):
                dice1.roll_side()

                if dice2 == dice1:
                    return 0
    return 1


n = int(input())
dice_list = []
result = []

for i in range(n):
    dice_list.append(Dice(list(map(int, input().split()))))

for i in range(n):
    for j in range(n):
        if i != j:
            result.append(match_dice(dice_list[i], dice_list[j]))

if 0 in result:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys

class Dice:
    def __init__(self, labels):
        self.labels = labels
    def east(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[3], self.labels[0], self.labels[2], self.labels[5]
    def west(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[2], self.labels[5], self.labels[3], self.labels[0]
    def north(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[1], self.labels[5], self.labels[4], self.labels[0]
    def south(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[4], self.labels[0], self.labels[1], self.labels[5]

dice_num = int(input())
dices = []

for _ in range(dice_num):
    dices.append( Dice(list(map(int, input().split()))) )

south_cnt = 0

for d_i1 in range(len(dices)):
    for d_i2 in range(len(dices)):
        if d_i1 == d_i2:
            continue
        dice1 = dices[d_i1]
        dice2 = dices[d_i2]
        for i in range(8):
            for j in range(4):    
                if dice1.labels[0] == dice2.labels[0] and dice1.labels[1] == dice2.labels[1] and dice1.labels[2] == dice2.labels[2] and dice1.labels[3] == dice2.labels[3] and dice1.labels[4] == dice2.labels[4] and dice1.labels[5] == dice2.labels[5]:
                    print("No")
                    sys.exit()

                dice2.south()
                dice2.east()
                dice2.north()

            if south_cnt == 4:
                dice2.east()
            else:
                dice2.south()
                south_cnt += 1
    
print("Yes")

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.b = b
        self.u = 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]]
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)