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

using System;

namespace Aizu
{
    class Program
    {
        static void Main(string[] args)
        {
            // Dice1を作成
            var diceValue1 = Console.ReadLine();
            var dice1 = new Dice(diceValue1);

            // Dice2を作成
            var diceValue2 = Console.ReadLine();
            var dice2 = new Dice(diceValue2);
            
            // 比較
            var ret = dice2.Judge(dice1);

            // 結果
            Console.WriteLine(ret);
        }
    }

    class Dice
    {
        public int Top { get; private set; }
        public int Bottom { get; private set; }
        public int Right { get; private set; }
        public int Left { get; private set; }
        public int Front { get; private set; }
        public int Back { get; private set; }

        public Dice(string value)
        {
            var temp = value.Split(' ');
            this.Top = int.Parse(temp[0]);
            this.Front = int.Parse(temp[1]);
            this.Right = int.Parse(temp[2]);
            this.Left = int.Parse(temp[3]);
            this.Back = int.Parse(temp[4]);
            this.Bottom = int.Parse(temp[5]);
        }
 
        /// <summary>
        /// 受け取ったダイスのTopとBottomに一致する箇所を調べその時の側面が一致するかチェックする
        /// </summary>
        /// <param name="dice">比較対象のダイス</param>
        /// <returns>True:一致, False:不一致</returns>
        public string Judge(Dice dice)
        {
            string judge = "No";
            int[] diceSide = new int[] { dice.Front, dice.Right, dice.Back, dice.Left };

            // Top, Bottom
            if (dice.Top == this.Top && dice.Bottom == this.Bottom)
            {
                int[] thisDiceSide = new int[] { this.Front, this.Right, this.Back, this.Left };
                judge = JudgeSide(diceSide, thisDiceSide);
            }

            // Bottom, Top
            if (dice.Top == this.Bottom && dice.Bottom == this.Top)
            {
                int[] thisDiceSide = new int[] { this.Front, this.Left, this.Back, this.Right };
                judge = JudgeSide(diceSide, thisDiceSide);
            }

            // Right, Left
            if (dice.Top == this.Right && dice.Bottom == this.Left)
            {
                int[] thisDiceSide = new int[] { this.Front, this.Bottom, this.Back, this.Top };
                judge = JudgeSide(diceSide, thisDiceSide);
            }

            // Left, Right
            if (dice.Top == this.Left && dice.Bottom == this.Right)
            {
                int[] thisDiceSide = new int[] { this.Front, this.Top, this.Back, this.Bottom };
                judge = JudgeSide(diceSide, thisDiceSide);
            }

            // Front, Back
            if (dice.Top == this.Front && dice.Bottom == this.Back)
            {
                int[] thisDiceSide = new int[] { this.Bottom, this.Right, this.Top, this.Left };
                judge = JudgeSide(diceSide, thisDiceSide);
            }

            // Back, Front
            if (dice.Top == this.Back && dice.Bottom == this.Front)
            {
                int[] thisDiceSide = new int[] { this.Bottom, this.Left, this.Top, this.Right };
                judge = JudgeSide(diceSide, thisDiceSide);
            }

            return judge;
        }

        public string JudgeSide(int[] diceSide, int[] thisDiceSide)
        {
            for(int ds = 0; ds < 4; ds++)
            {
                int start = 0;
                for(int tds = start; tds < 4; tds++)
                {
                    if(diceSide[ds % 4] == thisDiceSide[tds % 4] 
                        && diceSide[(ds + 1) % 4] == thisDiceSide[(tds + 1) % 4]
                        && diceSide[(ds + 2) % 4] == thisDiceSide[(tds + 2) % 4]
                        && diceSide[(ds + 3) % 4] == thisDiceSide[(tds + 3) % 4])
                    {
                        return "Yes";
                    }

                    start++;
                }
            }
            
            return "No";
        }
    }
}