Problem:
Dice III Write a program which reads the two dices constructed in the same way as Dice I , and determines whether these two dices are identical. You can roll a dice in the same way as Dice I , and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical. Input In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels. In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels. Output Print " Yes " if two dices are identical, otherwise " No " in a line. Constraints  $0 \leq $ the integer assigned to a face $ \leq 100$  Sample Input 1 1 2 3 4 5 6
6 2 4 3 5 1 Sample Output 1 Yes Sample Input 2 1 2 3 4 5 6
6 5 4 3 2 1 Sample Output 2 No

Solution (Python):


import random


class Dice() :

    mask = {'N':(1,5,2,3,0,4), 'E':(3,1,0,5,4,2),
            'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1)}
    way = ("N","E","W","S")

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

    def move(self, data):
        self.label = [self.label[idx] for idx in self.mask[data]]

    def get_up(self):
        return self.label[0]

    def compare(self, dice2):
        ok = False
        for i in range(1000):
            check = True
            for i2 in range(6):
                if self.label[i2] == dice2.label[i2] :
                    continue
                else:
                    check = False
                    break

            if check :
                ok = True
                break
            else:
                self.move(self.way[random.randint(0,1)])
        return ok

dice1 = Dice(input().split())
dice2 = Dice(input().split())

if dice1.compare(dice2) :
    print ("Yes")
else:
    print ("No")

Solution (Python):


import random


class Dice() :

    mask = {'N':(1,5,2,3,0,4), 'E':(3,1,0,5,4,2),
            'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1),'CW':(0,2,4,1,3,5)}

    way = ("N","E","W","S","CW","Nop")

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

    def move(self, data):
        if data == "Nop":
            return
        self.label = [self.label[idx] for idx in self.mask[data]]

    def get_up(self):
        return self.label[0]

    def compare_6sq(self, dice2):
        check = True
        for i in range(6):
            if self.label[i] == dice2.label[i] :
                continue
            else:
                check = False
                break

        return check
    
    def compare_4rot(self, dice2):
        ok = False
        for i in range(4):
            self.move("CW")
            if self.compare_6sq(dice2) :
                ok =True
                break
        return ok
    
    def compare(self,dice2):
        ok = False
        orderway =("Nop","E","N","E","N","E")

        for s in orderway:
            self.move(s)
            if self.compare_4rot(dice2):
                ok = True
                break
        
        return ok





dice1 = Dice(input().split())
dice2 = Dice(input().split())

if dice1.compare(dice2) :
    print ("Yes")
else:
    print ("No")

Solution (Python):
from enum import Enum
import sys
import math


class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5

    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])

    def query(self,top_num,front_num):
        self.save_data = [i for i in range(6)]
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]
        ret =-1

        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break
        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]

    def equal(self,another):
        ret = False;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG=True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return ret;

diceA = Dice()
diceB = Dice()
table=list(map(int,input().split()))
diceA.setNumber(table[0],table[1],table[2],table[3],table[4],table[5])

table=list(map(int,input().split()))
diceB.setNumber(table[0],table[1],table[2],table[3],table[4],table[5])

if diceA.equal(diceB):
    print("Yes")
else:
    print("No")

