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):
class Dice:
    same_dice_index = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5),
                       (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4),
                       (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3),
                       (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3),
                       (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2),
                       (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
                       (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0),
                       (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0))

    def __init__(self, str_tpl):
        self.faces = str_tpl

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            for n, j in enumerate(i):
                if dice.faces[n] != self.faces[j]:
                    break
            else:
                return True
        return False


str_tpl1 = tuple(input().split())
dice1 = Dice(str_tpl1)

str_tpl2 = tuple(input().split())
dice2 = Dice(str_tpl2)

if dice1.is_same(dice2):
    print('Yes')
else:
    print('No')

Solution (Python):
class Dice:
    same_dice_index = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5),
                       (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4),
                       (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3),
                       (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3),
                       (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2),
                       (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
                       (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0),
                       (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0))

    def __init__(self, str_tpl):
        self.faces = str_tpl

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            for n, j in enumerate(i):
                if dice.faces[n] != self.faces[j]:
                    break
            else:
                return True
        return False


str_tpl1 = tuple(input().split())
dice1 = Dice(str_tpl1)

str_tpl2 = tuple(input().split())
dice2 = Dice(str_tpl2)

if dice1.is_same(dice2):
    print('Yes')
else:
    print('No')

Solution (Python):
class Dice:
    same_dice_index = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5),
                       (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4),
                       (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3),
                       (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3),
                       (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2),
                       (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
                       (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0),
                       (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0))

    def __init__(self, str_tpl):
        self.faces = str_tpl

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            for n, j in enumerate(i):
                if dice.faces[n] != self.faces[j]:
                    break
            else:
                return 'Yes'
        return 'No'


str_tpl1 = tuple(input().split())
dice1 = Dice(str_tpl1)

str_tpl2 = tuple(input().split())
dice2 = Dice(str_tpl2)

print(dice1.is_same(dice2))

Solution (Python):

import sys
rolls1 = raw_input().split()
rolls2 = raw_input().split()
testpare = (rolls1[0],rolls1[5])
testparerev = (rolls1[5],rolls1[0])
rolls2pare = [(rolls2[0],rolls2[5]),(rolls2[2],rolls2[3]),(rolls2[1],rolls2[4])]


if testpare in rolls2pare:
    pareps = rolls2pare.index(testpare)
    revflag = False
elif testparerev in rolls2pare:
    pareps = rolls2pare.index(testparerev)
    revflag = True
else:
    print "No"
    sys.exit(0)


li1 = [rolls1[1],rolls1[2],rolls1[4],rolls1[3]]

if pareps==0:
    if revflag:
        tmp = rolls2[2]
        rolls2[2] = rolls2[3]
        rolls2[3] = tmp
    li2 = [rolls2[1],rolls2[2],rolls2[4],rolls2[3]]
elif pareps==1:
    if revflag:
        tmp = rolls2[1]
        rolls2[1] = rolls2[4]
        rolls2[4] = tmp
    li2 = [rolls2[0],rolls2[1],rolls2[5],rolls2[4]]
elif pareps==2:
    if revflag:
        tmp = rolls2[0]
        rolls2[0] = rolls2[5]
        rolls2[5] = tmp
    li2 = [rolls2[0],rolls2[3],rolls2[5],rolls2[2]]
else:
    print "No"
    sys.exit(0)



i=0
j=li2.index(li1[0])
matchflag = True
for x in xrange(4):
    
    if li1[i]==li2[j]:
        j+=1
        i+=1
    else:
        matchflag =False
        break
    if i>3:
        i=0
    if j>3:
        j=0
if matchflag:
    print "Yes"
else:
    print "No"

Solution (Python):
d1, d2 = list(map(int, input().split())), list(map(int, input().split()))

if tuple(sorted(d1)) != tuple(sorted(d2)):
    print('No')
    exit()

