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: Time Limit Exceeded

Solution code:
from copy import deepcopy
from itertools import groupby
import queue
import sys

class Dice:
    def __init__(self, nums):
        self.labels = [None] + [ nums[i] for i in range(6) ]
        self.pos = {
            "E" : 3,
            "W" : 4,
            "S" : 2,
            "N" : 5,
            "T" : 1,
            "B" : 6
        }

    def rolled(dice, queries):
        d = deepcopy(dice)
        for q in queries:
            if q == "E":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["W"], d.pos["T"], d.pos["E"], d.pos["B"]
            elif q == "W":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["E"], d.pos["B"], d.pos["W"], d.pos["T"]
            elif q == "S":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["N"], d.pos["T"], d.pos["S"], d.pos["B"]
            elif q == "N":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["S"], d.pos["B"], d.pos["N"], d.pos["T"]
        else:
            return d

    def isDiceSame(d1, d2):
        if not isinstance(d1, Dice) or not isinstance(d2, Dice):
            return False

        if set(d1.labels[1:]) != set(d2.labels[1:]):
            return False

        else:
            q = ["T", "S", "E", "N", "W", "B"]
            memo = [[False] * 7 for i in range(7)]
            memo[d1.pos["T"]][d1.pos["S"]] = ""
            res = {}
            for i in q[:3]:
                if d1.labels[d1.pos[i]] != d2.labels[d2.pos[i]]:
                    break
            else:
                res[memo[d1.pos["T"]][d1.pos["S"]]] = d1

            def bfs_isDiceSame():
                que = queue.Queue()
                que.put(d1)

                while not que.empty():
                    d = que.get()
                    for i in q[1:5]:
                        d_next = Dice.rolled(d, i)
                        if memo[d_next.pos["T"]][d_next.pos["S"]] == False:
                            que.put(d_next)
                            memo[d_next.pos["T"]][d_next.pos["S"]] = memo[d.pos["T"]][d.pos["S"]] + i
                            for j in q[:3]:
                                if d_next.labels[d_next.pos[j]] != d2.labels[d2.pos[j]]:
                                    break
                            else:
                                res[memo[d_next.pos["T"]][d_next.pos["S"]]] = d_next

            bfs_isDiceSame()
            if len(res) == 0:
                return False
            else:
                for k, v in res.items():
                    for i in q[3:]:
                        if v.labels[v.pos[i]] != d2.labels[d2.pos[i]]:
                            break
                    else:
                        return True
                else:
                    return False

n = int(sys.stdin.readline().rstrip())
d_nums = [tuple([int(x) for x in sys.stdin.readline().rstrip().split()]) for _ in range(n)]

if len(d_nums) != len(set(d_nums)):
    print("No")
else:
    d_nums.sort(key=lambda t: sum(t))
    for (_, g) in groupby(d_nums, key=lambda t: sum(t)):
        gl = list(g)
        if len(gl) == 1:
            continue
        else:
            for i in range(len(gl)):
                for j in range(i+1, len(gl)):
                    if Dice.isDiceSame(Dice(gl[i]), Dice(gl[j])):
                        print("No")
                        sys.exit()
    else:
        print("Yes")

Submission status: Time Limit Exceeded

Solution code:
#
# itp1 11d
#
import random