Solution (Python):
class Dice():
	def __init__(self):
		self.number = [_ for _ in range(6)]
		self.work = [_ for _ in range(6)]
		self.order = "NNNNWNNNWNNNENNNENNNWNNN"
	def setNumber(self,n0,n1,n2,n3,n4,n5):
		self.number[0] = n0
		self.number[1] = n1
		self.number[2] = n2
		self.number[3] = n3
		self.number[4] = n4
		self.number[5] = n5

	def roll(self,loc):
		for _ in range(6):
			self.work[_] = self.number[_]
		if loc == "E":
			self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
		elif loc == "N":
			self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
		elif loc == "S":
			self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
		elif loc == "W":
			self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
	def get_top(self):
		return self.number[0]
	def get_right(self,n1,n2):
		if(n1 == self.number[0]):
			if(n2 == self.number[1]): return(self.number[2])
			elif(n2 == self.number[2]): return(self.number[4])
			elif(n2 == self.number[3]): return(self.number[1])
			elif(n2 == self.number[4]): return(self.number[3])
		elif(n1 == self.number[1]):
                        if(n2 == self.number[0]): return(self.number[3])
                        elif(n2 == self.number[2]): return(self.number[0])
                        elif(n2 == self.number[3]): return(self.number[5])
                        elif(n2 == self.number[5]): return(self.number[2])
		elif(n1 == self.number[2]):
                        if(n2 == self.number[0]): return(self.number[1])
                        elif(n2 == self.number[1]): return(self.number[5])
                        elif(n2 == self.number[4]): return(self.number[0])
                        elif(n2 == self.number[5]): return(self.number[4])
		elif(n1 == self.number[3]):
                        if(n2 == self.number[0]): return(self.number[4])
                        elif(n2 == self.number[1]): return(self.number[0])
                        elif(n2 == self.number[4]): return(self.number[5])
                        elif(n2 == self.number[5]): return(self.number[1])
		elif(n1 == self.number[4]):
                        if(n2 == self.number[0]): return(self.number[2])
                        elif(n2 == self.number[2]): return(self.number[5])
                        elif(n2 == self.number[3]): return(self.number[0])
                        elif(n2 == self.number[5]): return(self.number[3])
		elif(n1 == self.number[5]):
                        if(n2 == self.number[1]): return(self.number[3])
                        elif(n2 == self.number[2]): return(self.number[1])
                        elif(n2 == self.number[3]): return(self.number[4])
                        elif(n2 == self.number[4]): return(self.number[2])

	def equals(self,another):
		ret = False
		for i in range(len(self.order)):
			self.roll(self.order[i])
			flg = True
			for k in range(6):
				if self.number[k] != another.number[k]:
					flg = False
					break
			if flg == True:
				return True
		return ret
dice1 = Dice()
dice2 = Dice()

data = list(map(int,input().split()))
dice1.setNumber(data[0],data[1],data[2],data[3],data[4],data[5])
data = list(map(int,input().split()))
dice2.setNumber(data[0],data[1],data[2],data[3],data[4],data[5])

if dice1.equals(dice2):
	print("Yes")
else:
	print("No")

Solution (Python):
def roll(l, command):
    '''
    return rolled list

    l : string list
    command: string
    '''
    res = []
    i = -1
    if command =='N':
        res = [l[i+2], l[i+6], l[i+3], l[i+4], l[i+1], l[i+5]]
    if command =='S':
        res = [l[i+5], l[i+1], l[i+3], l[i+4], l[i+6], l[i+2]]
    if command =='E':
        res = [l[i+4], l[i+2], l[i+1], l[i+6], l[i+5], l[i+3]]
    if command =='W':
        res = [l[i+3], l[i+2], l[i+6], l[i+1], l[i+5], l[i+4]]

    return res

def spin(l):
    '''
    return right sppined list

    l : string list
    '''

    i = -1
    res = [l[i+1], l[i+3], l[i+5], l[i+2], l[i+4], l[i+6]]

    return res
def has_same_faces(a, b):
    '''
    check if all elements of a are equel to those of b.
    a : string list
    b : string list
    '''
    return set(a) == set(b)

def is_identical_lists(a, b):
    for x, y in zip(a, b):
        if x != y:
            return False

    return True

def check_two_dice(a, b):
    if not has_same_faces(a, b):
        return False
    
    orig_a = a[:]

    
    for i in range(6):
        if 1 <= i <= 3:
            a = roll(a, "N")
        elif i == 4:
            pass
            a = orig_a[:]
            a = roll(a, "W")
        elif i == 5:
            a = orig_a[:]
            a = roll(a, "E")

        
        for _ in range(4): 
            a = spin(a)
            if is_identical_lists(a, b):
                return True
        
    return False


if __name__ == "__main__":
    a_list = input().split()
    b_list = input().split()
    res = check_two_dice(a_list, b_list)  
    print("Yes") if res else print("No")

