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;

namespace aoj11c
{
    class Program
    {
        static void Main(string[] args)
        {

            DICE diceA = makeDice();                     //DICE??????????????????????????????
            DICE diceB = makeDice();                     //diceA??¨diceB?????????

            Console.WriteLine(compareDice(diceA, diceB) ? "Yes" : "No");



        }//Main???????????§


        /*???????????????????????????????????????????¬?????????????????????????????????????*/
        private static bool compareDice(DICE diceA, DICE diceB)
        {
            /*???????????????*/
            if (compareTop(diceA,diceB))
            {
                return true;
            }

            diceA.rotateN();

            /*???????????????*/
            if (compareTop(diceA, diceB))
            {
                return true;
            }

            diceA.rotateN();

            /*???????????????*/
            if (compareTop(diceA, diceB))
            {
                return true;
            }

            diceA.rotateN();

            /*???????????????*/
            if (compareTop(diceA, diceB))
            {
                return true;
            }

            diceA.rotateN();        //???????????£???
            diceA.rotateE();

            /*???????????????*/
            if (compareTop(diceA, diceB))
            {
                return true;
            }

            diceA.rotateE();
            diceA.rotateE();

            /*???????????????*/
            if (compareTop(diceA, diceB))
            {
                return true;
            }

            return false;
        }

        /*TOP??¨BOTTOM????????´?????????????????´??????rotateDice???????????????????????????*/
        private static bool compareTop(DICE diceA, DICE diceB)
        {
            if (diceA.TOP == diceB.TOP && diceA.BOTTOM == diceB.BOTTOM)
            {
                if (rotateDice(diceA, diceB))
                {
                    return true;
                }
            }
            return false;
        }

        /*????¨????????????¢????????????match???????????????????????????
         * ??????????????????????????????????????¢???????????????false???????????´??????dice?????¶????????????????????????????????¶????????????*/
        private static bool rotateDice(DICE diceA, DICE diceB)
        {
            for (int i = 1; i <= 4; i++)
            {
                if (matchDice(diceA, diceB))
                {
                    return true;
                }
                diceA.rotateCW();
            }
            return false;
        }

        /*?????????????????????????????¢?????°???????????¨?????´????????????????????????????????????*/
        private static bool matchDice(DICE diceA, DICE diceB)
        {
            if (diceA.TOP == diceB.TOP && diceA.FRONT == diceB.FRONT && diceA.RIGHT == diceB.RIGHT 
                    && diceA.LEFT == diceB.LEFT && diceA.BACK == diceB.BACK && diceA.BOTTOM == diceB.BOTTOM)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        private static DICE makeDice()
        {
            int[] label = new int[6];
            string[] line = Console.ReadLine().Split(' ');
            if (line.Length != 6)    //line????????????6??§???????????°??¨??????
            {
                throw new NotImplementedException();
            }
            for (int i = 0; i < 6; i++)
            {
                label[i] = int.Parse(line[i]);
            }
            DICE newdice = new DICE(label);
            return newdice;
        }


    }

    internal class DICE
    {
        #region ?????£?????????
        public int TOP { get; set; }
        public int FRONT { get; set; }
        public int RIGHT { get; set; }
        public int LEFT { get; set; }
        public int BACK { get; set; }
        public int BOTTOM { get; set; }
        #endregion

        public DICE(int[] label)

        {
            TOP = label[0];
            FRONT = label[1];
            RIGHT = label[2];
            LEFT = label[3];
            BACK = label[4];
            BOTTOM = label[5];
        }

        public DICE()//?????°???????????´???

        {
            TOP = 1;
            FRONT = 2;
            RIGHT = 3;
            LEFT = 4;
            BACK = 5;
            BOTTOM = 6;
        }


        internal void show()
        {
            Console.WriteLine(TOP + " " + FRONT + " " + RIGHT + " " + LEFT + " " + BACK + " " + BOTTOM);
        }

        internal void rotateN()//N???????????¢
        {
            int tmp = TOP;
            TOP = FRONT;
            FRONT = BOTTOM;
            BOTTOM = BACK;
            BACK = tmp;
        }
        internal void rotateS()//S???????????¢
        {
            rotateN();
            rotateN();
            rotateN();
        }
        internal void rotateE()//E???????????¢
        {
            int tmp = TOP;
            TOP = LEFT;
            LEFT = BOTTOM;
            BOTTOM = RIGHT;
            RIGHT = tmp;
        }
        internal void rotateW()//W???????????¢
        {
            rotateE();
            rotateE();
            rotateE();
        }
        internal void rotateCW()//TOP-BOTTOM??????????¨???????
        {
            int tmp = FRONT;
            FRONT = RIGHT;
            RIGHT = BACK;
            BACK = LEFT;
            LEFT = tmp;
        }
    }
}