class Cube:
    def __init__(self, u, s, e, w, n, d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d

    def rotate(self, dic):
        if dic == "N":
            tmp = self.u
            self.u = self.s
            self.s = self.d
            self.d = self.n
            self.n = tmp
        elif dic == "E":
            tmp = self.u
            self.u = self.w
            self.w = self.d
            self.d = self.e
            self.e = tmp
        elif dic == "W":
            tmp = self.u
            self.u = self.e
            self.e = self.d
            self.d = self.w
            self.w = tmp
        else:
            tmp = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = tmp


def main():
    N = int(input())
    cubeL = []
    for i in range(N):
        u, s, e, w, n, d = map(int, input().split())
        cube = Cube(u, s, e, w, n, d)
        cubeL.append(cube)

    ret = "Yes"
    for i in range(N):
        for j in range(i+1, N):
            flag = True
            for k in range(10000):
                cubeL[j].rotate(random.choice("NEWS"))
                if cubeL[i].u == cubeL[j].u and cubeL[i].n == cubeL[j].n and cubeL[i].w == cubeL[j].w and cubeL[i].e == cubeL[j].e and cubeL[i].s == cubeL[j].s and cubeL[i].d == cubeL[j].d:
                    flag = False
                    break
            if not flag:
                break
        if not flag:
            ret = "No"
            break
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#
# itp1 11d
#
import random


class Cube:
    def __init__(self, u, s, e, w, n, d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d

    def rotate(self, dic):
        if dic == "N":
            tmp = self.u
            self.u = self.s
            self.s = self.d
            self.d = self.n
            self.n = tmp
        elif dic == "E":
            tmp = self.u
            self.u = self.w
            self.w = self.d
            self.d = self.e
            self.e = tmp
        elif dic == "W":
            tmp = self.u
            self.u = self.e
            self.e = self.d
            self.d = self.w
            self.w = tmp
        else:
            tmp = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = tmp


def main():
    N = int(input())
    cubeL = []
    for i in range(N):
        u, s, e, w, n, d = map(int, input().split())
        cube = Cube(u, s, e, w, n, d)
        cubeL.append(cube)

    ret = "Yes"
    for i in range(N):
        for j in range(i+1, N):
            flag = True
            for k in range(1000):
                cubeL[j].rotate(random.choice("NEWS"))
                if cubeL[i].u == cubeL[j].u and cubeL[i].n == cubeL[j].n and cubeL[i].w == cubeL[j].w and cubeL[i].e == cubeL[j].e and cubeL[i].s == cubeL[j].s and cubeL[i].d == cubeL[j].d:
                    flag = False
                    break
            if not flag:
                break
        if not flag:
            ret = "No"
            break
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 22 11:38:11 2015

@author: hirose
"""

# -*- coding: utf-8 -*-

from random import *
import copy

def command(hougaku, label):
    temp = {}
    temp = copy.deepcopy(label)
    if(hougaku == 'E'):
        label[1] = temp[4]
        label[3] = temp[1]
        label[4] = temp[6]
        label[6] = temp[3]
    elif(hougaku == 'W'):
        label[1] = temp[3]
        label[3] = temp[6]
        label[4] = temp[1]
        label[6] = temp[4]
    elif(hougaku == 'N'):
        label[1] = temp[2]
        label[2] = temp[6]
        label[5] = temp[1]
        label[6] = temp[5]
    elif(hougaku == 'S'):
        label[1] = temp[5]
        label[2] = temp[1]
        label[5] = temp[6]
        label[6] = temp[2]

if __name__=="__main__":
    n = input()
    label = {}
    for i in range(n):
        label[i] = {}
        temp = map(int, raw_input().split())
        for j in range(6):
            label[i][j+1] = temp[j]
        #print label[i]
    flag = 0
    for i in range(n-1):
        #print label[i]
        for j in range(i+1,n):
            count = 0
            #print label[j]
            while True:
                if(label[i] == label[j]):
                    flag = 1
                    break
                x = random()
                if(x < 0.25):
                    command('E', label[j])
                elif(x < 0.50):
                    command('W', label[j])
                elif(x < 0.75):
                    command('N', label[j])
                else:
                    command('S', label[j])
                count += 1
                if(count > 1000):
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if(flag == 0):
        print 'Yes'
    else:
        print 'No'

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 22 11:38:11 2015

@author: hirose
"""

# -*- coding: utf-8 -*-

from random import *
import copy

def command(hougaku, label):
    temp = {}
    temp = copy.deepcopy(label)
    if(hougaku == 'E'):
        label[1] = temp[4]
        label[3] = temp[1]
        label[4] = temp[6]
        label[6] = temp[3]
    elif(hougaku == 'W'):
        label[1] = temp[3]
        label[3] = temp[6]
        label[4] = temp[1]
        label[6] = temp[4]
    elif(hougaku == 'N'):
        label[1] = temp[2]
        label[2] = temp[6]
        label[5] = temp[1]
        label[6] = temp[5]
    elif(hougaku == 'S'):
        label[1] = temp[5]
        label[2] = temp[1]
        label[5] = temp[6]
        label[6] = temp[2]

if __name__=="__main__":
    n = input()
    label = {}
    for i in range(n):
        label[i] = {}
        temp = map(int, raw_input().split())
        for j in range(6):
            label[i][j+1] = temp[j]
        #print label[i]
    flag = 0
    for i in range(n-1):
        #print label[i]
        for j in range(i+1,n):
            count = 0
            #print label[j]
            while True:
                if(label[i] == label[j]):
                    flag = 1
                    break
                x = random()
                if(x < 0.25):
                    command('E', label[j])
                elif(x < 0.50):
                    command('W', label[j])
                elif(x < 0.75):
                    command('N', label[j])
                else:
                    command('S', label[j])
                count += 1
                if(count > 100):
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if(flag == 0):
        print 'Yes'
    else:
        print 'No'

Submission status: Time Limit Exceeded

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 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:
        for i in range (1000):
            dice.rot(random.randint(0,3))
            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
    dice_col.append(dice_b)

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

Submission status: Time Limit Exceeded

Solution code:
class Dice:
    def __init__(self, men):
        self.men = men

    def throw(self, direction):
        if direction == "E":
            pmen = men[:]
            men[0] = pmen[3]
            men[1] = pmen[1]
            men[2] = pmen[0]
            men[3] = pmen[5]
            men[4] = pmen[4]
            men[5] = pmen[2]
        elif direction == "W":
            pmen = men[:]
            men[0] = pmen[2]
            men[1] = pmen[1]
            men[2] = pmen[5]
            men[3] = pmen[0]
            men[4] = pmen[4]
            men[5] = pmen[3]
        elif direction == "S":
            pmen = men[:]
            men[0] = pmen[4]
            men[1] = pmen[0]
            men[2] = pmen[2]
            men[3] = pmen[3]
            men[4] = pmen[5]
            men[5] = pmen[1]
        elif direction == "N":
            pmen = men[:]
            men[0] = pmen[1]
            men[1] = pmen[5]
            men[2] = pmen[2]
            men[3] = pmen[3]
            men[4] = pmen[0]
            men[5] = pmen[4]
        elif direction == "C":
            pmen = men[:]
            men[0] = pmen[0]
            men[1] = pmen[2]
            men[2] = pmen[4]
            men[3] = pmen[1]
            men[4] = pmen[3]
            men[5] = pmen[5]
        elif direction == "U":
            pmen = men[:]
            men[0] = pmen[0]
            men[1] = pmen[3]
            men[2] = pmen[1]
            men[3] = pmen[4]
            men[4] = pmen[2]
            men[5] = pmen[5]

    def makeUe(self, ue):
        if(self.men[2] == ue or self.men[3] == ue):
            self.throw("E")

        while (self.men[0] != ue):
            self.throw("S")

n = int(raw_input())
anti2 = []
antiNot2 = []
for i in range(n):
    men = map(int, (raw_input()).split(" "))
    d = Dice(men)
    d.makeUe(1)
    if d.men[5] == 2:
        while (d.men[1] != 3):
            d.throw("C")
        S = d.men[2:5]
        anti2.append(S)
    else:
        while (d.men[1] != 2):
            d.throw("C")
        S = d.men[2:6]
        antiNot2.append(S)

flag = False
for i in range(len(anti2)-1):
    if anti2[i] == anti2[i+1]:
        flag = True

for i in range(len(antiNot2)-1):
    if antiNot2[i] == antiNot2[i+1]:
        flag = True

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
n = int(input())
inp = [[i for i in input().split()] for i in range(n)]
a = copy.deepcopy(inp)
number = 3
count = 0
fuck = 0
for i in range(n-3):
    number += 3+i
for i in range(number):
    for i3 in range(n-1):
        if i3 == 0:
            kais = n-1
            sika = kais
            continue
        kais += n-i3
        if i >= sika and i < kais:
            sika = kais
            count = i3
    for i2 in range(1,33):
        if (i2<=20 and i2%5==0) or i2==22 or i2==27 or i2==28:
            s = "N"
        else:
            s = "E"
        if s == "E":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                b.append(a[i4][3])
                b.append(a[i4][1])
                b.append(a[i4][0])
                b.append(a[i4][5])
                b.append(a[i4][4])
                b.append(a[i4][2])
                for ks in range(6):
                    a[i4][ks] = b[ks]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    fuck = 0
                    for x2 in range(6):
                        if inp[count][x2] == a[x][x2]:
                            fuck += 1
                    if  fuck == 6:
                        print("No")
                        sys.exit()
        elif s == "N":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                b.append(a[i4][1])
                b.append(a[i4][5])
                b.append(a[i4][2])
                b.append(a[i4][3])
                b.append(a[i4][0])
                b.append(a[i4][4])
                for ks in range(6):
                    a[i4][ks] = b[ks]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    fuck = 0
                    for x2 in range(6):
                        if inp[count][x2] == a[x][x2]:
                            fuck += 1
                    if  fuck == 6:
                        print("No")
                        sys.exit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
n = int(input())
inp = [[i for i in input().split()] for i in range(n)]
a = copy.copy(inp)
number = 3
count = 0
for i in range(n-3):
    number += 3+i
for i in range(number):
    for i3 in range(n-1):
        if i3 == 0:
            kais = n-1
            sika = kais
            continue
        kais += n-i3
        if i >= sika and i < kais:
            sika = kais
            count = i3
    for i2 in range(1,33):
        if (i2<=20 and i2%5==0) or i2==22 or i2==27 or i2==28:
            s = "N"
        else:
            s = "E"
        if s == "E":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                b.append(a[i4][3])
                b.append(a[i4][1])
                b.append(a[i4][0])
                b.append(a[i4][5])
                b.append(a[i4][4])
                b.append(a[i4][2])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
        elif s == "N":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                b.append(a[i4][1])
                b.append(a[i4][5])
                b.append(a[i4][2])
                b.append(a[i4][3])
                b.append(a[i4][0])
                b.append(a[i4][4])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
n = int(input())
inp = [[i for i in input().split()] for i in range(n)]
a = copy.copy(inp)
number = 3
count = 0
kais = n-1
for i in range(n-3):
    number += 3+i
for i in range(number):
    if i == kais-1:
        for i3 in range(n-1):
            if i3 == 0:
                sika = kais
                continue
            kais += n-i3
            if i >= sika and i < kais:
                sika = kais
                count = i3
    for i2 in range(1,33):
        if (i2<=20 and i2%5==0) or i2==22 or i2==27 or i2==28:
            s = "N"
        else:
            s = "E"
        if s == "E":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                b.append(a[i4][3])
                b.append(a[i4][1])
                b.append(a[i4][0])
                b.append(a[i4][5])
                b.append(a[i4][4])
                b.append(a[i4][2])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
        elif s == "N":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                b.append(a[i4][1])
                b.append(a[i4][5])
                b.append(a[i4][2])
                b.append(a[i4][3])
                b.append(a[i4][0])
                b.append(a[i4][4])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
inp = [[i for i in input().split()] for i in range(n)]
a = inp
number = 3
count = 0
kais = n-1
for i in range(n-3):
    number += 3+i
for i in range(number):
    if i == kais-1:
        for i3 in range(n-1):
            if i3 == 0:
                sika = kais
                continue
            kais += n-i3
            if i >= sika and i < kais:
                sika = kais
                count = i3
    for i2 in range(1,33):
        if (i2<=20 and i2%5==0) or i2==22 or i2==27 or i2==28:
            s = "N"
        else:
            s = "E"
        if s == "E":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                b.append(a[i4][3])
                b.append(a[i4][1])
                b.append(a[i4][0])
                b.append(a[i4][5])
                b.append(a[i4][4])
                b.append(a[i4][2])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
        elif s == "N":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                b.append(a[i4][1])
                b.append(a[i4][5])
                b.append(a[i4][2])
                b.append(a[i4][3])
                b.append(a[i4][0])
                b.append(a[i4][4])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
n = int(input())
inp = [[i for i in input().split()] for i in range(n)]
a = copy.copy(inp)
number = 3
count = 0
kais = n-1
for i in range(n-3):
    number += 3+i
for i in range(number):
    if i == kais-1:
        for i3 in range(n-1):
            if i3 == 0:
                sika = kais
                continue
            kais += n-i3
            if i >= sika and i < kais:
                sika = kais
                count = i3
    for i2 in range(1,33):
        if (i2<=20 and i2%5==0) or i2==22 or i2==27 or i2==28:
            s = "N"
        else:
            s = "E"
        if s == "E":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                append = b.append
                append(a[i4][3])
                append(a[i4][1])
                append(a[i4][0])
                append(a[i4][5])
                append(a[i4][4])
                append(a[i4][2])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
        elif s == "N":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                append = b.append
                append(a[i4][1])
                append(a[i4][5])
                append(a[i4][2])
                append(a[i4][3])
                append(a[i4][0])
                append(a[i4][4])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
n = int(input())
inp = [[i for i in input().split()] for i in range(n)]
a = copy.copy(inp)
number = 3
count = 0
yoshi = 33
kais = n-1
for i in range(n-3):
    number += 3+i
if n>=100:
    yoshi =21
for i in range(number):
    if i == kais-1:
        for i3 in range(n-1):
            if i3 == 0:
                sika = kais
                continue
            kais += n-i3
            if i >= sika and i < kais:
                sika = kais
                count = i3
    for i2 in range(1,yoshi):
        if (i2<=20 and i2%5==0) or i2==22 or i2==27 or i2==28:
            s = "N"
        else:
            s = "E"
        if s == "E":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                append = b.append
                append(a[i4][3])
                append(a[i4][1])
                append(a[i4][0])
                append(a[i4][5])
                append(a[i4][4])
                append(a[i4][2])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
        elif s == "N":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                append = b.append
                append(a[i4][1])
                append(a[i4][5])
                append(a[i4][2])
                append(a[i4][3])
                append(a[i4][0])
                append(a[i4][4])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
n = int(input())
inp = [[i for i in input().split()] for i in range(n)]
a = copy.copy(inp)
number = 3
count = 0
yoshi = 33
kais = n-1
for i in range(n-3):
    number += 3+i
if n>=100:
    yoshi =11
for i in range(number):
    if i == kais-1:
        for i3 in range(n-1):
            if i3 == 0:
                sika = kais
                continue
            kais += n-i3
            if i >= sika and i < kais:
                sika = kais
                count = i3
    for i2 in range(1,yoshi):
        if (i2<=20 and i2%5==0) or i2==22 or i2==27 or i2==28:
            s = "N"
        else:
            s = "E"
        if s == "E":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                append = b.append
                append(a[i4][3])
                append(a[i4][1])
                append(a[i4][0])
                append(a[i4][5])
                append(a[i4][4])
                append(a[i4][2])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
        elif s == "N":
            for i4 in range(len(inp)):
                if i4 == count:
                    continue
                b = []
                append = b.append
                append(a[i4][1])
                append(a[i4][5])
                append(a[i4][2])
                append(a[i4][3])
                append(a[i4][0])
                append(a[i4][4])
                a[i4][:] = b[:]
            for x in range(len(inp)):
                if x == count:
                    continue
                else:
                    if inp[count][:] == a[x][:]:
                        print("No")
                        sys.exit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
#dice4
def r(D,s):
    if s==0:
        t=D[0]
        D[0]=D[1]
        D[1]=D[5]
        D[5]=D[4]
        D[4]=t
    elif s==2:
        t=D[0]
        D[0]=D[4]
        D[4]=D[5]
        D[5]=D[1]
        D[1]=t        
    elif s==3:
        t=D[0]
        D[0]=D[3]
        D[3]=D[5]
        D[5]=D[2]
        D[2]=t        
    elif s==1:
        t=D[0]
        D[0]=D[2]
        D[2]=D[5]
        D[5]=D[3]
        D[3]=t
    elif s==4:
        D=r(r(D,1),1)
    return D
def ch(C,D):
    k=0
    while k<6 and C[k]==D[k]:
        k+=1
    if k==6:
        return 1
    else:
        return 0
def d3(C,D):
    nd=0
    if ch(C,D)==1:
        nd=1
    i=0
    while i<4 and nd==0:
        D=r(D,i)
        j=i+1
        j%=4
        k=0
        if ch(C,D)==1:
            nd=1
 #   if i==0:
    #    print(D)
        while k<3 and nd==0:
            D=r(D,j)
            if ch(C,D)==1:
                nd=1
            k+=1
  #      if i==0:
        #    print(D)
        D=r(D,j)
 #   if i==0:
   #     print(D)
        m=i+2
        m%=4
 #   if i==0:
    #    print(m)    
        D=r(D,m)
 #   if i==0:
 #       print(D)
        i+=1
    i=0
    while nd==0 and i<4:
        D=r(D,0)
        D=r(D,1)
        D=r(D,0)
        if ch(C,D)==1:
            nd=1
        D=r(r(D,0),0)
        if ch(C,D)==1:
            nd=1
        i+=1
    if nd==1:
        return 1
    else:
        return 0
n=int(input())
Dl=[[int(i) for i in input().split()] for i in range(n)]
i1=0
ne=1
while i1<n-1 and ne==1:
    i2=i1+1
    while i2<n and ne==1:
        if d3(Dl[i1],Dl[i2])==1:
            ne=0
if ne==0:
    print("No")
else:
    print("Yes")