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 N[6]={1,5,2,3,0,4},S[6]={4,0,2,3,5,1};
int E[6]={3,1,0,5,4,2},W[6]={2,1,5,0,4,3},O[6]={0,1,2,3,4,5};
int PT[8]={3,1,2,4,3,1,2,4};
void cpy(int *a,int *b,char dir){
    int i,*d;
    if (dir=='N'){d=N;}
    else if (dir=='S'){d=S;}
    else if (dir=='E'){d=E;}
    else if (dir=='W'){d=W;}
    else {d=O;}
    for(i=0;i<6;i++){b[i]=a[d[i]];}
}

int main(void){
    int i,j,q,buf,d[6],c[6],e[6],ca[8],cb[4],fl=0;
    for(i=0;i<6;i++){scanf("%d",&e[i]);}
    for(i=0;i<6;i++){scanf("%d",&d[i]);}
    while(1){
        if (d[1]==e[0] || d[4]==e[0] || d[5]==e[0]){cpy(d,c,'O');cpy(c,d,'N');}
        else if (d[3]==e[0] || d[2]==e[0]){cpy(d,c,'O');cpy(c,d,'E');}
        else {break;}
    }
    for(i=0;i<8;i++){
        ca[i]=e[PT[i]];
        if(i<4){cb[i]=d[PT[i]];}
    }
    for(i=0;i<5;i++){
        if (ca[i]==cb[0] && ca[i+1]==cb[1] && ca[i+2]==cb[2] && ca[i+3]==cb[3]){fl=1;break;}
    }
    printf("%s\n",(fl)? "Yes":"No");
    return 0;
}