d1dict = {v: k for k, v in enumerate(d1)}
dms = ((1, 2, 4, 3), (0, 3, 5, 2), (0, 1, 5, 4), (0, 4, 5, 1), (0, 2, 5, 3), (1, 3, 4, 2))

d20 = d1dict[d2[0]]
dm = dms[d20]
try:
    dmi = dm.index(d1dict[d2[1]])
    print('Yes' if d2[2] == d1[dm[(dmi + 1) % 4]]
                   and d2[3] == d1[dm[(dmi + 3) % 4]]
                   and d2[4] == d1[dm[(dmi + 2) % 4]]
                   and d2[5] == d1[5 - d20] else 'No')
except:
    print('No')
    exit()

Solution (Python):
class Dice():
    def __init__(self, nums):
        self.nums = nums
        self.top, self.front, self.right = 0, 1, 2

    def __eq__(self, dice):
        for x in "NNNNEEE":
            dice.move(x)
            for _ in range(4):
                dice.move("ESW")
                if self.nums[self.top] == dice.nums[dice.top] and \
                        self.nums[self.front] == dice.nums[dice.front] and \
                        self.nums[self.right] == dice.nums[dice.right] and \
                        self.nums[5 - self.top] == dice.nums[5 - dice.top] and \
                        self.nums[5 - self.front] == dice.nums[5 - dice.front] and \
                        self.nums[5 - self.right] == dice.nums[5 - dice.right]:
                    return True
        return False

    def move(self, op):
        for c in op:
            if c == 'N':
                self.top, self.front = self.front, 5 - self.top
            elif c == 'S':
                self.top, self.front = 5 - self.front, self.top
            elif c == 'E':
                self.top, self.right = 5 - self.right, self.top
            else:
                self.top, self.right = self.right, 5 - self.top

dice1 = Dice([int(n) for n in input().split()])
dice2 = Dice([int(n) for n in input().split()])
if dice1 == dice2:
    print("Yes")
else:
    print("No")

Solution (Python):


class dice_class:
    def __init__(self, list):
        self.num = list

    def sut(self, top):  
        i = 0
        while i < 3:
            if self.num[0] == top:
                break
            else:
                self.roll('E')
            if self.num[0] == top:
                break
            else:
                self.roll('N')
            i += 1

    def suf(self, front):   
        i = 0
        while i < 4:
            if self.num[1] == front:
                break
            else:
                self.roll('SEN')
            i += 1

    def roll(self, s):
        for i in s:
            if i == 'E':
                self.rollE()
            elif i == 'N':
                self.rollN()
            elif i == 'S':
                self.rollS()
            elif i == 'W':
                self.rollW()

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

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

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

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


if __name__ == "__main__":
    dice1 = dice_class(map(int, raw_input().split()))
    dice2 = dice_class(map(int, raw_input().split()))
    flg = False

    for i in range(6):
        if i % 2:
            dice1.roll('E')
        else:
            dice1.roll('N')
        dice2.sut(dice1.num[0])
        dice2.suf(dice1.num[1])
        if dice1.num == dice2.num:
            flg = True
            break

    if flg:
        print "Yes"
    else:
        print "No"

Solution (Python):
import sys
class Dice:
    def __init__(self):
        self.front = '1'
        self.back = '6'
        self.top = '5'
        self.bottom = '2'
        self. right = '3'
        self.left = '4'
    def turnRight(self):
        temp = self.top
        self.top = self.left
        self.left = self.bottom
        self.bottom = self.right
        self.right = temp
        return self.top
    def turnLeft(self):
        temp = self.top
        self.top = self.right
        self.right = self.bottom
        self.bottom = self.left
        self.left = temp
        return self.top
    def turnFront(self):
        temp = self.top
        self.top = self.back
        self.back = self.bottom
        self.bottom = self.front
        self.front = temp
        return self.top
    def turnBack(self):
        temp = self.top
        self.top = self.front
        self.front = self.bottom
        self.bottom = self.back
        self.back = temp
        return self.top
    def __eq__(self, other):
        return (self.top, self.bottom, self.front, self.back, self.right, self.left) == other
    def __ne__(self, other):
        return (self.top, self.bottom, self.front, self.back, self.right, self.left) != other