Solution (Python):
class Dice(object):
    def __init__(self, s1, s2, s3, s4, s5, s6):
        self.s1 = s1
        self.s2 = s2
        self.s3 = s3
        self.s4 = s4
        self.s5 = s5
        self.s6 = s6
    def east(self):
        prev_s6 = self.s6
        self.s6 = self.s3
        self.s3 = self.s1
        self.s1 = self.s4
        self.s4 = prev_s6
    def west(self):
        prev_s6 = self.s6
        self.s6 = self.s4
        self.s4 = self.s1
        self.s1 = self.s3
        self.s3 = prev_s6
    def north(self):
        prev_s6 = self.s6
        self.s6 = self.s5
        self.s5 = self.s1
        self.s1 = self.s2
        self.s2 = prev_s6
    def south(self):
        prev_s6 = self.s6
        self.s6 = self.s2
        self.s2 = self.s1
        self.s1 = self.s5
        self.s5 = prev_s6
    def rotate(self):
        prev_s2 = self.s2
        self.s2 = self.s4
        self.s4 = self.s5
        self.s5 = self.s3
        self.s3 = prev_s2
    def top(self):
        return self.s1
    def front(self):
        return self.s2
    def right(self):
        return self.s3

    def isSameDice(self, anotherDice):
        if self.s1 == anotherDice.s1 and \
           self.s2 == anotherDice.s2 and \
           self.s3 == anotherDice.s3 and \
           self.s4 == anotherDice.s4 and \
           self.s5 == anotherDice.s5 and \
           self.s6 == anotherDice.s6:
            return True
        return False


s1, s2, s3, s4, s5, s6 = map(int, input().split())
dice1 = Dice(s1, s2, s3, s4, s5, s6)
s1, s2, s3, s4, s5, s6 = map(int, input().split())
dice2 = Dice(s1, s2, s3, s4, s5, s6)

flag = False
for j in range(6):
    if j % 2 == 0:
        dice2.north()
    else:
        dice2.west()

    for k in range(4):
        dice2.rotate()
        if dice2.isSameDice(dice1):
            flag = True
            break
    if flag:
        break

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

Solution (Python):
mask = [[i for i in range(6)], (1, 5, 2, 3, 0, 4), (2, 1, 5, 0, 4,3),(3, 1, 0, 5, 4, 2), (4, 0, 2, 3, 5, 1)]
mask += [[mask[1][i] for i in mask[1]]]

def set_top(dice, top):
    return [dice[i] for i in mask[top]]

def twist(dice):
    return [dice[i] for i in (0, 3, 1, 4, 2, 5)]

def equal(dice1, dice2):
    for i in range(6):
        tmp_dice = set_top(dice2, i)
        for _ in range(4):
            if dice1 == tmp_dice:
                return True
            tmp_dice = twist(tmp_dice)
    return False
        
dice1 = input().split()
dice2 = input().split()

print('Yes' if equal(dice1, dice2) else 'No')

Solution (Python):
IDX_TBL = \
{1:[2,3,5,4],
 2:[3,1,4,6],
 3:[1,2,6,5],
 4:[1,5,6,2],
 5:[1,3,6,4],
 6:[2,4,5,3]}

l1=["-"] + raw_input().split(" ")
l2=["-"] + raw_input().split(" ")

if l1[1] not in l2:
    print "No"
else:
    idx_list = [i for i,x in enumerate(l2) if x==l1[1]]

    for idx in idx_list:
        nums1 = "".join([l1[i] for i in IDX_TBL[1]])
        nums2 = "".join([l2[i] for i in IDX_TBL[idx]])

        if nums2 in nums1*2:
            print "Yes"
            break
        else:
            continue
    else:
        print "No"

Solution (Python):
import sys

IDX_TBL = {1:[2,3,5,4], 2:[3,1,4,6], 3:[1,2,6,5],
           4:[1,5,6,2], 5:[1,3,6,4], 6:[2,4,5,3]}

l1=["_"] + raw_input().split(" ")
l2=["_"] + raw_input().split(" ")

if l1[1] in l2:
    idx_list = [i for i,x in enumerate(l2) if x==l1[1]]

    for idx in idx_list:
        nums1 = "".join([l1[i] for i in IDX_TBL[1]])
        nums2 = "".join([l2[i] for i in IDX_TBL[idx]])
        if nums2 in nums1*2:
            print "Yes"
            sys.exit(0)
print "No"

