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 ITP1_11_C
{
    class Dice
    {
        //static int count = 0;
        int[] srf_current = new int[6];
        int[] srf_first = new int[6];

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

        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;
            }
            //count++;
            //foreach (var s in srf_current)
            //    Console.Write(" " + s);
            //Console.WriteLine("  " + count + " " + vct);
        }

        //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++)
        //            {
        //                turn('E');
        //                if (srf_current[0] == top) break;
        //            }
        //        }
        //    }
        //}

        //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()
        {
            //Console.WriteLine("reset");
            for (int i = 0; i < 6; i++)
            {
                srf_current[i] = srf_first[i];
                //Console.Write(" " + srf_current[i]);
            }
            //Console.WriteLine();      
        }
    }


    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 < 4; i++)
            {
                isEqual = checkD(diceB, diceA);
                if (isEqual || i == 3) break;
                else
                {
                    diceB.reset();
                    for(int l = 0; l <= i; l++) diceB.turn('S');
                } 
            }
            if (!isEqual)
            {
                diceB.reset();
                diceB.turn('E');
                diceB.turn('N');
                diceB.turn('W');
                isEqual = checkD(diceB, diceA);
            }
            if(!isEqual)
            {
                diceB.reset();
                diceB.turn('W');
                diceB.turn('N');
                diceB.turn('E');
                isEqual = checkD(diceB, diceA);
            }
            
            //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");
        }
        static bool checkD(Dice x,Dice y)
        {
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; x[j] == y[j]; j++)
                    if (j == 5)
                        return true;

                if (i == 3) break;
                else x.turn('E');
            }
            return false;
        }
    }

    
}