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 C (judge verdict: Time Limit Exceeded)

#include <stdio.h>

int dice2[10];
int dicex(int a,int b,int c,int d);

int main(void)
{
    int i,j,dice[10];
    
    for(i=0;i<12;i++){
        scanf("%d",&dice[i]);
        if(i>=6) scanf("%d",&dice2[i-6]);
    }
    
    for(i=0;;i++){
        if(dice==dice2)break;
        if(dice[0]==dice2[0]){
            for(j=0;j<4;j++){
                *dice2=dicex(1,2,4,3);
                if(dice==dice2)break;
            }
        }else if(i<3){
            *dice2=dicex(0,1,5,4);
        }else{
            *dice2=dicex(0,2,5,3);
        }
    }
    
    if(dice==dice2){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

int dicex(int a,int b,int c,int d)
{
    int top;
    
    top=dice2[a];
    dice2[a]=dice2[b];
    dice2[b]=dice2[c];
    dice2[c]=dice2[d];
    dice2[d]=top;
    
    return dice2;
}