def judge(obj1, obj2):
    if obj1 == obj2:
        print('Yes')
        sys.exit()
    else:
        return

A = Dice()
B = Dice()
A.top, A.front, A.right, A.left, A.back, A.bottom = input().split()
B.top, B.front, B.right, B.left, B.back, B.bottom = input().split()

for rot1 in range(4):
    for rot2 in range(4):
        judge(A, B)
        B.turnRight()
    B.turnFront()
B.turnRight()
B.turnFront()
for rot in range(4):
    judge(A,B)
    B.turnRight()
B.turnBack()
B.turnBack()
for rot in range(4):
    judge(A,B)
    B.turnRight()
print('No')

Solution (Python):
def move_dice(d, dir):
    if(dir == 'N'):
        d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
    if(dir == 'S'):
        d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]
    if(dir == 'E'):
        d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
    if(dir == 'W'):
        d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]

def rotate_right_dice(d):
    d[1], d[2], d[3], d[4] = d[3], d[1], d[4], d[2]

def to_up_dice(d, num_index):
    move_num = {0:0, 1:3, 2:2, 3:0, 4:1, 5:2}
    if(num_index==2 or num_index==3):
        move_dice(d, 'E')
    for _ in range(move_num[num_index]):
        move_dice(d, 'N')

def to_front_dice(d, num):
    while(d[1] != num):
        rotate_right_dice(d)

def equal_dice(d1, d2):
    for i in range(6):
        tmp_d = list(d1)
        to_up_dice(tmp_d, i)
        for _ in range(4):
            if(tmp_d == d2): return 'Yes'
            else: rotate_right_dice(tmp_d)
    return 'No'



dice1 = list(map(int, input().split()))
dice2 = list(map(int, input().split()))

print(equal_dice(dice1, dice2))

Solution (Python):
import sys


class Dice:
    def __init__(self, labels):
        self.labels = labels

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def change(self, convert):
        result = []
        for i in range(6):
            result.append(self.labels[convert[i] - 1])

        self.labels = result

directions = 'EEEESEEEESEEEESEEEESNWSEEEESSEEEE'

dice1 = Dice(list(map(int, input().split())))
dice2 = Dice(list(map(int, input().split())))

for direction in directions:
    if direction == 'N':
        dice1.north()
    if direction == 'S':
        dice1.south()
    if direction == 'E':
        dice1.east()
    if direction == 'W':
        dice1.west()

    if dice1.labels == dice2.labels:
        print('Yes')
        sys.exit(0)

print('No')

Solution (Python):




class Dice:
    def __init__(self, nums):
        self.face = nums
    
    def turnSouth(self):
        temp = self.face[0]
        self.face[0] = self.face[4]
        self.face[4] = self.face[5]
        self.face[5] = self.face[1]
        self.face[1] = temp
        return self
    
    def turnEast(self):
        temp = self.face[0]
        self.face[0] = self.face[2]
        self.face[2] = self.face[5]
        self.face[5] = self.face[3]
        self.face[3] = temp
        return self
    
    def turnWest(self):
        temp = self.face[0]
        self.face[0] = self.face[3]
        self.face[3] = self.face[5]
        self.face[5] = self.face[2]
        self.face[2] = temp
        return self
    
    def turnNorth(self):
        temp = self.face[0]
        self.face[0] = self.face[1]
        self.face[1] = self.face[5]
        self.face[5] = self.face[4]
        self.face[4] = temp
    
    def turnRight(self):
        temp = self.face[1]
        self.face[1] = self.face[2]
        self.face[2] = self.face[4]
        self.face[4] = self.face[3]
        self.face[3] = temp
        return self
    
    def turnLeft(self):
        temp = self.face[1]
        self.face[1] = self.face[3]
        self.face[3] = self.face[4]
        self.face[4] = self.face[2]
        self.face[2] = temp
        return self
    def equals(self, Dice):
        
        for i in range(0, 4):
            if self.face[0] == Dice.face[0]:
                
                for j in range(0, 4):
                    if self.face[1] == Dice.face[1]:
                        if self.face == Dice.face:
                            return True
                    Dice.turnRight()
            Dice.turnNorth()
        
        for i in range(0, 4):
            if self.face[0] == Dice.face[0]:
                
                for j in range(0, 4):
                    if self.face[1] == Dice.face[1]:
                        if self.face == Dice.face:
                            return True
                    Dice.turnRight()
            Dice.turnEast()
        return False


