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;

class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] N = new int[6];
		for(int i=0;i<6;i++)N[i]=Integer.parseInt(sc.next());
		Dice dice1 = new Dice(N);
		for(int i=0;i<6;i++)N[i]=Integer.parseInt(sc.next());
		Dice dice2 = new Dice(N);
		//String order = sc.next();
		//char[] charOrder = order.toCharArray();
		
		
		
			System.out.println(dice1.equals(dice2)?"Yes":"No");
		
		sc.close();
	}

}

class Dice{
	private int[] roll=new int[6];
	private int[] nowRoll= new int[6];
	Dice(int[] N){
		for(int i = 0;i<6;i++){
			this.roll[i]=N[i];
			this.nowRoll[i]=N[i];
		}
	}

	public int getRoll(int i){
		return nowRoll[i];
	}

	public void roll(char c){
		//int dir;
		int[] tmpRoll=new int[6];
		for(int i=0;i<6;i++)tmpRoll[i]=this.nowRoll[i];
		int[][] mapRoll={{3,1,0,5,4,2},{1,5,2,3,0,4},{4,0,2,3,5,1},{2,1,5,0,4,3},{0,2,4,3,1,5},{0,3,1,4,2,5},{5,1,3,2,4,0}};
		int dir=0;
		if(c=='E') dir=0;
		if(c=='N') dir=1;
		if(c=='S') dir=2;
		if(c=='W') dir=3;
		if(c=='R') dir=4;
		if(c=='L') dir=5;
		if(c=='X') dir=6;
		
		for(int i=0;i<6;i++)this.nowRoll[i]=tmpRoll[mapRoll[dir][i]];
	}
	public int getRightRoll(int roll,int front){
		int[][] a={{-1,2,4,1,3,-1},{3,-1,0,5,-1,2},{1,5,-1,-1,0,4},{4,0,-1,-1,5,1},{2,-1,5,0,-1,3},{-1,3,1,4,2,-1}};
		int r=a[roll][front];
		return this.nowRoll[r];
	}
	public boolean equals(Dice d){
		int[] N= new int[6];
		for(int i=0;i<6;i++) N[i]=d.getRoll(i);
		Dice d1 = new Dice(N);
		String order=new String("RRRERRRERRREERRRWRRRWRRRX");
		boolean bool=false;
		
		for(char c: order.toCharArray()){
			boolean eachBool=true;
			for(int i=0;i<6;i++) eachBool=eachBool&&(this.getRoll(i)==d1.getRoll(i));
			d1.roll(c);
			bool=bool||eachBool;
		}	
		return bool;
	}
}