Solution (Python):
class Dice:
    def __init__(self, data):
        self.data = data
    
    def __eq__(self, value):
        for a in range(0,6,5):
            self.moveTopTo(self.getSortedList()[a])
            value.moveTopTo(value.getSortedList()[a])
            for b in range(4):
                if self.data == value.data:
                    return True
                else:
                    value.move('R')
        return False

    def move(self, direction):
        if direction == 'E':
            self.data[0], self.data[3], self.data[5], self.data[2] = \
                self.data[3], self.data[5], self.data[2], self.data[0]
        elif direction == 'N':
            self.data[0], self.data[4], self.data[5], self.data[1] = \
                self.data[1], self.data[0], self.data[4], self.data[5]
        elif direction == 'S':
            self.data[0], self.data[1], self.data[5], self.data[4] = \
                self.data[4], self.data[0], self.data[1], self.data[5]
        elif direction == 'W':
            self.data[0], self.data[2], self.data[5], self.data[3] = \
                self.data[2], self.data[5], self.data[3], self.data[0]
        elif direction == 'R':
            self.data[1], self.data[2], self.data[4], self.data[3] = \
                self.data[3], self.data[1], self.data[2], self.data[4]
        elif direction == 'L':
            self.data[1], self.data[2], self.data[4], self.data[3] = \
                self.data[2], self.data[4], self.data[3], self.data[1]

    def moveTopTo(self, target):
        for a in range(4):
            if self.data[0] == target:
                break
            self.move('W')
        if self.data[4] == target:
            self.move('S')
        elif self.data[1] == target:
            self.move('N')
    
    def moveFrontTo(self, target):
        for a in range(4):
            if self.data[1] == target:
                break
            self.move('R')

    def getTop(self):
        return self.data[0]
    
    def getRight(self):
        return self.data[2]

    def getSortedList(self):
        tmp = self.data[:]
        tmp.sort()
        return tmp


a = Dice(input().split())
b = Dice(input().split())
if a == b:
    print('Yes')
else:
    print('No')

Solution (Python):
class Dice:
    def __init__(self, data):
        self.data = data

    def __eq__(self, value):
            
        for i in range(4):
            if self.data[0] == value.data[0]:
                for j in range(4):
                    if self.data == value.data:
                        return True
                    self.move('R')
            self.move('E')

        for i in range(4):
            if self.data[0] == value.data[0]:
                for j in range(4):
                    if self.data == value.data:
                        return True
                    self.move('R')
            self.move('N')
        return False

    def move(self, direction):
        if direction == 'E':
            self.data[0],self.data[3], self.data[5], self.data[2] = \
                self.data[3],self.data[5], self.data[2], self.data[0] 
        elif direction == 'N':
            self.data[0],self.data[1], self.data[5], self.data[4] = \
                self.data[1],self.data[5], self.data[4], self.data[0]
        elif direction == 'S':
            self.data[0],self.data[1], self.data[5], self.data[4] = \
                self.data[4],self.data[0], self.data[1], self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2], self.data[5], self.data[3] = \
                self.data[2],self.data[5], self.data[3], self.data[0]
        elif direction == 'R':
            self.data[1],self.data[2], self.data[4], self.data[3] = \
                self.data[2],self.data[4], self.data[3], self.data[1]

a = Dice(input().split())
b = Dice(input().split())

if a == b:
    print('Yes')
else:
    print('No')

Solution (Python):


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__":
    label1 = {}
    label2 = {}
    n1 = map(int, raw_input().split())
    n2 = map(int, raw_input().split())
    for i in range(6):
        label1[i+1] = n1[i]
        label2[i+1] = n2[i]
    
    
    count = 0
    flag = 0
    while True:
        if(label1 == label2):
            flag = 1
            break
        x = random()
        if(x < 0.25):
            command('E', label1)
        elif(x < 0.50):
            command('W', label1)
        elif(x < 0.75):
            command('N', label1)
        else:
            command('S', label1)
        count += 1
        
        if(count > 1000):
            break
    if(flag == 1):
        print 'Yes'
    else:
        print 'No'

