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: Wrong Answer)

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";
            if (diceA.Top != diceB.Top)
            {
                if (diceA.Top == diceB.Front) diceB.RollY(true);
                else if (diceA.Top == diceB.Rear) diceB.RollY(false);
                else if (diceA.Top == diceB.Left) diceB.RollZ(true);
                else if (diceA.Top == diceB.Right) diceB.RollZ(false);
                else if (diceA.Top == diceB.Bottom)  
                {
                    diceB.RollZ(true);
                    diceB.RollZ(true);
                }
                else
                {
                    Console.WriteLine(No);
                    return;
                }
            }
            if (diceA.Front != diceB.Front)
            {
                if (diceA.Front == diceB.Right) diceB.RollX(false);
                else if (diceA.Front == diceB.Left) diceB.RollX(true);
                else if (diceA.Front == diceB.Rear)
                {
                    diceB.RollX(true);
                    diceB.RollX(true);
                }
                else
                {
                    Console.WriteLine(No);
                    return;
                }
            }

            if (diceA.Left != diceB.Left) Console.WriteLine(No);
            else if (diceA.Right != diceB.Right) Console.WriteLine(No);
            else if (diceA.Bottom != diceB.Bottom) Console.WriteLine(No);
            else if (diceA.Rear != diceB.Rear) Console.WriteLine(No);
            else
            {
                Console.WriteLine(Yes);
            }
        }
    }

    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;
            }
        }
    }
}