Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

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



Sample input:
1 2 3 4 5 6
6 2 4 3 5 1


Sample output:
Yes

Submission status: Accepted

Solution code:
class Dice(object):
    """Dice Class

    """

    def __init__(self, numbers):
        """

        Args:
            numbers:
        """
        self.numbers_inverse = {numbers[0]: 1, numbers[1]: 2, numbers[2]: 3, numbers[3]: 4, numbers[4]: 5,
                                numbers[5]: 6}
        self.numbers = {1: numbers[0], 2: numbers[1], 3: numbers[2], 4: numbers[3], 5: numbers[4], 6: numbers[5]}

        self.vertical = [self.numbers[1], self.numbers[2], self.numbers[6], self.numbers[5]]
        self.horizontal = [self.numbers[4], self.numbers[1], self.numbers[3], self.numbers[6]]

    def roll_dice(self, str):
        """

        Args:
            str: move direction

        Returns:

        """
        for s in str:
            if s == 'N':
                self.move_north()
            elif s == 'S':
                self.move_south()
            elif s == 'W':
                self.move_west()
            elif s == 'E':
                self.move_east()

    def set_top(self, value):
        """
        Args:
            value: target_value
        """
        counter = 0
        while counter < 4:
            if self.vertical[0] == value:
                self.map_values()
                return
            else:
                self.roll_dice("S")
            counter += 1
        counter = 0
        while counter < 4:
            if self.vertical[0] == value:
                self.map_values()
                return
            else:
                self.roll_dice("W")
            counter += 1

    def set_front(self, value):
        """
        Args:
            value: target value
        """
        counter = 0
        while counter < 4:
            if self.vertical[1] == value:
                self.map_values()
                return
            else:
                self.roll_dice("SWN")
            counter += 1

    def move_south(self):
        """move this dice towered north
        """
        self.vertical = (self.vertical * 2)[3:7]
        self.horizontal[1] = self.vertical[0]
        self.horizontal[3] = self.vertical[2]
        self.map_values()

    def move_north(self):
        """move this dice towered south
        """
        self.vertical = (self.vertical * 2)[1:5]
        self.horizontal[1] = self.vertical[0]
        self.horizontal[3] = self.vertical[2]
        self.map_values()

    def move_east(self):
        """move this dice towered east
        """
        self.horizontal = (self.horizontal * 2)[3:7]
        self.vertical[0] = self.horizontal[1]
        self.vertical[2] = self.horizontal[3]
        self.map_values()

    def move_west(self):
        """move this dice towered west
        """
        self.horizontal = (self.horizontal * 2)[1:5]
        self.vertical[0] = self.horizontal[1]
        self.vertical[2] = self.horizontal[3]
        self.map_values()

    def map_values(self):
        self.numbers[1] = self.vertical[0]
        self.numbers[2] = self.vertical[1]
        self.numbers[3] = self.horizontal[2]
        self.numbers[4] = self.horizontal[0]
        self.numbers[5] = self.vertical[3]
        self.numbers[6] = self.vertical[2]

    def get_top(self):
        return self.vertical[0]


dice1 = Dice([int(x) for x in raw_input().split()])
dice2 = Dice([int(x) for x in raw_input().split()])

flag = False
if dice1.numbers == dice2.numbers:
    flag = True
else:
    for i in range(6):
        dice1.set_top(i+1)
        for j in xrange(4):
            dice1.roll_dice("SWN")
            if dice1.numbers == dice2.numbers:
                flag = True
        dice1.roll_dice("S")

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

Submission status: Accepted

Solution code:
dice1 = map(int, raw_input().split())
dice2 = map(int, raw_input().split())
  
def rolling(inst, dice):
    if inst == 'E':
        dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
    elif inst == 'W':
        dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
    elif inst == 'N':
        dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
    elif inst == 'S':
        dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
  
def dice_matching():
    if dice1[1] == dice2[1]:
        for i in range(4):
            if dice1 == dice2:
                return 1
                break
            rolling('E', dice2)
        return 0
    else:
        return 0
 