Solution (Python):
import sys

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

    def roll_north(self):
        self.__dice = (self.__dice[1], self.__dice[5], self.__dice[2],
                       self.__dice[3], self.__dice[0], self.__dice[4])

    def roll_south(self):
        self.__dice = (self.__dice[4], self.__dice[0], self.__dice[2],
                       self.__dice[3], self.__dice[5], self.__dice[1])

    def roll_west(self):
        self.__dice = (self.__dice[2], self.__dice[1], self.__dice[5],
                       self.__dice[0], self.__dice[4], self.__dice[3])

    def roll_east(self):
        self.__dice = (self.__dice[3], self.__dice[1], self.__dice[0],
                       self.__dice[5], self.__dice[4], self.__dice[2])

    def number(self, face_id):
        return self.__dice[face_id - 1]

    def equals(self, dice):
        my_pair = {self.number(1): self.number(6),
                   self.number(2): self.number(5),
                   self.number(3): self.number(4),
                   self.number(4): self.number(3),
                   self.number(5): self.number(2),
                   self.number(6): self.number(1)}
        other_pair = {dice.number(1): dice.number(6),
                      dice.number(2): dice.number(5),
                      dice.number(3): dice.number(4),
                      dice.number(4): dice.number(3),
                      dice.number(5): dice.number(2),
                      dice.number(6): dice.number(1)}
        if my_pair != other_pair:
            return False
        if self.number(2) in (dice.number(3), dice.number(4)):
            dice.roll_west()
        while self.number(2) != dice.number(2):
            dice.roll_north()
        while self.number(1) != dice.number(1):
            dice.roll_west()
        return self.number(3) == dice.number(3)

dice1 = Dice([int(i) for i in sys.stdin.readline().split()])
dice2 = Dice([int(i) for i in sys.stdin.readline().split()])
if dice1.equals(dice2):
    print("Yes")
else:
    print("No")

Solution (Python):
import copy

class Dice(object):
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, directions):
        if directions == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if directions == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if directions == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if directions == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

        self.roll(directions[0])
        self.roll(directions[1:])

    def equal(self, dice):
        d = copy.copy(self)

        if(dice.front == d.top):
            d.roll('S')
        elif(dice.front == d.right):
            d.roll('WS')
        elif(dice.front == d.left):
            d.roll('ES')
        elif(dice.front == d.back):
            d.roll('SS')
        elif(dice.front == d.bottom):
            d.roll('N')

        if(dice.top == d.right):
            d.roll('W')
        elif(dice.top == d.left):
            d.roll('E')
        elif(dice.top == d.bottom):
            d.roll('WW')

        return not(dice.top != d.top or dice.front != d.front or dice.right != d.right or dice.left != d.left or dice.back != d.back or dice.bottom != d.bottom)

if __name__ == '__main__':
    d1 = Dice([int(i) for i in input().split()])
    d2 = Dice([int(i) for i in input().split()])
    if d1.equal(d2):
        print('Yes')
    else:
        print("No")

Solution (Python):
import copy, sys

class Dice(object):
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, directions):
        if directions == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if directions == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if directions == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if directions == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

        self.roll(directions[0])
        self.roll(directions[1:])

    def equal(self, dice):
        d = copy.copy(self)

        if(dice.front == d.top):
            d.roll('S')
        elif(dice.front == d.right):
            d.roll('WS')
        elif(dice.front == d.left):
            d.roll('ES')
        elif(dice.front == d.back):
            d.roll('SS')
        elif(dice.front == d.bottom):
            d.roll('N')

        if(dice.top == d.right):
            d.roll('W')
        elif(dice.top == d.left):
            d.roll('E')
        elif(dice.top == d.bottom):
            d.roll('WW')

        return not(dice.top != d.top or dice.front != d.front or dice.right != d.right or dice.left != d.left or dice.back != d.back or dice.bottom != d.bottom)

if __name__ == '__main__':
    nums1 = [int(i) for i in input().split()]
    nums2 = [int(i) for i in input().split()]
    if set(nums1) != set(nums2):
        print('No')
        sys.exit()

    d1 = Dice(nums1)
    d2 = Dice(nums2)
    if d1.equal(d2):
        print('Yes')
    else:
        print("No")

Solution (Python):


import time
import sys
import io
import re
import math
import itertools



mod=1000000007

pi=3.141592653589
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]

ans=chk=0
a=[0,2,5,3]
b=[0,1,5,4]
c=[1,2,4,3]

