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.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class Main {
    public static void main(String[] args) throws Exception {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");

        int[] data = new int[line.length];
        for (int i = 0; i < data.length; i++) {
        	data[i] = Integer.parseInt(line[i]);
		}
        Dice dice1 = new Dice(data);


        line = br.readLine().split(" ");

        data = new int[line.length];
        for (int i = 0; i < data.length; i++) {
        	data[i] = Integer.parseInt(line[i]);
		}
        Dice dice2 = new Dice(data);


        String[] topPosList = dice2.getPosList(dice1.getData("top"));
        for (int i = 0; i < topPosList.length; i++) {
        	dice2.moveToTop(topPosList[i]);

        	String[] frontPosList = dice2.getPosList(dice1.getData("front"));
        	for (int j = 0; j < frontPosList.length; j++) {
            	dice2.moveToFront(frontPosList[i]);

                if (dice1.getAllData().equals(dice2.getAllData())) {
                	continue;
                } else {
                	System.out.println("No");
                	return;
                }

        	}
        }
        System.out.println("Yes");
    }
}

class Dice {
	HashMap<String, Integer> pos;
	Dice(int[] data) {
		pos = new HashMap<String, Integer>();
		pos.put("top"   , data[1 - 1]);
		pos.put("bottom", data[6 - 1]);
		pos.put("left"  , data[4 - 1]);
		pos.put("right" , data[3 - 1]);
		pos.put("front" , data[2 - 1]);
		pos.put("back"  , data[5 - 1]);
	}

	public String[] getPosList(int data) {
		List<String> posList = new ArrayList<String>();
		Iterator<HashMap.Entry<String, Integer>> ite = pos.entrySet().iterator();
		while(ite.hasNext()) {
            Map.Entry<String, Integer> entry = ite.next();

			if (data == entry.getValue()) {
				posList.add(entry.getKey());
			}
		}

		return posList.toArray(new String[posList.size()]);
	}

	public void moveToTop(String currentPos) {
		switch (currentPos) {
		case "top":
			break;

		case "bottom":
			roll('S');
			roll('S');
			break;

		case "left":
			roll('E');
			break;

		case "right":
			roll('W');
			break;

		case "front":
			roll('N');
			break;

		case "back":
			roll('S');
			break;
		}
	}

	public void moveToFront(String currentPos) {
		switch (currentPos) {
		case "front":
			break;

		case "bottom":
			break;

		case "right":
			spin('R');
			break;

		case "left":
			spin('L');
			break;

		case "back":
			spin('L');
			spin('L');
			break;
		}
	}

	public void roll(char m) {
		int temp = -1;
		switch (m) {
		case 'N':
			temp = pos.get("top");
			pos.put("top"   , pos.get("front"));
			pos.put("front" , pos.get("bottom"));
			pos.put("bottom", pos.get("back"));
			pos.put("back"  , temp);

			break;

		case 'E':
			temp = pos.get("top");
			pos.put("top"    , pos.get("left"));
			pos.put("left"   , pos.get("bottom"));
			pos.put("bottom" , pos.get("right"));
			pos.put("right"  , temp);

			break;

		case 'W':
			temp = pos.get("top");
			pos.put("top"    , pos.get("right"));
			pos.put("right"  , pos.get("bottom"));
			pos.put("bottom" , pos.get("left"));
			pos.put("left"   , temp);

			break;

		case 'S':
			temp = pos.get("top");
			pos.put("top"    , pos.get("back"));
			pos.put("back"   , pos.get("bottom"));
			pos.put("bottom" , pos.get("front"));
			pos.put("front"  , temp);

			break;
		}
	}

	public void spin(char t) {
		int temp = -1;
		switch (t) {
		case 'L':
			temp = pos.get("front");
			pos.put("front" , pos.get("left"));
			pos.put("left"  , pos.get("back"));
			pos.put("back"  , pos.get("right"));
			pos.put("right" , temp);

			break;

		case 'R':
			temp = pos.get("front");
			pos.put("front" , pos.get("right"));
			pos.put("right" , pos.get("back"));
			pos.put("back"  , pos.get("left"));
			pos.put("left"  , temp);

			break;
		}
	}

	public int getData(String p) {
		return pos.get(p);
	}

	public String getAllData() {
		StringBuilder sb = new StringBuilder();
		sb.append(pos.get("top")).append(" ");
		sb.append(pos.get("bottom")).append(" ");
		sb.append(pos.get("left")).append(" ");
		sb.append(pos.get("right")).append(" ");
		sb.append(pos.get("front")).append(" ");
		sb.append(pos.get("back"));

		return sb.toString();
	}
}