count = 0
while(1):
    if dice_matching() == 1:
        print "Yes"
        break
    else:
        if count < 3:
            rolling('N', dice2)
            count += 1
        elif 7 > count and count >= 3:
            if count == 3:
                rolling('E', dice2)
            rolling('N', dice2)
            count += 1
        else:
            print "No"
            break

Submission status: Accepted

Solution code:
class Dice(object):
    """
    6??¢???????????????
    ?????¢???top, ?????¢???bottom???????????\??????4??¢??????????????? north, south, east, west ??¨?????¶???
    """
    def __init__(self, faces):
        # faces???????????????????????¨?????????????????????????????????
        # ???????????? top, south, east, west, north, bottom ????????§????´????????????????????????¨??????????????????????????§???top??????????????£????????????
        self.top = faces[0]
        self.south = faces[1]
        self.east = faces[2]
        self.west = faces[3]
        self.north = faces[4]
        self.bottom = faces[5]
        self.values = (self.top, self.south, self.east, self.west, self.north, self.bottom)

    def rotate(self, dir):
        # ???????????????dir??????????????????????????¢?????????
        # ????????????N, S, E, W???????????????????????????(1??????)??§????????????
        if dir == 'N':
            temp = self.top
            self.top = self.south
            self.south = self.bottom
            self.bottom = self.north
            self.north = temp
        elif dir == 'S':
            temp = self.top
            self.top = self.north
            self.north = self.bottom
            self.bottom = self.south
            self.south = temp
        elif dir == 'E':
            temp = self.top
            self.top = self.west
            self.west = self.bottom
            self.bottom = self.east
            self.east = temp
        elif dir == 'W':
            temp = self.top
            self.top = self.east
            self.east = self.bottom
            self.bottom = self.west
            self.west = temp

    def get_top_value(self):
        return self.top

    def get_bottom_value(self):
        return self.bottom

    def get_east_value(self):
        return self.east

    def get_west_value(self):
        return self.west

    def get_north_value(self):
        return self.north

    def get_south_value(self):
        return self.south

    def spin(self, count=1):
        """???????????????top??¨bottom?????????????????????????????????????????????????????????????¨??????????90????????¢?????????
        ?????????????????§???1?????????????????????????????§?????§?????°??????????????????
        """
        for i in range(count):
            temp = self.south
            self.south = self.east
            self.east = self.north
            self.north = self.west
            self.west = temp

    def place(self, upper, front):
        """ ?????¢(top)??¨??¨??¢(south)?????????????????????upper, front??¨???????????????????????????????????¢?????????
        ??????????????????????????¨??????????????????????????????????????¢?????????????????????????????????????????????????????´???????????????(ValueError)?????????????????????
        """
        # ????????? top == upper??¨????????????????????¢?????????
        if upper not in self.values or front not in self.values:
            raise ValueError
        if upper == self.top:
            pass
        elif upper == self.east:
            self.rotate('W')
        elif upper == self.west:
            self.rotate('E')
        elif upper == self.north:
            self.rotate('S')
        elif upper == self.south:
            self.rotate('N')
        else:
            self.rotate('N')
            self.rotate('N')
        # ????????????south == front ??¨????????????????????¢?????????
        #if front == self.bottom:
        #    raise ValueError
        count = 0
        while front != self.south:
            self.spin()
            count += 1
            if count > 4:
                raise ValueError

    def is_identical(self, dice):
        """ ????????¨???????????????????????????????§????????????£?????????????¢?????????? (?????¢???????????°??????????????????????????????)
        :param dice: ?????????????????????????????????
        :return: ???????§????????????????(True/False)
        """
        # 6??¢????????????????§????????????£?????????????¢????
        my_v = sorted(list(self.values))
        d_v = sorted(list(dice.values))
        if my_v != d_v:
            return False

        # ?????¢????§????????¢????
        try:
            dice.place(self.get_top_value(), self.get_south_value())
        except ValueError:
            return False
        if self.get_east_value() != dice.get_east_value():
            return False
        self.spin()
        try:
            dice.place(self.get_top_value(), self.get_south_value())
        except ValueError:
            return False
        if self.get_east_value() != dice.get_east_value():
            return False
        self.spin()
        try:
            dice.place(self.get_top_value(), self.get_south_value())
        except ValueError:
            return False
        if self.get_east_value() != dice.get_east_value():
            return False
        self.spin()
        try:
            dice.place(self.get_top_value(), self.get_south_value())
        except ValueError:
            return False
        if self.get_east_value() != dice.get_east_value():
            return False

        return True


