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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ITP1_11_C();
        }

        static bool Same(Dice dice1, Dice dice2)
        {
            var flag = false;

            for (int i = 0; i < 3; i++)
            {
                // ①A: Dice1.Top を Dice2.Top に合わせる 
                for (int n = 0; n < 3; n++)
                {
                    if (dice1.Top == dice2.Top)
                    {
                        flag = true;
                        break;
                    }
                    dice1.Roll(Direction.East);

                    if (dice1.Top == dice2.Top)
                    {
                        flag = true;
                        break;
                    }
                    dice1.Roll(Direction.South);
                }

                // ②A: Dice1.Front を Dice2.Front に合わせる
                if (flag)
                {
                    flag = false;

                    for (int n = 0; n < 4; n++)
                    {
                        if (dice1.Front == dice2.Front)
                        {
                            flag = true;
                            break;
                        }
                        dice1.Roll(Direction.Right);
                    }
                }

                // ③A: 全体が一致すれば真
                if (flag &&
                    dice1.Top == dice2.Top &&
                    dice1.Bottom == dice2.Bottom &&
                    dice1.Right == dice2.Right &&
                    dice1.Left == dice2.Left &&
                    dice1.Front == dice2.Front &&
                    dice1.Back == dice2.Back)
                {
                    return true;
                }

                dice2.Roll(Direction.East);

                // ①B: Dice1.Top を Dice2.Top に合わせる 
                for (int n = 0; n < 3; n++)
                {
                    if (dice1.Top == dice2.Top)
                    {
                        flag = true;
                        break;
                    }
                    dice1.Roll(Direction.East);

                    if (dice1.Top == dice2.Top)
                    {
                        flag = true;
                        break;
                    }
                    dice1.Roll(Direction.South);
                }

                // ②B: Dice1.Front を Dice2.Front に合わせる
                if (flag)
                {
                    flag = false;

                    for (int n = 0; n < 4; n++)
                    {
                        if (dice1.Front == dice2.Front)
                        {
                            flag = true;
                            break;
                        }
                        dice1.Roll(Direction.Right);
                    }
                }

                // ③B: 全体が一致すれば真
                if (flag &&
                    dice1.Top == dice2.Top &&
                    dice1.Bottom == dice2.Bottom &&
                    dice1.Right == dice2.Right &&
                    dice1.Left == dice2.Left &&
                    dice1.Front == dice2.Front &&
                    dice1.Back == dice2.Back)
                {
                    return true;
                }

                dice2.Roll(Direction.South);
            }

            return false;
        }

        /// <summary>
        /// Dice I
        /// </summary>
        static void ITP1_11_A()
        {
            var numList = Console.ReadLine()
                .Split(' ').Select(x => int.Parse(x)).ToArray();

            var directList = Console.ReadLine();
            var dice = new Dice(numList);

            foreach (char direction in directList)
            {
                switch (direction)
                {
                    case 'N':
                        dice.Roll(Direction.North);
                        break;

                    case 'E':
                        dice.Roll(Direction.East);
                        break;

                    case 'S':
                        dice.Roll(Direction.South);
                        break;

                    case 'W':
                        dice.Roll(Direction.West);
                        break;
                }
            }

            Console.WriteLine(dice.Top);
        }

        /// <summary>
        /// Dice II
        /// </summary>
        static void ITP1_11_B()
        {
            var numList = Console.ReadLine()
                .Split(' ').Select(x => int.Parse(x)).ToArray();

            var q = int.Parse(Console.ReadLine());
            var dice = new Dice(numList);

            for (int i = 0; i < q; i++)
            {
                var list = Console.ReadLine()
                    .Split(' ').Select(x => int.Parse(x)).ToArray();

                while (true)
                {
                    if (dice.Top == list[0]) break;
                    dice.Roll(Direction.East);

                    if (dice.Top == list[0]) break;
                    dice.Roll(Direction.South);
                }

                if (dice.Front == list[1])
                    Console.WriteLine(dice.Right);

                else if (dice.Right == list[1])
                    Console.WriteLine(dice.Back);

                else if (dice.Back == list[1])
                    Console.WriteLine(dice.Left);

                else if (dice.Left == list[1])
                    Console.WriteLine(dice.Front);
            }
        }

        /// <summary>
        /// Dice III
        /// </summary>
        static void ITP1_11_C()
        {
            var numList1 = Console.ReadLine()
                .Split(' ').Select(x => int.Parse(x)).ToList();

            var numList2 = Console.ReadLine()
                .Split(' ').Select(x => int.Parse(x));

            var dice1 = new Dice(numList1.ToArray());
            var dice2 = new Dice(numList2.ToArray());

            var list = new List<int>();

            //// 重複確認用のリストを作成
            //for (int i = 0; i < numList1.Count(); i++)
            //{
            //    var count = 0;

            //    for (int n = 0; n < numList1.Count(); n++)
            //    {
            //        if (numList1[i] == numList1[n]) count++;
            //    }

            //    if (count == 1)
            //        list.Add(numList1[i]);
            //}

            //// 重複の確認
            //if (list.Count() < numList1.Count())
            //{
            //    // サイコロ２の上面を適当な非重複値に合わせる
            //    for (int i = 0; i < 3; i++)
            //    {
            //        if (dice2.Top == list[0])
            //        {
            //            break;
            //        }
            //        dice2.Roll(Direction.East);

            //        if (dice2.Top == list[0])
            //        {
            //            break;
            //        }
            //        dice2.Roll(Direction.South);
            //    }
            //}

            if (Same(dice1, dice2))
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }

        static void ITP1_11_D()
        {
            var listCount = int.Parse(Console.ReadLine());
            var listList = new List<List<int>>();

            for (int i = 0; i < listCount; i++)
            {
                listList.Add(
                    Console.ReadLine()
                    .Split(' ').Select(x => int.Parse(x)).ToList());
            }

        }
    }

    /// <summary>
    /// 方角を示します。
    /// </summary>
    public enum Direction
    {
        North,
        East,
        South,
        West,
        Right,
        Left
    }

    public class Dice
    {
        private int[,] diceList;

        #region Public Property

        /// <summary>
        /// サイコロの上面の要素を取得します。
        /// </summary>
        public int Top
        {
            get { return diceList[0, 0]; }
            private set { diceList[0, 0] = value; }
        }
        /// <summary>
        /// サイコロの下面の要素を取得します。
        /// </summary>
        public int Bottom
        {
            get { return diceList[2, 0]; }
            private set { diceList[2, 0] = value; }
        }

        /// <summary>
        /// サイコロの左面の要素を取得します。
        /// </summary>
        public int Left
        {
            get { return diceList[0, 3]; }
            private set { diceList[0, 3] = value; }
        }

        /// <summary>
        /// サイコロの右面の要素を取得します。
        /// </summary>
        public int Right
        {
            get { return diceList[0, 1]; }
            private set { diceList[0, 1] = value; }
        }

        /// <summary>
        /// サイコロの前面の要素を取得します。
        /// </summary>
        public int Front
        {
            get { return diceList[1, 0]; }
            private set { diceList[1, 0] = value; }
        }

        /// <summary>
        /// サイコロの後面の要素を取得します。
        /// </summary>
        public int Back
        {
            get { return diceList[3, 0]; }
            private set { diceList[3, 0] = value; }
        }

        #endregion

        public Dice(int[] face)
        {
            diceList = new int[4, 4];

            diceList[0, 0] = face[0];
            diceList[1, 0] = face[1];
            diceList[2, 0] = face[5]; //
            diceList[3, 0] = face[4];

            diceList[0, 1] = face[2];
            diceList[0, 2] = face[5]; //
            diceList[0, 3] = face[3];
        }

        /// <summary>
        /// 方角を指定してサイコロを転がします、
        /// </summary>
        public void Roll(Direction direction)
        {
            switch (direction)
            {
                case Direction.North:
                    RollNorth();
                    break;

                case Direction.East:
                    RollEast();
                    break;

                case Direction.South:
                    RollSouth();
                    break;

                case Direction.West:
                    RollWest();
                    break;

                case Direction.Right:
                    RoolRight();
                    break;

                case Direction.Left:
                    RoolLeft();
                    break;
            }
        }

        #region Private Method

        /// <summary>
        /// 横方向の変更を縦方向に反映します。
        /// </summary>
        private void UpdateXtoY() => diceList[2, 0] = diceList[0, 2];

        /// <summary>
        /// 縦方向の変更を横方向に反映します。
        /// </summary>
        private void UpdateYtoX() => diceList[0, 2] = diceList[2, 0];

        /// <summary>
        /// 北方向へ回転します。
        /// </summary>
        private void RollNorth()
        {
            var tmp = diceList[0, 0];

            for (int i = 0; i < 3; i++)
            {
                diceList[i, 0] = diceList[i + 1, 0];
            }

            diceList[3, 0] = tmp;
            UpdateYtoX();
        }

        /// <summary>
        /// 南方向へ回転します。
        /// </summary>
        private void RollSouth()
        {
            var tmp = diceList[3, 0];

            for (int i = 3; i > 0; i--)
            {
                diceList[i, 0] = diceList[i - 1, 0];
            }

            diceList[0, 0] = tmp;
            UpdateYtoX();
        }

        /// <summary>
        /// 東方向へ回転します。
        /// </summary>
        private void RollEast()
        {
            var tmp = diceList[0, 3];

            for (int i = 3; i > 0; i--)
            {
                diceList[0, i] = diceList[0, i - 1];
            }

            diceList[0, 0] = tmp;
            UpdateXtoY();
        }

        /// <summary>
        /// 西方向へ回転します。
        /// </summary>
        private void RollWest()
        {
            var tmp = diceList[0, 0];

            for (int i = 0; i < 3; i++)
            {
                diceList[0, i] = diceList[0, i + 1];
            }

            diceList[0, 3] = tmp;
            UpdateXtoY();
        }

        /// <summary>
        /// 右方向へ回転します。
        /// </summary>
        private void RoolRight()
        {
            var tmp = Front;
            Front = Left;
            Left = Back;
            Back = Right;
            Right = tmp;
        }

        /// <summary>
        /// 左方向へ回転します。
        /// </summary>
        private void RoolLeft()
        {
            var tmp = Front;
            Front = Right;
            Right = Back;
            Back = Left;
            Left = tmp;
        }

        #endregion
    }
}