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){
		//????????????A?????¶???-------------------------
		//????????£?????????????????????
		Scanner sc  = new Scanner(System.in);
		//A????????????
		String num6A = sc.nextLine();
		//??????????????????
		Dice dice1 = new Dice(num6A);
		//????????????B?????¶???-------------------------
		//B????????????
		String num6B = sc.nextLine();
		//??????????????????
		Dice dice2 = new Dice(num6B);
//------------------------------------------------------------------------------------------------------------------------------------------------------
		//????????????A????????????-------------------------
		//?????????????????????.???????????????(??????????¨????('?????£???????????????'));
		//N??????????????????
		//dice1.Move(MoveType.getEnum('N'));


		//????????§ ????????????
		//????????????B????????????-------------------------
		//??°?????????
		//????????????A??¨????????????B???????????????
		if(dice1.CompareTo(dice2)){
			System.out.println(1);
		}else{
			System.out.println(0);
		}
		//?????¶??? ?????´???????????????
		//?????????

	}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------
/** ?§?????¨???? */
enum MoveType
{
	N,
	S,
	W,
	E,
	R,
	L;

	/**
	 * ??????????????????????§?????¨???????????????????
	 * @param c ??????????±???????
	 * @return ?§?????¨????
	 */
	public static MoveType getEnum(char c) {
		for (MoveType mt : MoveType.values()) {
			if (String.valueOf(c).equals(mt.name().toString()))
				return mt;
		}
		return null;
	}
}

/**
 * ?????????????????????
 * @author shimada
 */
class Dice {

	/**
	 * @return top
	 */
	public int getTop() {
		return Top;
	}

	/**
	 * @return front
	 */
	public int getFront() {
		return Front;
	}

	/**
	 * @return right
	 */
	public int getRight() {
		return Right;
	}

	/**
	 * @return left
	 */
	public int getLeft() {
		return Left;
	}

	/**
	 * @return back
	 */
	public int getBack() {
		return Back;
	}

	/**
	 * @return bottom
	 */
	public int getBottom() {
		return Bottom;
	}

	/** ?????¢?????? */
	private int Top = 0;
	/** ?????¢?????? */
	private int Front = 0;
	/** ?????¢?????? */
	private int Right = 0;
	/** ?????¢?????? */
	private int Left = 0;
	/** ?????¢?????? */
	private int Back = 0;
	/** ?????¢?????? */
	private int Bottom = 0;

	/**
	 * ?????????????????????
	 * @param input ?????????????????§6????????°?????????????????????????????¢?????????
	 */
	public Dice(String input) {
		String[] values = input.split(" ");

		int i = 0;
		this.Top = Integer.parseInt(values[i++]);
		this.Front = Integer.parseInt(values[i++]);
		this.Right = Integer.parseInt(values[i++]);
		this.Left = Integer.parseInt(values[i++]);
		this.Back = Integer.parseInt(values[i++]);
		this.Bottom = Integer.parseInt(values[i++]);
	}

	/**
	 * ??????????????????????????§??????????????????????????????
	 * @param cmd N/S/W/E/R/L ??????????????????????????????????????\?????????????????????
	 */
	public void Move(String cmd) {
		for (char c : cmd.toCharArray()) {
			Move(MoveType.getEnum(c));
		}
	}

	/**
	 * ????????????????§?????¨????????????????????????????
	 * @param mt ?§?????¨????
	 */
	public void Move(MoveType mt) {
		switch(mt) {
		case N: MoveN(); break;
		case S: MoveS(); break;
		case E: MoveE(); break;
		case W: MoveW(); break;
		case R: MoveR(); break;
		case L: MoveL(); break;
		}
	}

	/**
	 * ??????????????????
	 */
	private void MoveN() {
		int tmp = Top;
		Top = Front;
		Front = Bottom;
		Bottom = Back;
		Back = tmp;
	}

	/**
	 * ??????????????????
	 */
	private void MoveS() {
		int tmp = Top;
		Top = Back;
		Back = Bottom;
		Bottom = Front;
		Front = tmp;
	}

	/**
	 * ??????????????????
	 */
	private void MoveE() {
		int tmp = Top;
		Top = Left;
		Left = Bottom;
		Bottom = Right;
		Right = tmp;
	}

	/**
	 * ??????????????????
	 */
	private void MoveW() {
		int tmp = Top;
		Top = Right;
		Right = Bottom;
		Bottom = Left;
		Left = tmp;
	}

	/**
	 * ?°´???????????¢
	 */
	private void MoveR() {
		int tmp = Front;
		Front = Right;
		Right = Back;
		Back = Left;
		Left = tmp;
	}

	/**
	 * ?°´???????????¢
	 */
	private void MoveL() {
		int tmp = Front;
		Front = Left;
		Left = Back;
		Back = Right;
		Right = tmp;
	}

	/**
	 * ?????????????????????????????¨????????¢?§??????§????????????????????????
	 * @param dice ??????????±????????????????
	 * @return ??¢?§???????????????§????????°true???????????\??????false
	 */
	public boolean CompareTo(Dice dice) {
		// Top????????¢?????????????°´????????¢
		if (TopHoldCompare(dice)) return true;
		// Front????????¢?????????????°´????????¢
		MoveN();
		if (TopHoldCompare(dice)) return true;
		// Right????????¢?????????????°´????????¢
		MoveW();
		if (TopHoldCompare(dice)) return true;
		// Bottom????????¢?????????????°´????????¢
		MoveN();
		if (TopHoldCompare(dice)) return true;
		// Back????????¢?????????????°´????????¢
		MoveW();
		if (TopHoldCompare(dice)) return true;
		// Left????????¢?????????????°´????????¢
		MoveN();
		if (TopHoldCompare(dice)) return true;

		return false;
	}

	/**
	 * ????????????????????¢????????????????°´????????????4?????????????????´???????????????????????????????????????????´¢??????
	 * @param dice ??????????±????????????????
	 * @return ?????´??????????????°true???????????\??????false
	 */
	private boolean TopHoldCompare(Dice dice) {

		for (int i = 0; i < 4; i++) {
			MoveR();
			if(this.Top == dice.Top
					&& this.Front == dice.Front
					&& this.Right == dice.Right
					&& this.Left == dice.Left
					&& this.Back == dice.Back
					&& this.Bottom == dice.Bottom)
				return true;
		}

		return false;
	}
}