if __name__ == '__main__':
    # ??????????????\???
    dice1_values = [int(x) for x in input().split(' ')]
    dice2_values = [int(x) for x in input().split(' ')]


    # ??????????????????????????????????§?????????????????¢??????????
    d1 = Dice(dice1_values)
    d2 = Dice(dice2_values)

    if d1.is_identical(d2):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
class Dice(object):
    """
    6??¢???????????????
    ?????¢???top, ?????¢???bottom???????????\??????4??¢??????????????? north, south, east, west ??¨?????¶???
    """
    def __init__(self, faces):
        # faces???????????????????????¨?????????????????????????????????
        # ???????????? top, south, east, west, north, bottom ????????§????´????????????????????????¨??????????????????????????§???top??????????????£????????????
        self.top = faces[0]
        self.south = faces[1]
        self.east = faces[2]
        self.west = faces[3]
        self.north = faces[4]
        self.bottom = faces[5]
        self.values = (self.top, self.south, self.east, self.west, self.north, self.bottom)

    def rotate(self, dir):
        # ???????????????dir??????????????????????????¢?????????
        # ????????????N, S, E, W???????????????????????????(1??????)??§????????????
        if dir == 'N':
            temp = self.top
            self.top = self.south
            self.south = self.bottom
            self.bottom = self.north
            self.north = temp
        elif dir == 'S':
            temp = self.top
            self.top = self.north
            self.north = self.bottom
            self.bottom = self.south
            self.south = temp
        elif dir == 'E':
            temp = self.top
            self.top = self.west
            self.west = self.bottom
            self.bottom = self.east
            self.east = temp
        elif dir == 'W':
            temp = self.top
            self.top = self.east
            self.east = self.bottom
            self.bottom = self.west
            self.west = temp

    def get_top_value(self):
        return self.top

    def get_bottom_value(self):
        return self.bottom

    def get_east_value(self):
        return self.east

    def get_west_value(self):
        return self.west

    def get_north_value(self):
        return self.north

    def get_south_value(self):
        return self.south

    def spin(self, count=1):
        """???????????????top??¨bottom?????????????????????????????????????????????????????????????¨??????????90????????¢?????????
        ?????????????????§???1?????????????????????????????§?????§?????°??????????????????
        """
        for i in range(count):
            temp = self.south
            self.south = self.east
            self.east = self.north
            self.north = self.west
            self.west = temp

    def place(self, upper, front):
        """ ?????¢(top)??¨??¨??¢(south)?????????????????????upper, front??¨???????????????????????????????????¢?????????
        ??????????????????????????¨??????????????????????????????????????¢?????????????????????????????????????????????????????´???????????????(ValueError)?????????????????????
        """
        # ????????? top == upper??¨????????????????????¢?????????
        if upper not in self.values or front not in self.values:
            raise ValueError
        if upper == self.top:
            pass
        elif upper == self.east:
            self.rotate('W')
        elif upper == self.west:
            self.rotate('E')
        elif upper == self.north:
            self.rotate('S')
        elif upper == self.south:
            self.rotate('N')
        else:
            self.rotate('N')
            self.rotate('N')
        # ????????????south == front ??¨????????????????????¢?????????
        #if front == self.bottom:  # ?????°??¢??§????????????????????????????????§????????????????????§????????????3?????¢??????????????????????????????????????°???????????????
        #    raise ValueError
        count = 0
        while front != self.south:
            self.spin()
            count += 1
            if count > 3:
                raise ValueError

    def is_identical(self, dice):
        """ ????????¨???????????????????????????????§????????????£?????????????¢?????????? (?????¢???????????°??????????????????????????????)
        :param dice: ?????????????????????????????????
        :return: ???????§????????????????(True/False)
        """
        # 6??¢????????????????§????????????£?????????????¢????
        my_v = sorted(list(self.values))
        d_v = sorted(list(dice.values))
        if my_v != d_v:
            return False

        # ?????¢????§????????¢????
        try:
            dice.place(self.get_top_value(), self.get_south_value())
        except ValueError:
            return False
        if self.get_east_value() != dice.get_east_value():
            return False
        self.spin()
        try:
            dice.place(self.get_top_value(), self.get_south_value())
        except ValueError:
            return False
        if self.get_east_value() != dice.get_east_value():
            return False
        self.spin()
        try:
            dice.place(self.get_top_value(), self.get_south_value())
        except ValueError:
            return False
        if self.get_east_value() != dice.get_east_value():
            return False
        self.spin()
        try:
            dice.place(self.get_top_value(), self.get_south_value())
        except ValueError:
            return False
        if self.get_east_value() != dice.get_east_value():
            return False

        return True


