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;

public class Main {
	//
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc  = new Scanner(System.in);
//------------------------------------------------------------------------------------------------------------------------------------------------------
		//????????????A
		//????????????
		String num6A = sc.nextLine();
		//??????????????????
		Dice dice1 = new Dice(num6A);

//------------------------------------------------------------------------------------------------------------------------------------------------------
		//????????????B
		//????????????
		String num6B = sc.nextLine();
		//??????????????????
		Dice dice2 = new Dice(num6B);

//------------------------------------------------------------------------------------------------------------------------------------------------------
		//???????????¨???
		//????????????A??¨????????????B???????????????
		if(directionCheck(dice1,dice2)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
//------------------------------------------------------------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------------------------------------------------------------
	//???????????????
	public static boolean directionCheck(Dice dice1, Dice dice2) {
		//???????????????????????????????????°
		char action = 'a';
		//??£?¨?
		boolean flag = false;
		//??????4????????????
		for(int i = 0; i<4; i++){
				//????????????1??¨????????????2????????§????????????
				if(rightCheck(dice1,dice2)){
					flag = true;
					break;
				}else{
					action ='N';
					dice2.roll(action);
					flag = false;
				}
			}
		//??±???4????????????
		for(int j = 0; j<4; j++){
			//????????????1??¨????????????2????????§????????????
			if(rightCheck(dice1,dice2)){
				flag = true;
				break;
			}else{
				action ='W';
				dice2.roll(action);
				flag = false;
			}
		}
		return flag;
	}
	//------------------------------------------------------------------------------------------------------------------------------------------------------
	public static boolean rightCheck(Dice dice1, Dice dice2) {
		//?????£??????????¨????
		char action = 'a';
		//????????????false????¨????
		boolean flag = false;
		//??????????????????
		for(int i = 0; i<4;i++){
			//?????¶??? dice1????????¨dice2???????????????OK
			if(allCheck(dice1,dice2)){
				flag = true;
				break;
			}else{
				action ='R';
				dice2.roll(action);
				flag = false;
			}
		}
		return flag;
	}
	//------------------------------------------------------------------------------------------------------------------------------------------------------
	private static boolean allCheck(Dice dice1, Dice dice2) {
		//??¨?????????????????§???????????? ??¨????????¢?????????????????°true
		boolean flag = false;
		if( dice1.getNum(0) == dice2.getNum(0) && dice1.getNum(1) == dice2.getNum(1) && dice1.getNum(2) == dice2.getNum(2)
		&&dice1.getNum(3) == dice2.getNum(3) && dice1.getNum(4) == dice2.getNum(4) && dice1.getNum(5) == dice2.getNum(5)){
			 flag = true;
		}
		return flag;
	}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------
class Dice{
	//??????????????¶???
	//?????£?????????
	int [] num = new int[6];
	//?????????????????????
	Dice (String numbers ){
		String[]  A = numbers.split(" ");
		//???????????????????????\???
		for(int i = 0; i<4; i++){
			this.num[i] = Integer.parseInt(A[i]);
		}
	}
//------------------------------------------------------------------------------------------------------------------------------------------------------
//???????????????????????????????????????
public  int  getNum( int  i){

	return num[i];

}
//------------------------------------------------------------------------------------------------------------------------------------------------------
//roll????????????  ????§? ???????????????
	void  roll(char  action){
		//?????????????????¢??????
		int temp;
		switch(action){
			case'N':	//???
				temp = num[0];
				num[0]= num[1];
				num[1]=num[5];
				num[5]= num[4];
				num[4] = temp;
				break;
			case'W':	//??±
				temp = num[0];
				num[0]= num[2];
				num[2]= num[5];
				num[5]= num[3];
				num[3]= temp;
				break;
			case'E':	//?\?
				temp = num[0];
				num[0]= num[3];
				num[3]= num[5];
				num[5]= num[2];
				num[2]= temp;
				break;
			case'S':	//???
				temp = num[0];
				num[0]= num[4];
				num[4]= num[5];
				num[5]= num[1];
				num[1]= temp;
				break;
			case'L':	//???
				temp = num[1];
				num[1]= num[3];
				num[3]= num[4];
				num[4]= num[2];
				num[2]= temp;
				break;
			case'R':	//???
				temp = num[1];
				num[1]= num[2];
				num[2]= num[4];
				num[4]= num[3];
				num[3]= temp;
				break;
		}
	}
}