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 JAVA (judge verdict: Accepted)

import java.util.Scanner;
import java.util.Arrays;

class Main{
       public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	Dice dice1 = new Dice();
    	Dice dice2 = new Dice();
    	for(int i = 0; i < 6; i++){
    		dice1.inputSurface(i , scan.nextInt());
    	}
    	for(int i = 0; i < 6; i++){
    		dice2.inputSurface(i , scan.nextInt());
    	}
    	
    	int top = dice2.getSurface(0);
    	int front = dice2.getSurface(1);
    	int i;
    	
    	for(i = 0; i < 6; i++){
    		if(dice1.getSurface(i) == top){
    			dice1.setTop(top);
    			
    			for(i = 1; i < 5; i++){
    				if(dice1.getSurface(i) == front){
    					dice1.setFront(front);
    					if(Arrays.equals(dice1.getSurfaceAll(), dice2.getSurfaceAll())){
    						System.out.println("Yes");
    						return;
    					}
    				}
    			}
    			break;
    		}
    	}
    	System.out.println("No");
     }
}

/*
????????????:Dice
?????? ?????????????????¢?????????????????????
	 ?????¢???????????????
*/
class Dice{
	private int[] surface = new int[6];
	
	public void inputSurface(int c, int x){
		surface[c] = x;
	}
	
	public void spin(char order){
		int buf;
		//???????????????????????¢?????£????????????surface?????\????????????
		switch(order){
			case 'N':{
				buf = surface[0];
				surface[0] = surface[1];
				surface[1] = surface[5];
				surface[5] = surface[4];
				surface[4] = buf;
				break;
			}
			case 'E':{
    			buf = surface[0];
    			surface[0] = surface[3];
    			surface[3] = surface[5];
    			surface[5] = surface[2];
    			surface[2] = buf;
    			break;
			}
			case 'W':{
				buf = surface[0];
    			surface[0] = surface[2];
    			surface[2] = surface[5];
    			surface[5] = surface[3];
    			surface[3] = buf;
    			break;
			}
			case 'S':{
				buf = surface[0];
    			surface[0] = surface[4];
    			surface[4] = surface[5];
    			surface[5] = surface[1];
    			surface[1] = buf;
    			break;
			}
		}
	}
	
	public void setTop(int top){
		if(top == surface[1]){
			this.spin('N');
		}else if(top == surface[2]){
			this.spin('W');
		}else if(top == surface[3]){
			this.spin('E');
		}else if(top == surface[4]){
			this.spin('S');
		}else if(top == surface[5]){
			this.spin('N');
			this.spin('N');
		}
	}
	
	public void setFront(int front){
		int temp;
		if(front == surface[2]){
			temp = surface[1];
			surface[1] = surface[2];
			surface[2] = surface[4];
			surface[4] = surface[3];
			surface[3] = temp;
		}else if(front == surface[3]){
			temp = surface[1];
			surface[1] = surface[3];
			surface[3] = surface[4];
			surface[4] = surface[2];
			surface[2] = temp;
		}else if(front == surface[4]){
			temp = surface[1];
			surface[1] = surface[4];
			surface[4] = temp;
			temp = surface[2];
			surface[2] = surface[3];
			surface[3] = temp;
		}
	}
	
	public int getSurface(int num){
		return surface[num];
	}
	
	public int[] getSurfaceAll(){
		return surface;
	}
}