def rolling(word,dice):
    if word=='S':
        dice[0],dice[1],dice[5],dice[4]=dice[4],dice[0],dice[1],dice[5]
    elif word=='N':
        dice[0],dice[1],dice[5],dice[4]=dice[1],dice[5],dice[4],dice[0]
    elif word=='W':
        dice[0],dice[2],dice[5],dice[3]=dice[2],dice[5],dice[3],dice[0]
    else:
        dice[0],dice[2],dice[5],dice[3]=dice[3],dice[0],dice[2],dice[5]
    return dice

def sortdice(dice1,dice2,p,q,r):
    for i in range(4):
        dice1[p[0]],dice1[p[1]],dice1[p[2]],dice1[p[3]]=dice1[p[1]],dice1[p[2]],dice1[p[3]],dice1[p[0]]
        for j in range(4):
            dice1[q[0]],dice1[q[1]],dice1[q[2]],dice1[q[3]]=dice1[q[1]],dice1[q[2]],dice1[q[3]],dice1[q[0]]
            for k in range(4):
                dice1[r[0]],dice1[r[1]],dice1[r[2]],dice1[r[3]]=dice1[r[1]],dice1[r[2]],dice1[r[3]],dice1[r[0]]
                if dice1==dice2:
                    print 'Yes'
                    exit()
    return 0

l1=map(int,raw_input().split())
l2=map(int,raw_input().split())
sortdice(l1,l2,a,b,c)
print 'No'

Solution (Python):
class Dice:	
	def __init__( self, nums ):
		self.face = nums
	
	def rolltoTopIndex( self, faceindex ):	
		if faceindex == 1:
			self.roll( "N" )
		elif faceindex == 2:
			self.roll( "W" )
		elif faceindex == 3:
			self.roll( "E" )
		elif faceindex == 4:
			self.roll( "S" )
		elif faceindex == 5:
			self.roll( "NN" )
	
	def roll( self, actions ):
		for act in actions:
			t = 0
			if act == "E":
				t =   self.face[0]
				self.face[0] =   self.face[3]
				self.face[3] =   self.face[5]
				self.face[5] =   self.face[2]
				self.face[2] = t
			elif  act == "N":
				t =   self.face[0]
				self.face[0] =   self.face[1]
				self.face[1] =   self.face[5]
				self.face[5] =   self.face[4]
				self.face[4] = t
			elif  act == "S":
				t =  self.face[ 0]
				self.face[0] =  self.face[4]
				self.face[4] =  self.face[5]
				self.face[5] =  self.face[1]
				self.face[1] = t	
			elif  act == "W":
				t =  self.face[0]
				self.face[0] =  self.face[2]
				self.face[2] =  self.face[5]
				self.face[5] =  self.face[3]
				self.face[3] = t	
			elif  act == "M":
				t =  self.face[1]
				self.face[1] =  self.face[2]
				self.face[2] =  self.face[4]
				self.face[4] =  self.face[3]
				self.face[3] = t

diceface = [ int( val ) for val in raw_input( ).split( " " ) ]
dice1 = Dice( diceface )
diceface = [ int( val ) for val in raw_input( ).split( " " ) ]
dice2 = Dice( diceface )


cnt = 0
for i in range( 6 ):
	if dice1.face[0] == dice2.face[i]:
		dice2.rolltoTopIndex( i )
		for j in range( 1, 5 ):
			if dice1.face[1] == dice2.face[1]:
				cnt = 0
				for k in range( 6 ):
					if dice1.face[k] == dice2.face[k]:
						cnt += 1
				if cnt == 6:
					break
			dice2.roll( "M" )
	if cnt == 6:
		break
	dice2.face = diceface


if cnt == 6:
	print( "Yes" )
else:
	print( "No" )

