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: Accepted)

import java.io.*;
import java.util.*;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] in=new int[6];
        String[] input=new String[6];
        input=(br.readLine().split(" "));
        for(int i=0;i<6;i++)in[i]=Integer.parseInt(input[i]);
        Dice D1=new Dice(in);
        input=(br.readLine().split(" "));
        for(int i=0;i<6;i++)in[i]=Integer.parseInt(input[i]);
        Dice D2=new Dice(in);
        if(D1.isequal(D2))out.println("Yes");
        else out.println("No");
        out.flush();
    }
}
class Dice{
    private int[] memo=new int[6];
    private static final String equalmove="NNNNWNNNWNNNENNNENNNWNNN";
    public Dice(int[] in){
        Set(in[0],in[1],in[2],in[3],in[4],in[5]);
    }
    private void Set(int a,int b,int c,int d,int e,int f){
        memo[0]=a;memo[1]=b;memo[2]=c;memo[3]=d;memo[4]=e;memo[5]=f;
    }
    public void move(char c){
        switch(c){
            case 'W':
                Set(memo[2],memo[1],memo[5],memo[0],memo[4],memo[3]);
                break;
            case 'N':
                Set(memo[1],memo[5],memo[2],memo[3],memo[0],memo[4]);
                break;
            case 'S':
                Set(memo[4],memo[0],memo[2],memo[3],memo[5],memo[1]);
                break;
            case 'E':
                Set(memo[3],memo[1],memo[0],memo[5],memo[4],memo[2]);
                break;
            default:
                System.out.println("error");
        }
    }
    public int Get(int i){
        return memo[i];
    }
    public boolean isequal(Dice D2){
        if(D2==this)return true;
        for(int i=0;i<equalmove.length();i++){
            this.move(equalmove.charAt(i));
            boolean flag=true;
            for(int j=0;j<6;j++){
                if(this.Get(j)!=D2.Get(j)){
                    flag=false;
                    break;
                }
            }
            if(flag)return true;
        }
        return false;
    }
}