if __name__ == '__main__':
    # ??????????????\???
    dice1_values = [int(x) for x in input().split(' ')]
    dice2_values = [int(x) for x in input().split(' ')]


    # ??????????????????????????????????§?????????????????¢??????????
    d1 = Dice(dice1_values)
    d2 = Dice(dice2_values)

    if d1.is_identical(d2):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
    
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d
        self.dic={"W":0,"S":1,"E":2,"N":3}

    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[way]

        if(way==0):
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way==1:
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way==2:
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c

import random
u,s,e,w,n,d=map(int,input().split())
dice=Dice(u,w,s,e,n,d)
u,s,e,w,n,d=map(int,input().split())
dice_b=Dice(u,w,s,e,n,d)
ok=False
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):
        ok=True
if ok:
    print('Yes')
else :
    print('No')

Submission status: Accepted

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

d1 = list(map(int, input().split()))
top, front, right = d1[0], d1[1], d1[2]
d2 = list(map(int, input().split()))
da1 = {v: k for k, v in enumerate(d1)}
da2 = {v: k for k, v in enumerate(d2)}
boo = True if len(da1) == 6 and len(da2) == 6 else False
if boo:
    x, y = da2[top], da2[front]
    adjacent = {v: k for k, v in da2.items()}
    try:
        if right == adjacent[p[x][y]]:
            print("Yes")
        else:
            print("No")
    except KeyError:
        print("No")

else:
    db1 = [(k, v) for k, v in enumerate(d1)]
    db2 = [(k, v) for k, v in enumerate(d2)]
    for m in range(5, 1, -1):
        if db1[m][1] != db1[m-1][1]:
            x, y = db1[m][0], db1[m-1][0]
            t1, f1, r1 = db1[m][0], db1[m-1][0], db1[p[x][y]][0]
            break
        else:
            t1, f1, r1 = 0, 0, 0
    for m in range(5, 1, -1):
        if db2[m][1] != db2[m-1][1]:
            x, y = db2[m][0], db2[m-1][0]
            t2, f2, r2 = db2[m][0], db2[m-1][0], db2[p[x][y]][0]

    if t2 == r1 and r2 == t1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

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

	def roll(self,com):
		a1,a2,a3,a4,a5,a6=self.d
		if com=="E":
			self.d = [a4,a2,a1,a6,a5,a3]
		elif com=="W":
			self.d = [a3,a2,a6,a1,a5,a4]
		elif com=="S":
			self.d = [a5,a1,a3,a4,a6,a2]
		elif com=="N":
			self.d = [a2,a6,a3,a4,a1,a5]

dice1=dice(d1)
dice2=dice(d2)

if sorted(d1)!=sorted(d2):
	print("No")
else:
	c=["E","W","S","N"]
	import random
	n=0
	while n<10**5:
		if dice1.d==dice2.d:
			break 
		else:
			dice1.roll(c[random.randint(1,2)])
		n+=1
	if n==10**5:
		print("No")
	else:
		print("Yes")

Submission status: Accepted

Solution code:
class Dice:
    index_list_map = [[[-1],[2,3,4,5],[4,1,3,5],[1,4,2,5],[3,2,1,5],[-1]],
                      [[3,2,5,4],[-1],[0,5,3,4],[5,0,2,4],[-1],[2,3,0,4]],
                      [[1,4,5,3],[5,0,4,3],[-1],[-1],[0,5,1,3],[4,1,0,3]],
                      [[4,1,5,2],[0,5,4,2],[-1],[-1],[5,0,1,2],[1,4,0,2]],
                      [[2,3,5,1],[-1],[5,0,3,1],[0,5,2,1],[-1],[3,2,0,1]],
                      [[-1],[3,2,4,0],[1,4,3,0],[4,1,2,0],[2,3,1,0],[-1]]]

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

    def lookup_east_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][0]]


    def lookup_west_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][1]]

    def lookup_north_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][2]]

    def lookup_down_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][3]]

