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;
using System.Text;
using System.Threading.Tasks;

namespace AOJ1_11_C
{
    class Program
    {
        static int[] _dice1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        static int[] _dice2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        static void Main(string[] args)
        {
            if (Dice.RoundRobin(_dice1, _dice2) == true)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
        class Dice
        {
            internal static void RollDice(int[] a_Dice, string order)
            {
                int tmp = a_Dice[0];
                if (order == "E")
                {
                    a_Dice[0] = a_Dice[3];
                    a_Dice[3] = a_Dice[5];
                    a_Dice[5] = a_Dice[2];
                    a_Dice[2] = tmp;
                }
                else if (order == "N")
                {
                    a_Dice[0] = a_Dice[1];
                    a_Dice[1] = a_Dice[5];
                    a_Dice[5] = a_Dice[4];
                    a_Dice[4] = tmp;
                }
                else if (order == "S")
                {
                    a_Dice[0] = a_Dice[4];
                    a_Dice[4] = a_Dice[5];
                    a_Dice[5] = a_Dice[1];
                    a_Dice[1] = tmp;
                }
                else if (order == "W")
                {
                    a_Dice[0] = a_Dice[2];
                    a_Dice[2] = a_Dice[5];
                    a_Dice[5] = a_Dice[3];
                    a_Dice[3] = tmp;
                }
            }
            internal static void SpinDice(int[] a_Dice, string order)
            {
                int tmp = a_Dice[1];
                if (order == "R")
                {
                    a_Dice[1] = a_Dice[2];
                    a_Dice[2] = a_Dice[4];
                    a_Dice[4] = a_Dice[3];
                    a_Dice[3] = tmp;
                }
                else if (order == "L")
                {
                    a_Dice[1] = a_Dice[3];
                    a_Dice[3] = a_Dice[1];
                    a_Dice[4] = a_Dice[2];
                    a_Dice[2] = tmp;
                }
            }

            internal static bool MatchDice(int[] dice1, int[] dice2)
            {
                int top1 = dice1[0];
                int flont1 = dice1[1];
                int right1 = dice1[2];
                int left1 = dice1[3];
                int buck1 = dice1[4];
                int bottom1 = dice1[5];
                int top2 = dice2[0];
                int flont2 = dice2[1];
                int right2 = dice2[2];
                int left2 = dice2[3];
                int buck2 = dice2[4];
                int bottom2 = dice2[5];
                if (top1 == top2 && flont1 == flont2 && right1 == right2 && left1 == left2 && buck1 == buck2
                    && bottom1 == bottom2)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            static internal bool SideCheck(int[] dice1, int[] dice2)
            {
                bool sideNumberMatch = false;
                for (int i = 0; i < 4; ++i)
                {
                    sideNumberMatch = MatchDice(_dice1, _dice2);
                    if (sideNumberMatch == true)
                    {
                        return true;
                    }
                    SpinDice(_dice2, "R");
                }
                return false;
            }
            static internal bool RoundRobin(int[] dice1, int[] dice2)
            {
                bool match_or_Not = false;
                match_or_Not = SideCheck(dice1, dice2);
                if (match_or_Not == true)
                {
                    return true;
                }
                RollDice(dice2, "N");
                match_or_Not = SideCheck(dice1, dice2);
                if (match_or_Not == true)
                {
                    return true;
                }
                RollDice(dice2, "W");
                match_or_Not = SideCheck(dice1, dice2);
                if (match_or_Not == true)
                {
                    return true;
                }
                RollDice(dice2, "W");
                match_or_Not = SideCheck(dice1, dice2);
                if (match_or_Not == true)
                {
                    return true;
                }
                RollDice(dice2, "W");
                match_or_Not = SideCheck(dice1, dice2);
                if (match_or_Not == true)
                {
                    return true;
                }
                RollDice(dice2, "N");
                match_or_Not = SideCheck(dice1, dice2);
                if (match_or_Not == true)
                {
                    return true;
                }
                return false;
            }
        }
    }
}