Dice1 = Dice(input().split())
Dice2 = Dice(input().split())

if Dice1.equals(Dice2):
    print("Yes")
else:
    print("No")

Solution (Python):
d1=tuple(map(int,input().split()))
d2=tuple(map(int,input().split()))

def rot(d, r):
    if r == 'N':
        return (d[1], d[5], d[2], d[3], d[0], d[4])
    if r == 'E':
        return (d[3], d[1], d[0], d[5], d[4], d[2])
    if r == 'W':
        return (d[2], d[1], d[5], d[0], d[4], d[3])
    if r == 'S':
        return (d[4], d[0], d[2], d[3], d[5], d[1])
    return d

def gen_all( d1 ):
    ds = { d1 }
    while 1:
        ds2 = { rot(d, r) for d in ds for r in list('NEWS') }.union(ds)
        if ds == ds2: break
        ds = ds2
    return ds

print('Yes' if d2 in gen_all(d1) else 'No')

Solution (Python):





class Dice:
    def __init__(self, nums):
        self.face = nums

    
    def turnSouth(self):
        temp = self.face[0]
        self.face[0] = self.face[4]
        self.face[4] = self.face[5]
        self.face[5] = self.face[1]
        self.face[1] = temp
        return self

    
    def turnEast(self):
        temp = self.face[0]
        self.face[0] = self.face[2]
        self.face[2] = self.face[5]
        self.face[5] = self.face[3]
        self.face[3] = temp
        return self

    
    def turnWest(self):
        temp = self.face[0]
        self.face[0] = self.face[3]
        self.face[3] = self.face[5]
        self.face[5] = self.face[2]
        self.face[2] = temp
        return self

    
    def turnNorth(self):
        temp = self.face[0]
        self.face[0] = self.face[1]
        self.face[1] = self.face[5]
        self.face[5] = self.face[4]
        self.face[4] = temp

    
    def turnRight(self):
        temp = self.face[1]
        self.face[1] = self.face[2]
        self.face[2] = self.face[4]
        self.face[4] = self.face[3]
        self.face[3] = temp
        return self

    
    def turnLeft(self):
        temp = self.face[1]
        self.face[1] = self.face[3]
        self.face[3] = self.face[4]
        self.face[4] = self.face[2]
        self.face[2] = temp
        return self

    def equals(self, another):
        
        for i in range(0, 4):
            if self.face[0] == another.face[0]:
                
                for j in range(0, 4):
                    if self.face[1] == another.face[1]:
                        if self.face == another.face:
                            return True
                    another.turnRight()
            another.turnNorth()
        
        for i in range(0, 4):
            if self.face[0] == another.face[0]:
                
                for j in range(0, 4):
                    if self.face[1] == another.face[1]:
                        if self.face == another.face:
                            return True
                    another.turnRight()
            another.turnEast()
        return False


Dice1 = Dice(input().split())
Dice2 = Dice(input().split())

if Dice1.equals(Dice2):
    print("Yes")
else:
    print("No")

Solution (Python):





