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>
#include<string.h>
int main(void){
    int i,u,y,e=0,g,m=0,q,z=0,de,r[3][6]={0},f[2][6]={0};
	    for(i=0;i<6;i++){
	    	scanf("%d",&r[0][i]);
	    }
	     for(i=0;i<6;i++){
	    	scanf("%d",&r[1][i]);
	    }
    for(de=0;de<2;de++){
	    memcpy(f[de],r[de],6);
    }
   de=0;
	    for(g=0;g<1000;g++){
	    	while(r[de][0]!=r[1][0]){
		    	r[3][1]=r[de][0];
		    	r[de][0]=r[de][4];
		    	r[de][4]=r[de][5];
		    	r[de][5]=r[de][1];
		    	r[de][1]=r[3][1];
		    	m++;
		    	if(m==7){
		    		break;
		    	}
	    	}
	  	  while(r[de][1]!=r[1][1]){
		    	r[3][1]=r[de][1];
		    	r[de][1]=r[de][2];
		    	r[de][2]=r[de][4];
		    	r[de][4]=r[de][3];
		    	r[de][3]=r[3][1];
		    	if(m==7){
		    		while(r[de][0]!=r[1][0]){
		    	r[3][1]=r[de][0];
		    	r[de][0]=r[de][4];
		    	r[de][4]=r[de][5];
		    	r[de][5]=r[de][1];
		    	r[de][1]=r[3][1];
		    		}
		    	}
	   	 }
	    }
    
   
	if(r[0][0]==r[1][0]&&r[0][1]==r[1][1]&&r[0][2]==r[1][2]&&r[0][3]==r[1][3]&&r[0][4]==r[1][4]&&r[0][5]==r[1][5])
	{
		printf("Yes\n");
	}else{
		printf("No\n");
	}
    return 0;
}