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 Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var labelsA = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            var labelsB = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            var diceA = new Dice(labelsA);
            var diceB = new Dice(labelsB);
            const string Yes = "Yes";
            const string No = "No";
            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 4; y++)
                {
                    for (int z = 0; z < 4; z++)
                    {
                        if (IsEqualDice(diceA, diceB))
                        {
                            Console.WriteLine(Yes);
                            return;
                        }
                        diceB.RollZ(true);
                    }
                    diceB.RollY(true);
                }
                diceB.RollX(true);
            }
            Console.WriteLine(No);
        }

        private static bool IsEqualDice(Dice diceA, Dice diceB)
        {
            if (diceA.Front != diceB.Front) return false;
            else if (diceA.Bottom != diceB.Bottom) return false;
            else if (diceA.Right != diceB.Right) return false;
            else if (diceA.Left != diceB.Left) return false;
            else if (diceA.Top != diceB.Top) return false;
            else if (diceA.Rear != diceB.Rear) return false;
            else return true;
        }
        
    }

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

        public Dice(int[] label)
        {
            Front = label[0];
            Bottom = label[1];
            Right = label[2];
            Left = label[3];
            Top = label[4];
            Rear = label[5];
        }

        public void RollX(bool direction)
        {
            var temp = 0;
            if (direction)
            {
                temp = Front;
                Front = Left;
                Left = Rear;
                Rear = Right;
                Right = temp;
            }
            else
            {
                temp = Front;
                Front = Right;
                Right = Rear;
                Rear = Left;
                Left = temp;
            }
        }
        public void RollY(bool direction)
        {
            var temp = 0;
            if (direction)
            {
                temp = Front;
                Front = Bottom;
                Bottom = Rear;
                Rear = Top;
                Top = temp;
            }
            else
            {
                temp = Front;
                Front = Top;
                Top = Rear;
                Rear = Bottom;
                Bottom = temp;
            }
        }
        public void RollZ(bool direction)
        {
            var temp = 0;
            if (direction)
            {
                temp = Top;
                Top = Left;
                Left = Bottom;
                Bottom = Right;
                Right = temp;
            }
            else
            {
                temp = Top;
                Top = Right;
                Right = Bottom;
                Bottom = Left;
                Left = temp;
            }
        }
    }
}