class Dice:
    def __init__(self, nums):
        self.face = nums

    
    def __turnSouth__(self):
        temp = self.face[0]
        self.face[0] = self.face[4]
        self.face[4] = self.face[5]
        self.face[5] = self.face[1]
        self.face[1] = temp
        return self

    
    def __turnEast__(self):
        temp = self.face[0]
        self.face[0] = self.face[2]
        self.face[2] = self.face[5]
        self.face[5] = self.face[3]
        self.face[3] = temp
        return self

    
    def __turnWest__(self):
        temp = self.face[0]
        self.face[0] = self.face[3]
        self.face[3] = self.face[5]
        self.face[5] = self.face[2]
        self.face[2] = temp
        return self

    
    def __turnNorth__(self):
        temp = self.face[0]
        self.face[0] = self.face[1]
        self.face[1] = self.face[5]
        self.face[5] = self.face[4]
        self.face[4] = temp

    
    def __turnRight__(self):
        temp = self.face[1]
        self.face[1] = self.face[2]
        self.face[2] = self.face[4]
        self.face[4] = self.face[3]
        self.face[3] = temp
        return self

    
    def __turnLeft__(self):
        temp = self.face[1]
        self.face[1] = self.face[3]
        self.face[3] = self.face[4]
        self.face[4] = self.face[2]
        self.face[2] = temp
        return self

    def equals(self, another):
        
        for i in range(0, 4):
            if self.face[0] == another.face[0]:
                
                for j in range(0, 4):
                    if self.face[1] == another.face[1]:
                        if self.face == another.face:
                            return True
                    another.__turnRight__()
            another.__turnNorth__()
        
        for i in range(0, 4):
            if self.face[0] == another.face[0]:
                
                for j in range(0, 4):
                    if self.face[1] == another.face[1]:
                        if self.face == another.face:
                            return True
                    another.__turnRight__()
            another.__turnEast__()
        return False


Dice1 = Dice(input().split())
Dice2 = Dice(input().split())

if Dice1.equals(Dice2):
    print("Yes")
else:
    print("No")

Solution (Python):

class dise:
    def __init__(self, label):
        self.label1 = label[0]
        self.label2 = label[1]
        self.label3 = label[2]
        self.label4 = label[3]
        self.label5 = label[4]
        self.label6 = label[5]
    
    def N_rotation(self):
        reg = self.label1
        self.label1 = self.label2
        self.label2 = self.label6
        self.label6 = self.label5
        self.label5 = reg
        
    def E_rotation(self):
        reg = self.label1
        self.label1 = self.label4
        self.label4 = self.label6
        self.label6 = self.label3
        self.label3 = reg
        
    def S_rotation(self):
        reg = self.label1
        self.label1 = self.label5
        self.label5 = self.label6
        self.label6 = self.label2
        self.label2 = reg
        
    def W_rotation(self):
        reg = self.label1
        self.label1 = self.label3
        self.label3 = self.label6
        self.label6 = self.label4
        self.label4 = reg
    
    def right_rotation(self):
        reg = self.label2
        self.label2 = self.label3
        self.label3 = self.label5
        self.label5 = self.label4
        self.label4 = reg
    
'''
    def search(self, other_dise):
        count = 0
        while True:
            count += 1
            self.N_rotation()
            if other_dise[0] == self.label1:
                break
            self.E_rotation()
            if other_dise[0] == self.label1:
                break
            if count == 6:
                print("No")
                break

            count = 0            
        while True :
            count += 1
            self.right_rotation()
            if other_dise[1] == self.label2 and other_dise[2] == self.label3 and other_dise[3] == self.label4 and other_dise[4] == self.label5:
                print("Yes")
                break
            if count == 4:
                print("No")
                break
'''



dise1 = dise(input().split())
dise2 = dise(input().split())
flag = 0

