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 ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int[]> dice = new List<int[]>();
            string ans = "";
            for (int i = 0; i < 2; i++)
            {
                int[] dice1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                dice.Add(dice1);
            }

            for (int j = 0; j < 6; j++)
            {
                int dir = 0;
                if (dice[0][0] == dice[1][j]) dir = j;
                else if (!(dice[0].Contains(dice[1][j])))
                {
                    ans = "Yes"; break;
                }
                else continue;

                int d = dice[1][5 - dir];
                dice[1][5 - dir] = dice[1][0];
                dice[1][0] = dice[1][dir];
                dice[1][dir] = dice[1][5];
                dice[1][5] = d;

                if (dir == 5)
                {
                    int d2 = dice[1][2];
                    dice[1][2] = dice[1][3];
                    dice[1][3] = d2;
                }

                int[] side = { dice[1][1], dice[1][2], dice[1][4], dice[1][3], dice[1][1], dice[1][2] };
                for (int k = 0; k < 4; k++)
                {
                    if (side[k] == dice[0][1])
                    {
                        if (side[k + 1] == dice[0][2] && side[k + 2] == dice[0][4] && dice[1][5] == dice[0][5])
                        {
                            ans = "Yes"; break;
                        }
                        else
                            ans = "No";
                    }
                    else if (!(side.Contains(dice[0][1])))
                    {
                        ans = "Yes";
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}