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;
using System.Linq;

namespace Structure_and_Class
{
    class Dice_III
    {
        static void Main(string[] args)
        {
            var diceA = new Dice3(Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray());
            var diceB = new Dice3(Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray());
            if (diceA.IsEqual(diceB)) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }

    public class Dice3
    {
        public int[] label = new int[6];

        public Dice3(int[] label)
        {
            this.label = label;
        }

        public bool IsEqual(Dice3 diceB)
        {
            if (RotaetCheck(diceB)) return true;
            diceB.Move('N');
            if (RotaetCheck(diceB)) return true;
            diceB.Move('N');
            if (RotaetCheck(diceB)) return true;
            diceB.Move('E');
            if (RotaetCheck(diceB)) return true;
            diceB.Move('N');
            if (RotaetCheck(diceB)) return true;
            diceB.Move('N');
            if (RotaetCheck(diceB)) return true;

            return false;
        }

        private bool RotaetCheck(Dice3 diceB)
        {
            for (int i = 0; i < 4; i++)
            {
                diceB.Rotate();
                if (label.SequenceEqual(diceB.label)) return true;
            }
            return false;
        }

        public void Move(char c)
        {
            int[] res = new int[6];
            switch (c)
            {
                case 'E':
                    res[0] = label[3];
                    res[1] = label[1];
                    res[2] = label[0];
                    res[3] = label[5];
                    res[4] = label[4];
                    res[5] = label[2];
                    label = res;
                    break;
                case 'N':
                    res[0] = label[1];
                    res[1] = label[5];
                    res[2] = label[2];
                    res[3] = label[3];
                    res[4] = label[0];
                    res[5] = label[4];
                    label = res;
                    break;
                case 'S':
                    Move('N');
                    Move('N');
                    Move('N');
                    break;
                case 'W':
                    Move('E');
                    Move('E');
                    Move('E');
                    break;
            }
        }

        public void Rotate()
        {
            int[] res = new int[6];
            res[0] = label[0];
            res[1] = label[3];
            res[2] = label[1];
            res[3] = label[4];
            res[4] = label[2];
            res[5] = label[5];
            label = res;
        }
    }
}