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.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        enum Directoin
        {
            N,
            E,
            W,
            S,
            U,
            D,
        }

        class Dice
        {
            private int[] nums = new int[6];
            private List<Directoin> dirs;
            public Dice(IEnumerable<int> nums)
            {
                this.nums = nums.ToArray();
                dirs = new List<Directoin>()
                {
                    Directoin.U,
                    Directoin.S,
                    Directoin.E,
                    Directoin.W,
                    Directoin.N,
                    Directoin.D,
                };
            }
            public void Roll(Directoin roll)
            {
                switch (roll)
                {
                    case Directoin.N:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    dirs[i] = Directoin.D;
                                    break;
                                case Directoin.E:
                                    break;
                                case Directoin.W:
                                    break;
                                case Directoin.S:
                                    dirs[i] = Directoin.U;
                                    break;
                                case Directoin.U:
                                    dirs[i] = Directoin.N;
                                    break;
                                case Directoin.D:
                                    dirs[i] = Directoin.S;
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    case Directoin.E:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    break;
                                case Directoin.E:
                                    dirs[i] = Directoin.D;
                                    break;
                                case Directoin.W:
                                    dirs[i] = Directoin.U;
                                    break;
                                case Directoin.S:
                                    break;
                                case Directoin.U:
                                    dirs[i] = Directoin.E;
                                    break;
                                case Directoin.D:
                                    dirs[i] = Directoin.W;
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    case Directoin.W:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    break;
                                case Directoin.E:
                                    dirs[i] = Directoin.U;
                                    break;
                                case Directoin.W:
                                    dirs[i] = Directoin.D;
                                    break;
                                case Directoin.S:
                                    break;
                                case Directoin.U:
                                    dirs[i] = Directoin.W;
                                    break;
                                case Directoin.D:
                                    dirs[i] = Directoin.E;
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    case Directoin.S:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    dirs[i] = Directoin.U;
                                    break;
                                case Directoin.E:
                                    break;
                                case Directoin.W:
                                    break;
                                case Directoin.S:
                                    dirs[i] = Directoin.D;
                                    break;
                                case Directoin.U:
                                    dirs[i] = Directoin.S;
                                    break;
                                case Directoin.D:
                                    dirs[i] = Directoin.N;
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            public void Rotate(Directoin rotate)
            {
                switch (rotate)
                {
                    case Directoin.E:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    dirs[i] = Directoin.E;
                                    break;
                                case Directoin.E:
                                    dirs[i] = Directoin.S;
                                    break;
                                case Directoin.W:
                                    dirs[i] = Directoin.N;
                                    break;
                                case Directoin.S:
                                    dirs[i] = Directoin.W;
                                    break;
                                case Directoin.U:
                                case Directoin.D:
                                default:
                                    break;
                            }
                        }
                        break;
                    case Directoin.W:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    dirs[i] = Directoin.W;
                                    break;
                                case Directoin.E:
                                    dirs[i] = Directoin.N;
                                    break;
                                case Directoin.W:
                                    dirs[i] = Directoin.S;
                                    break;
                                case Directoin.S:
                                    dirs[i] = Directoin.E;
                                    break;
                                case Directoin.U:
                                case Directoin.D:
                                default:
                                    break;
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            public int Getnum(Directoin dir)
            {
                return nums[dirs.IndexOf(dir)];
            }
            public override int GetHashCode()
            {
                var result = 17;
                foreach (var dir in Enum.GetValues(typeof(Directoin)).Cast<Directoin>())
                {
                    result = 100 * result + Getnum(dir);
                }
                return result;
            }
            public override bool Equals(object obj)
            {
                if (obj == null)
                {
                    return false;
                }
                var c = obj as Dice;
                if (c == null)
                {
                    return false;
                }
                return GetHashCode() == c.GetHashCode();
            }
        }

        static void Main(string[] args)
        {
            var nums1 = GetNumbersInt();
            var nums2 = GetNumbersInt();
            var rolls = new[]
            {
                Directoin.S,
                Directoin.S,
                Directoin.S,
                Directoin.S,
                Directoin.W,
                Directoin.W,
                Directoin.W,
            };
            var rotates = new[]
            {
                Directoin.W,
                Directoin.W,
                Directoin.W,
                Directoin.W
            };

            var dice1 = new Dice(nums1);
            var dice2 = new Dice(nums2);

            var top = dice2.Getnum(Directoin.U);
            foreach (var roll in rolls)
            {
                dice1.Roll(roll);
                if (dice1.Getnum(Directoin.U) == top)
                {
                    break;
                }
            }
            foreach (var rotate in rotates)
            {
                dice1.Rotate(rotate);
                if (dice1.Equals(dice2))
                {
                    System.Console.WriteLine("Yes");
                    return;
                }
            }

            System.Console.WriteLine("No");
        }

        //static StreamReader Console = new StreamReader("input.txt");

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static double GetDounble()
        {
            return double.Parse(Console.ReadLine().Trim());
        }

        static int[] GetNumbersInt(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static long[] GetNumbersLong(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToArray();
        }

        static double[] GetNumbersDouble(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToArray();
        }

        static string[] GetStrings(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
        }
    }
}