spots1 = map(int,raw_input().split())
spots2 = map(int,raw_input().split())

s2_index_u = [ i for i,x in enumerate(spots2) if x == spots1[0]]
s2_index_s = [ i for i,x in enumerate(spots2) if x == spots1[1]]

combinations_u_s = [ [x,y] for x in s2_index_u for y in s2_index_s if x != y and (abs(x-2.5) != abs(y-2.5))]

dice2 = Dice(spots2)

for comb in  combinations_u_s :
    e = dice2.lookup_east_side(comb[0],comb[1])
    w = dice2.lookup_west_side(comb[0],comb[1])
    n = dice2.lookup_north_side(comb[0],comb[1])
    d = dice2.lookup_down_side(comb[0],comb[1])

    if e == spots1[2] and w == spots1[3] and n == spots1[4] and d == spots1[5]:
        print "Yes"
        quit()
print "No"

Submission status: Accepted

Solution code:
class Dice:
    index_list_map = [[[-1],[2,3,4,5],[4,1,3,5],[1,4,2,5],[3,2,1,5],[-1]],
                      [[3,2,5,4],[-1],[0,5,3,4],[5,0,2,4],[-1],[2,3,0,4]],
                      [[1,4,5,3],[5,0,4,3],[-1],[-1],[0,5,1,3],[4,1,0,3]],
                      [[4,1,5,2],[0,5,4,2],[-1],[-1],[5,0,1,2],[1,4,0,2]],
                      [[2,3,5,1],[-1],[5,0,3,1],[0,5,2,1],[-1],[3,2,0,1]],
                      [[-1],[3,2,4,0],[1,4,3,0],[4,1,2,0],[2,3,1,0],[-1]]]

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

    def lookup_east_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][0]]


    def lookup_west_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][1]]

    def lookup_north_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][2]]

    def lookup_down_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][3]]

    def is_same(self,dice):
        index_u = [ i for i,x in enumerate(dice.num) if x == self.num[0]]
        index_s = [ i for i,x in enumerate(dice.num) if x == self.num[1]]

        combinations_u_s = [ [x,y] for x in index_u for y in index_s if x != y and (abs(x-2.5) != abs(y-2.5))]
        for comb in  combinations_u_s :
            e = dice.lookup_east_side(comb[0],comb[1])
            w = dice.lookup_west_side(comb[0],comb[1])
            n = dice.lookup_north_side(comb[0],comb[1])
            d = dice.lookup_down_side(comb[0],comb[1])
            if e == self.num[2] and w == self.num[3] and n == self.num[4] and d == self.num[5]:
                return True
        return False

spots1 = map(int,raw_input().split())
spots2 = map(int,raw_input().split())

dice1 = Dice(spots1)
dice2 = Dice(spots2)

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

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self,num):
        self.f=num[0]
        self.s=num[1]
        self.e=num[2]
        self.w=num[3]
        self.n=num[4]
        self.b=num[5]
    def create(self,order):
        if order=='N':
            return [self.s,self.b,self.e,self.w,self.f,self.n]
        elif order=='S':
            return [self.n,self.f,self.e,self.w,self.b,self.s]
        elif order=='E':
            return [self.w,self.s,self.f,self.b,self.n,self.e]
        else:
            return [self.e,self.s,self.b,self.f,self.n,self.w]
    def judge(self,dice_2):
        T={0:'N',1:'E',2:'S',3:'W'}
        m=[dice_2.s,dice_2.w,dice_2.n,dice_2.e,dice_2.f,dice_2.b]
        for i in range(6):
            if m[i]==self.f:#?????¢??¨?????´???????????????????????????
                if i==4:temp=dice_2#?????¢??????????????´
                elif i==5:temp=Dice(Dice(dice_2.create('N')).create('N'))#?????¢??¨?????´
                else:temp=Dice(dice_2.create(T[i]))#??´??¢??¨?????´

                if self.b==temp.b:
                        side_1=''.join(list(map(str,[self.s,self.w,self.n,self.e])))*2
                        side_2=''.join(list(map(str,[temp.s,temp.w,temp.n,temp.e])))
                        if side_2 in side_1:return 'Yes'
        return 'No'
