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: Wrong Answer)

import java.util.Scanner;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner as = new Scanner(System.in);
		
		int dice1[];
		int dice2[];
		int Pdice1[][];
		int Pdice2[][];
		int count = 0;
		int tr = 0;
		String str = "";
		String spn = "";
		Boolean breakp = null;
		
		dice1 = new int[6];
		dice2 = new int[6];
		Pdice1 = new int[6][6];
		Pdice2 = new int[6][6];
		
		for(int i=0;i<6;i++){
			
			dice1[i] = as.nextInt();
			
		}
		
		for(int i=0;i<6;i++){
			
			dice2[i] = as.nextInt();
			
		}
		
		for(int i=0;i<3;i++){
			
			
			
			switch (i){
			case 0:
				spn = "x";
				break;
				
			case 1:
				spn = "y";
				break;
				
			case 2:
				spn = "z";
				break;
				
			}
		
			breakp = Spin.Check(dice1, dice2, i);
			
			if(breakp == true){
				
				str = "Yes";
				break;
				
			}
			
			dice2 = Spin.diceSpin(dice2, "x");
			breakp = Spin.Check(dice1, dice2, i);
			
			if(breakp == true){
				
				str = "Yes";
				break;
				
			}
			
			dice2 = Spin.diceSpin(dice2, "x");
			dice2 = Spin.diceSpin(dice2, "x");
			breakp = Spin.Check(dice1, dice2, i);
			
			if(breakp == true){
				
				str = "Yes";
				break;
				
			}
			
			dice2 = Spin.diceSpin(dice2, "z");
			dice2 = Spin.diceSpin(dice2, "x");
			dice2 = Spin.diceSpin(dice2, "x");
			breakp = Spin.Check(dice1, dice2, i);
			
			if(breakp == true){
				
				str = "Yes";
				break;
				
			}
			
			str = "No";
		
		}
		
		System.out.println(str);

	}

}


class Spin{
	
	public static int[] diceSpin(int[] dice,String spn) {
		
	
		int tre = 0;
			
			
		switch (spn){
		case "x":
			tre = dice[4];
			dice[4] = dice[0];
			dice[0] = dice[1];
			dice[1] = dice[5];
			dice[5] = tre;
			break;
			
		case "y":
			tre = dice[3];
			dice[3] = dice[0];
			dice[0] = dice[2];
			dice[2] = dice[5];
			dice[5] = tre;
			break;
			
		case "z":
			tre = dice[2];
			dice[2] = dice[1];
			dice[1] = dice[3];
			dice[3] = dice[4];
			dice[4] = tre;
			break;
			
				
		}
			
		
			
		return dice;
		
		
		
	  }
	
	public static Boolean Samecheck(int[] dice1,int[] dice2){
		
		Boolean flag = null;
		
		for(int i=0;i<6;i++){
			
			if(dice1[i] != dice2[i]){
				
				flag = false;
				break;
			}
			else{
				
				flag = true;
				
			}
			
		}
		
		
		return flag;
		
	}
	
	public static Boolean Check(int[] dice1,int[] dice2,int sp){
		
		Boolean flag = null;
		String spn = null;
		
		switch (sp){
		case 0:
			spn = "x";
			break;
			
		case 1:
			spn = "y";
			break;
			
		case 2:
			spn = "z";
			break;
			
		}
		
		for(int j=0;j<4;j++){
			
			
			dice2 = Spin.diceSpin(dice2, spn);
			if(Spin.Samecheck(dice1, dice2)){
				
	
				flag = true;
				break;
			
			}
			flag = false;
			
		}
		
		
		return flag;
		
	}
	
	
	
}