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

Solution in Python3 (judge verdict: Wrong Answer)

class Dice(object):
 
    def __init__(self, d):

        self.rows = [d[0], d[4], d[5], d[1]]
        self.cols = [d[0], d[2], d[5], d[3]]
 
    def move_next_rows(self):
        temp = self.rows.pop(0)
        self.rows.append(temp)
        self.__update(self.cols, self.rows)

    def move_prev_rows(self):
        temp = self.rows.pop(3)
        self.rows.insert(0, temp)
        self.__update(self.cols, self.rows)
    
    def move_next_cols(self):
        temp = self.cols.pop(0)
        self.cols.append(temp)
        self.__update(self.rows, self.cols)
 
    def move_prev_cols(self):
        temp = self.cols.pop(3)
        self.cols.insert(0, temp)
        self.__update(self.rows, self.cols)

    def __update(self, x, y):
        x[0] = y[0]
        x[2] = y[2]
 
class DiceChecker(object):

    def __init__(self, dice1, dice2):
        self.dice1 = dice1
        self.dice2 = dice2
        self.dice1_top = self.dice1.rows[0]
        self.dice1_front = self.dice1.rows[3]
        
    def check_same_dice(self):

        # self.__find_num(self.dice1_top, self.dice2)
        # if self.dice1_front not in self.dice2.rows:
        #     self.dice2.move_prev_cols()  
        #     self.__find_num(self.dice1_front, self.dice2)
        #     while self.dice1_top != self.dice2.rows[0]:
        #         self.dice2.move_next_rows()
        is_same = False
        for _ in range(4):
            for _ in range(4):
                is_same_element = self.dice1.rows == self.dice2.rows and self.dice1.cols == self.dice2.cols
                self.__rot(self.dice2)
                is_rot_same = self.dice1.rows == self.dice2.rows and self.dice1.cols == self.dice2.cols
                
                if is_same_element or is_rot_same: 
                    is_same = True
                    break
                self.dice2.move_next_cols()
                
                print(self.dice2.rows)

            else:     
                self.dice2.move_next_rows()
                continue
            break
        if is_same:
            print("Yes")
        else:
            print("No")
    
    def __find_num(self, x, dice):
        i = 0
        while x != dice.rows[0]:
            dice.move_next_rows()
            if i > 3:
                dice.move_next_cols()
                i = 0
            i+=1
    
    def __rot(self, dice):
        temp = dice.rows[1]
        dice.rows[1] = dice.rows[3]
        dice.rows[3] = temp

        temp = dice.cols[1]
        dice.cols[1] = dice.cols[3]
        dice.cols[3] = temp

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

dice_checker = DiceChecker(dice1, dice2)
dice_checker.check_same_dice()