num_1=list(map(int,input().split()))
num_2=list(map(int,input().split()))
dice_1=Dice(num_1)
dice_2=Dice(num_2)
print(dice_1.judge(dice_2))

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, init_values = ['1','2','3','4','5','6']):
        self.value = dict(zip(["top", "front","right","left","back","bottom"]\
                             , init_values))

    #north, south, east and west
    def roll(self, direction):
        if direction == 'N':
            self.value["top"], self.value["front"], self.value["bottom"], self.value["back"] = \
            self.value["front"], self.value["bottom"], self.value["back"], self.value["top"]
        elif direction == 'S':
            self.value["top"], self.value["back"], self.value["bottom"], self.value["front"] = \
            self.value["back"], self.value["bottom"], self.value["front"], self.value["top"]
        elif direction == 'E':
            self.value["top"], self.value["left"], self.value["bottom"], self.value["right"] = \
            self.value["left"], self.value["bottom"], self.value["right"], self.value["top"]
        elif direction == 'W':
            self.value["top"], self.value["right"], self.value["bottom"], self.value["left"] = \
            self.value["right"], self.value["bottom"], self.value["left"], self.value["top"]
        else:
            print("Error: illegal format.")

    # clockwise, counterclockwise
    def spin(self, direction):
        if direction == "CW":
            self.value["front"], self.value["right"], self.value["back"], self.value["left"] = \
            self.value["right"], self.value["back"], self.value["left"], self.value["front"]
        elif direction == "CCW":
            self.value["front"], self.value["left"], self.value["back"], self.value["right"] = \
            self.value["left"], self.value["back"], self.value["right"], self.value["front"]
        else:
            print("Error: illegal format.")
            
dice1 = Dice(input().split())
dice2 = Dice(input().split())

result = "No"
for direction in 'SESESE':
    dice2.roll(direction)
    if dice1.value["top"] == dice2.value["top"]:
        for j in range(4):
            dice2.spin("CW")
            if dice1.value == dice2.value:
                result = "Yes"
                break

print(result)

Submission status: Accepted

Solution code:

class Dice:
    def __init__(self, label):
        self.d = label

    def roll(self, direction):
        if direction == "N":
            self.d[0], self.d[1], self.d[5], self.d[4] = self.d[1], self.d[5], self.d[4], self.d[0]
        elif direction == "S":
            self.d[0], self.d[1], self.d[5], self.d[4] = self.d[4], self.d[0], self.d[1], self.d[5]
        elif direction == "E":
            self.d[0], self.d[2], self.d[5], self.d[3] = self.d[3], self.d[0], self.d[2], self.d[5]
        elif direction == "W":
            self.d[0], self.d[2], self.d[5], self.d[3] = self.d[2], self.d[5], self.d[3], self.d[0]
        else:
            pass

label = [int(i) for i in input().split()]
label2 = [int(i) for i in input().split()]

dice1 = Dice(label)
dice2 = Dice(label2)

# ??¨????????¶???(4 * 6)???????????????????????¢??????
cmd = "N" * 4 + ("W" + "N" * 4) * 3 + "NE" + "N" * 4 + "EE" + "N" * 4 

for i in cmd:
    dice2.roll(i)

    if dice1.d == dice2.d:
        print("Yes")
        break
else:
    print("No")

Submission status: Accepted

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]

men = map(int, (raw_input()).split(" "))
d1 = Dice(men)
men = map(int, (raw_input()).split(" "))
d2 = Dice(men)

flag = False

for i in range(4):
    d1.throw("W")
    for j in range(4):
        d1.throw("S")
        if d1.men == d2.men:
            flag = True

for i in range(4):
    d1.throw("C")
    for j in range(4):
        d1.throw("S")
        if d1.men == d2.men:
            flag = True

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