for i in range(3):
    dise1.N_rotation()
    if dise1.label1 == dise2.label1 and dise1.label6 == dise2.label6 :
        for j in range(4):
            dise1.right_rotation()
            if dise1.label2 == dise2.label2 and dise1.label3 == dise2.label3 and dise1.label4 == dise2.label4 and dise1.label5 == dise2.label5:
                flag = 1
                break
    dise1.E_rotation()
    if dise1.label1 == dise2.label1 and dise1.label6 == dise2.label6 :
        for j in range(4):
            dise1.right_rotation()
            if dise1.label2 == dise2.label2 and dise1.label3 == dise2.label3 and dise1.label4 == dise2.label4 and dise1.label5 == dise2.label5:
                flag = 1
                break
    
            
            
if flag == 1:
    print("Yes")
elif flag == 0:
    print("No")





'''
class dise:
    def __init__(self, label):
        self.label1 = label[0]
        self.label2 = label[1]
        self.label3 = label[2]
        self.label4 = label[3]
        self.label5 = label[4]
        self.label6 = label[5]
    
    def N_rotation(self):
        reg = self.label1
        self.label1 = self.label2
        self.label2 = self.label6
        self.label6 = self.label5
        self.label5 = reg
        
    def E_rotation(self):
        reg = self.label1
        self.label1 = self.label4
        self.label4 = self.label6
        self.label6 = self.label3
        self.label3 = reg
        
    def S_rotation(self):
        reg = self.label1
        self.label1 = self.label5
        self.label5 = self.label6
        self.label6 = self.label2
        self.label2 = reg
        
    def W_rotation(self):
        reg = self.label1
        self.label1 = self.label3
        self.label3 = self.label6
        self.label6 = self.label4
        self.label4 = reg
    
    def right_rotation(self):
        reg = self.label2
        self.label2 = self.label3
        self.label3 = self.label5
        self.label5 = self.label4
        self.label4 = reg
    

    def search(self, other_dise):
        count = 0
        while True:
            count += 1
            self.N_rotation()
            if other_dise[0] == self.label1:
                break
            self.E_rotation()
            if other_dise[0] == self.label1:
                break
            if count == 6:
                print("No")
                break

            count = 0            
        while True :
            count += 1
            self.right_rotation()
            if other_dise[1] == self.label2 and other_dise[2] == self.label3 and other_dise[3] == self.label4 and other_dise[4] == self.label5:
                print("Yes")
                break
            if count == 4:
                print("No")
                break



dise1 = dise(input().split())
dise2 = dise(input().split())

for i in range(6):
    if dise1.label1 == dise2.label1 and dise1.label6 == dise2.label6 :
        for j in range(4):
            dise1.right_rotation()
            if dise1.label2 == dise2.label2 and dise1.label3 == dise2.label3 and dise1.label4 == dise2.label4 and dise1.label5 == dise2.label5:
                print("Yes")
                break
            if i == 3:
            

dise1.search(dise2)
'''

Solution (Python):
def s2n(dice):
    aft_dice = [dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]]
    return aft_dice

def w2e(dice):
    aft_dice = [dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]]
    return aft_dice

def rspin(dice):
    aft_dice = [dice[0],dice[2],dice[4],dice[1],dice[3],dice[5]]
    return aft_dice

def isd(dice1, dice2):
    if dice1 == dice2:
        return 1
    return 0

dice1 = map(int, raw_input().split())
dice2 = map(int, raw_input().split())

flag = 0

for i in xrange(4):
    for j in xrange(4):
        flag += isd(dice1, dice2);
        dice2 = rspin(dice2)
    dice2 = s2n(dice2)

dice2 = w2e(dice2)
for i in xrange(4):
    flag += isd(dice1, dice2)
    dice2 = rspin(dice2)

