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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//      ????????????????????????????????¢?????°??????????????????dice???????????????????????£??\
        String str1 = br.readLine();
        Dice dice1 = new Dice(str1);
//      ????????????????????????????????¢?????°??????????????????dice???????????????????????£??\
        String str2 = br.readLine();
        Dice dice2 = new Dice(str2);

        int i;
        boolean judge = false;

//      ???????????????????????????getNum(0)??¨????????°?????????????????????????????????????????????i?????????????¢????
        for(i = 0; i < str1.length(); i++){
            if(dice1.getNum(0).equals(dice2.getNum(i))){
                break;
            }
        }

//      ??????????????????????????¨??????????????????????????§??¢??????
        switch(i){

        case 0:
            break;

        case 1:
            dice2.moveN();
            break;

        case 2:
            dice2.moveW();
            break;

        case 3:
            dice2.moveE();
            break;

        case 4:
            dice2.moveS();
            break;

        case 5:
            dice2.moveN();
            dice2.moveN();
            break;
        }
//      ???????????????????????????getNum(1)??¨????????°?????????????????????????????????????????????i?????????????¢????
        for(i = 1; i < str1.length() - 1; i++){
            if(dice1.getNum(1).equals(dice2.getNum(i))){
                break;
            }
        }
        switch(i){
        case 1:
            if(dice1.getNum(2).equals(dice2.getNum(2)) &&
                dice1.getNum(3).equals(dice2.getNum(3)) &&
                dice1.getNum(4).equals(dice2.getNum(4)) &&
                dice1.getNum(5).equals(dice2.getNum(5))){

                judge = true;
            }
        case 2:
            if(dice1.getNum(2).equals(dice2.getNum(4)) &&
                dice1.getNum(3).equals(dice2.getNum(1)) &&
                dice1.getNum(4).equals(dice2.getNum(3)) &&
                dice1.getNum(5).equals(dice2.getNum(5))){

                judge = true;
            }
        case 3:
            if(dice1.getNum(2).equals(dice2.getNum(1)) &&
                dice1.getNum(3).equals(dice2.getNum(4)) &&
                dice1.getNum(4).equals(dice2.getNum(2)) &&
                dice1.getNum(5).equals(dice2.getNum(5))){

                judge = true;
            }
        case 4:
            if(dice1.getNum(2).equals(dice2.getNum(3)) &&
                dice1.getNum(3).equals(dice2.getNum(2)) &&
                dice1.getNum(4).equals(dice2.getNum(1)) &&
                dice1.getNum(5).equals(dice2.getNum(5))){

                judge = true;
            }
        }

        if(judge){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

class Dice{
    private String[] str;
    private String tmp;

    Dice(String str){
        this.str = new String[6];
        this.str = str.split(" ");
    }
    public String getNum(int n){
        return this.str[n];

    }
    public void moveE(){
        tmp = this.str[0];
        this.str[0] = this.str[3];
        this.str[3] = this.str[5];
        this.str[5] = this.str[2];
        this.str[2] = tmp;
    }
    public void moveN(){
        tmp = this.str[0];
        this.str[0] = this.str[1];
        this.str[1] = this.str[5];
        this.str[5] = this.str[4];
        this.str[4] = tmp;
    }
    public void moveS(){
        tmp = this.str[0];
        this.str[0] = this.str[4];
        this.str[4] = this.str[5];
        this.str[5] = this.str[1];
        this.str[1] = tmp;
    }
    public void moveW(){
        tmp = this.str[0];
        this.str[0] = this.str[2];
        this.str[2] = this.str[5];
        this.str[5] = this.str[3];
        this.str[3] = tmp;
    }
}