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 C# (judge verdict: Runtime Error)

using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program{
    static void Main(){
        int[] inputs = Console.ReadLine().Split(' ')
                                         .Select(val => int.Parse(val))
                                         .ToArray();
        Dice dc1 = new Dice(inputs);
        inputs = Console.ReadLine().Split(' ')
                                   .Select(val => int.Parse(val))
                                   .ToArray();
        Dice dc2 = new Dice(inputs);
        Console.WriteLine(dc1.Equals(dc2) ? "Yes" : "No");
    }

    class Dice
    {
        const int NumOfFace = 6;
        public int[] rables {get; set;}
        //[0]???[1]??????[2]???[3]???[4]?\\[5]???
        //[5 - index]??§????????´?????????
        public Dice(int[] iarr){
            rables = new int[NumOfFace];
            Array.Copy(iarr, 0, this.rables, 0, iarr.Length);
        }

        public int IndexOf(int num){
            for (int i = 0; i < rables.Length; i++)
            {
                if(rables[i] == num) return i;
            }
            return -1;
        }

        public void Rotate(int top, int front){
            char firstOrder = 'N';
            if(new int[]{2, 3}.Contains(this.IndexOf(top))) firstOrder = 'W';
            while(this.rables[0] != top) this.Move(firstOrder);
            while(this.rables[1] != front) this.Move('R');
        }

        public bool Equals(Dice dice){
            int[] thisDiceNumber = new int[NumOfFace];
            Array.Copy(this.rables, 0, thisDiceNumber, 0, NumOfFace);
            int[] comparedDiceNumber = new int[NumOfFace];
            Array.Copy(dice.rables, 0, comparedDiceNumber, 0, NumOfFace);
            int top1 = thisDiceNumber.Min();
            int front1 = thisDiceNumber.Where((val, idx) => val != top1 && idx != NumOfFace - 1 - Array.IndexOf(thisDiceNumber, top1))
                                       .OrderBy(val => val)
                                       .Min();
            int top2 = comparedDiceNumber.Min();
            int front2 = comparedDiceNumber.Where((val, idx) => val != top2 && idx != NumOfFace - 1 - Array.IndexOf(comparedDiceNumber, top2))
                                           .OrderBy(val => val)
                                           .Min();
            if(top1 != top2 || front1 != front2) return false;
            Dice thisDice = new Dice(thisDiceNumber);
            thisDice.Rotate(top1, front1);
            Dice comparedDice = new Dice(comparedDiceNumber);
            comparedDice.Rotate(top2, front2);
            return thisDice.rables.SequenceEqual(comparedDice.rables);
        }

        public void Move(char direction){
            int tmp;
            switch (direction)
            {
                case 'N':   //?\\??????
                    tmp = rables[0];
                    rables[0] = rables[1];
                    rables[1] = rables[5];
                    rables[5] = rables[4];
                    rables[4] = tmp;
                    break;
                case 'W':   //?????????
                    tmp = rables[0];
                    rables[0] = rables[2];
                    rables[2] = rables[5];
                    rables[5] = rables[3];
                    rables[3] = tmp;
                    break;
                case 'S':   //?????????
                    tmp = rables[0];
                    rables[0] = rables[4];
                    rables[4] = rables[5];
                    rables[5] = rables[1];
                    rables[1] = tmp;
                    break;
                case 'E':   //?????????
                    tmp = rables[0];
                    rables[0] = rables[3];
                    rables[3] = rables[5];
                    rables[5] = rables[2];
                    rables[2] = tmp;
                    break;
                default:
                    tmp = rables[1];
                    rables[1] = rables[2];
                    rables[2] = rables[4];
                    rables[4] = rables[3];
                    rables[3] = tmp;
                    break;
            }
        }
    }
}