dice2 = w2e(dice2)
dice2 = w2e(dice2)
for i in xrange(4):
    flag += isd(dice1, dice2)
    dice2 = rspin(dice2)

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

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,label):
        self.label = {i+1: l for i,l in enumerate(label)}
    def roll(self,op):
        l = self.label
        if   op=='N': self.label = {1:l[2], 2:l[6], 3:l[3], 4:l[4], 5:l[1], 6:l[5]}
        elif op=='E': self.label = {1:l[4], 2:l[2], 3:l[1], 4:l[6], 5:l[5], 6:l[3]}
        elif op=='W': self.label = {1:l[3], 2:l[2], 3:l[6], 4:l[1], 5:l[5], 6:l[4]}
        elif op=='S': self.label = {1:l[5], 2:l[1], 3:l[3], 4:l[4], 5:l[6], 6:l[2]}
    def yaw(self,op):
        l = self.label
        if   op=='CW' : self.label = {1:l[1], 2:l[3], 3:l[5], 4:l[2], 5:l[4], 6:l[6]}
        elif op=='CCW': self.label = {1:l[1], 2:l[4], 3:l[2], 4:l[5], 5:l[3], 6:l[6]}
    def get_label(self,i=0):
        if 1 <= i <= 6:
            return self.label[i]
        else:
            return [self.label[x] for x in range(1,7)] 


if __name__ == '__main__':
    d0 = dice(list(map(int,input().split())))
    d1 = dice(list(map(int,input().split())))
    result='No'
    if set(d0.get_label())==set(d1.get_label()):
        for i in range(6):
            for _ in range(4):
                if d0.get_label()==d1.get_label():
                    result='Yes'
                    break
                d0.yaw('CW')
            if d0.get_label()==d1.get_label():
                break
            if i < 4:
                d0.roll('E')
            if i >= 3:
                d0.roll('N')
            if i >= 4:
                d0.roll('N')
    print(result)

Solution (Python):
import sys
import math

def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S

def float_to_str(num):
    return str("{:.10f}".format(num))

def list_input(tp):
    return map(tp, str_input().split())



class Dice:
    pip = [0 for i in xrange(6)]

    def __init__(self, arg):
        self.pip = arg

    def rollDir(self, dr):
        nextPip = [0 for i in xrange(6)]
        if dr == "N":
            nextPip[0] = self.pip[1]
            nextPip[1] = self.pip[5]
            nextPip[2] = self.pip[2]
            nextPip[3] = self.pip[3]
            nextPip[4] = self.pip[0]
            nextPip[5] = self.pip[4]
        elif dr == "E":
            nextPip[0] = self.pip[3]
            nextPip[1] = self.pip[1]
            nextPip[2] = self.pip[0]
            nextPip[3] = self.pip[5]
            nextPip[4] = self.pip[4]
            nextPip[5] = self.pip[2]
        self.pip = nextPip

    def roll(self, dr):
        if dr == "N" or dr == "E":
            self.rollDir(dr)
        elif dr == "S":
            self.rollDir("N")
            self.rollDir("N")
            self.rollDir("N")
        elif dr == "W":
            self.rollDir("E")
            self.rollDir("E")
            self.rollDir("E")

    def check(self, a, b):
        while self.pip[0] != a:
            if self.pip[2] != a and self.pip[3] != a:
                self.roll("N")
            else:
                self.roll("N")
                self.roll("W")
                self.roll("S")

        while self.pip[1] != b:
            self.roll("N")
            self.roll("W")
            self.roll("S")
        return self.pip[2]

dice1 = Dice(list_input(int))
dice2 = Dice(list_input(int))

for i in xrange(4):
    for j in xrange(4):
        if dice1.pip == dice2.pip:
            print "Yes"
            sys.exit()
        dice2.roll("E")
    dice2.roll("N")
dice2.roll("N")
dice2.roll("E")
dice2.roll("S")
for i in xrange(4):
    if dice1.pip == dice2.pip:
        print "Yes"
        sys.exit()
    dice2.roll("E")
dice2.roll("N")
dice2.roll("E")
dice2.roll("E")
dice2.roll("S")
for i in xrange(4):
    if dice1.pip == dice2.pip:
        print "Yes"
        sys.exit()
    dice2.roll("E")

print "No"