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

namespace ITP1_11_C
{
    class Dice
    {
        int[] srf_current;
        int[] srf_first;

        public Dice(int[] x) { srf_current = srf_first = x; }

        public int this[int index]
        {
            get { return srf_current[index]; }
            set { srf_current[index] = value; }
        }

        public void turn(char vct)
        {
            int[] sub = new int[6];

            for (int i = 0; i < 6; i++)
                sub[i] = srf_current[i];

            switch (vct)
            {
                case 'S':
                    srf_current[0] = sub[4];
                    srf_current[1] = sub[0];
                    srf_current[5] = sub[1];
                    srf_current[4] = sub[5];
                    break;
                case 'N':
                    srf_current[0] = sub[1];
                    srf_current[1] = sub[5];
                    srf_current[5] = sub[4];
                    srf_current[4] = sub[0];
                    break;
                case 'W':
                    srf_current[0] = sub[2];
                    srf_current[2] = sub[5];
                    srf_current[5] = sub[3];
                    srf_current[3] = sub[0];
                    break;
                case 'E':
                    srf_current[0] = sub[3];
                    srf_current[2] = sub[0];
                    srf_current[5] = sub[2];
                    srf_current[3] = sub[5];
                    break;
                default:
                    break;
            }
            //foreach (var s in srf_current)
            //    Console.Write(" " + s);
            //Console.WriteLine();
        }

        public void upturn(int top)
        {
            if (srf_current[0] != top)
            {
                if (srf_current[1] == top) turn('N');
                else if (srf_current[4] == top) turn('S');
                else
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (srf_current[0] == top) break;
                        else turn('E');
                    }
                }
            }
        }

        public int findnum(int found)
        {
            int ret = 0;
            foreach (var s in srf_current)
                if (s == found) ret++;
            return ret;
        }

        public int findStat(int top, int front)
        {
            upturn(top);
            if (srf_current[1] == front) return srf_current[2];
            else if (srf_current[2] == front) return srf_current[4];
            else if (srf_current[4] == front) return srf_current[3];
            else return srf_current[1];
        }

        public void reset()
        {
            for (int i = 0; i < 6; i++)
                srf_current[i] = srf_first[i];
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            Dice diceA = new Dice(Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray());
            Dice diceB = new Dice(Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray());
            bool isEqual = false;

            for(int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; diceA[k] == diceB[k]; k++)
                    {
                        if (k == 5)
                        {
                            isEqual = true;
                            break;
                        }
                    }
                    if (isEqual) break;
                    else diceB.turn('E');   
                }
                if (isEqual) break;
                else diceB.turn('S');
            }
            
            //if (diceB.findnum(diceA[0]) != 0)
            //{
            //    diceB.upturn(diceA[0]);

            //    for (int i = 1; i < 6; i++)
            //        if (diceB[i] != diceA[i])
            //        {
            //            isEqual = false;
            //            break;
            //        }
            //}
            //else isEqual = false;

            if (isEqual) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}