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.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		int[] num = new int[Dice.SURFACE];

		for(int i = 0; i < input.length; i++){
			num[i] = Integer.parseInt(input[i]);
		}

		Dice dice_1 = new Dice(num);
		input = br.readLine().split(" ");

		for(int i = 0; i < input.length; i++){
			num[i] = Integer.parseInt(input[i]);
		}

		Dice dice_2 = new Dice(num);

		if(dice_1.equals(dice_2)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}
}

class Dice{

	static final int SURFACE = 6;
	static final int TOP = 1;
	static final int FRONT = 2;
	static final int RIGHT = 3;
	static final int LEFT = 4;
	static final int REAR = 5;
	static final int BOTTOM = 6;
	private int[] num = new int[SURFACE];

	public Dice(int[] set){

		for(int i = 0; i < SURFACE; i++){
			num[i] = set[i];
		}

	}

	public int getNum(int rabel){

		return num[rabel - 1];

	}

	public int getRabel(int n){

		for(int i = 0; i < SURFACE; i++){

			if(n == num[i]){
				return i + 1;
			}

		}

		return -1;

	}

	public void moveE(){

		int temp = num[0];
		num[0] = num[3];
		num[3] = num[5];
		num[5] = num[2];
		num[2] = temp;

	}

	public void moveN(){

		int temp = num[0];
		num[0] = num[1];
		num[1] = num[5];
		num[5] = num[4];
		num[4] = temp;

	}

	public void moveS(){

		int temp = num[0];
		num[0] = num[4];
		num[4] = num[5];
		num[5] = num[1];
		num[1] = temp;

	}

	public void moveW(){

		int temp = num[0];
		num[0] = num[2];
		num[2] = num[5];
		num[5] = num[3];
		num[3] = temp;

	}

	public void spinL(){

		int temp = num[1];
		num[1] = num[2];
		num[2] = num[4];
		num[4] = num[3];
		num[3] = temp;

	}

	public void spinR(){

		int temp = num[1];
		num[1] = num[3];
		num[3] = num[4];
		num[4] = num[2];
		num[2] = temp;

	}

	public void fixing(int top, int front){

		switch(getRabel(top)){
			case 2:
				moveN();
				break;
			case 3:
				moveW();
				break;
			case 4:
				moveE();
				break;
			case 5:
				moveS();
				break;
			case 6:
				moveN();
				moveN();
				break;
		}

		switch(getRabel(front)){
			case 3:
				spinL();
				break;
			case 4:
				spinR();
				break;
			case 5:
				spinR();
				spinR();
				break;
		}

	}

	public boolean equals(Dice another){

		another.fixing(num[0], num[1]);

		for(int i = 0; i < SURFACE; i++){

			if(num[i] != another.getNum(i + 1)){
				return false;
			}

		}

		return true;

	}

}