Solution (Python):
class Dice:	
	def __init__( self, nums ):
		self.face = nums
	
	def rolltoTopIndex( self, faceindex ):	
		if faceindex == 1:
			self.roll( "N" )
		elif faceindex == 2:
			self.roll( "W" )
		elif faceindex == 3:
			self.roll( "E" )
		elif faceindex == 4:
			self.roll( "S" )
		elif faceindex == 5:
			self.roll( "NN" )
	
	def roll( self, actions ):
		for act in actions:
			t = 0
			if act == "E":
				t =   self.face[0]
				self.face[0] =   self.face[3]
				self.face[3] =   self.face[5]
				self.face[5] =   self.face[2]
				self.face[2] = t
			elif  act == "N":
				t =   self.face[0]
				self.face[0] =   self.face[1]
				self.face[1] =   self.face[5]
				self.face[5] =   self.face[4]
				self.face[4] = t
			elif  act == "S":
				t =  self.face[ 0]
				self.face[0] =  self.face[4]
				self.face[4] =  self.face[5]
				self.face[5] =  self.face[1]
				self.face[1] = t	
			elif  act == "W":
				t =  self.face[0]
				self.face[0] =  self.face[2]
				self.face[2] =  self.face[5]
				self.face[5] =  self.face[3]
				self.face[3] = t	
			elif  act == "M":
				t =  self.face[1]
				self.face[1] =  self.face[2]
				self.face[2] =  self.face[4]
				self.face[4] =  self.face[3]
				self.face[3] = t

diceface = [ int( val ) for val in input( ).split( " " ) ]
dice1 = Dice( diceface )
diceface = [ int( val ) for val in input( ).split( " " ) ]
dice2 = Dice( diceface )


cnt = 0
for i in range( 6 ):
	if dice1.face[0] == dice2.face[i]:
		dice2.rolltoTopIndex( i )
		for j in range( 1, 5 ):
			if dice1.face[1] == dice2.face[1]:
				cnt = 0
				for k in range( 6 ):
					if dice1.face[k] == dice2.face[k]:
						cnt += 1
				if cnt == 6:
					break
			dice2.roll( "M" )
	if cnt == 6:
		break
	dice2.face = diceface


if cnt == 6:
	print( "Yes" )
else:
	print( "No" )

Solution (Python):
p=[0,2,5,3]
q=[0,1,5,4]
r=[1,2,4,3]

dice1=map(int,raw_input().split())
dice2=map(int,raw_input().split())
for i in range(4):
    dice1[p[0]],dice1[p[1]],dice1[p[2]],dice1[p[3]]=dice1[p[1]],dice1[p[2]],dice1[p[3]],dice1[p[0]]
    for j in range(4):
        dice1[q[0]],dice1[q[1]],dice1[q[2]],dice1[q[3]]=dice1[q[1]],dice1[q[2]],dice1[q[3]],dice1[q[0]]
        for k in range(4):
            dice1[r[0]],dice1[r[1]],dice1[r[2]],dice1[r[3]]=dice1[r[1]],dice1[r[2]],dice1[r[3]],dice1[r[0]]
            if dice1==dice2:
                print 'Yes'
                exit()
print 'No'

Solution (Python):
import random
class Dice:
    def __init__(self, top, front, right, left, back, bottom):
        self.top,   self.bottom = top, bottom
        self.right, self.left   = right, left
        self.front, self.back   = front, back

    def rot(self, d):
        if   d == "N":
            (self.top, self.back, self.bottom, self.front) = (
             self.front, self.top, self.back, self.bottom)
        elif d == "S":
            (self.top, self.back, self.bottom, self.front) = (
             self.back, self.bottom, self.front, self.top)
        elif d == "E":
            (self.top, self.right, self.bottom, self.left) = (
             self.left, self.top, self.right, self.bottom)
        elif d == "W":
            (self.top, self.right, self.bottom, self.left) = (
             self.right, self.bottom, self.left, self.top)

def same(a, b):
    if ((a.top, a.bottom, a.right, a.left, a.front, a.back) ==
        (b.top, b.bottom, b.right, b.left, b.front, b.back)):
        return True
    else:
        return False

ref = {}
ls1 = map(int, raw_input().split())
ls2 = map(int, raw_input().split())
dice1 = Dice(ls1[0], ls1[1], ls1[2], ls1[3], ls1[4], ls1[5])
dice2 = Dice(ls2[0], ls2[1], ls2[2], ls2[3], ls2[4], ls2[5])
for i in xrange(1000):
    d = "NSEW"[random.randint(0,3)]
    dice1.rot(d)
    if same(dice1, dice2):
        print "Yes"
        break
else:
    print "No"