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;

struct Dise
{
    public int D1 { set; get; }
    public int D2 { set; get; }
    public int D3 { set; get; }
    public int D4 { set; get; }
    public int D5 { set; get; }
    public int D6 { set; get; }
}


class Program
{
    //今回はdise[1]を回転する
    static void Rotate(Dise[] dise , char order)
    {
        int a, b;
        switch (order)
        {
            case 'N':
                a = dise[1].D1;
                b = dise[1].D6;
                dise[1].D1 = dise[1].D2;
                dise[1].D2 = b;
                dise[1].D6 = dise[1].D5;
                dise[1].D5 = a;
                break;
            case 'E':
                a = dise[1].D1;
                b = dise[1].D6;
                dise[1].D6 = dise[1].D3;
                dise[1].D1 = dise[1].D4;
                dise[1].D3 = a;
                dise[1].D4 = b;
                break;
            case 'S':
                a = dise[1].D1;
                dise[1].D1 = dise[1].D5;
                dise[1].D5 = dise[1].D6;
                dise[1].D6 = dise[1].D2;
                dise[1].D2 = a;
                break;
            case 'W':
                a = dise[1].D4;
                b = dise[1].D3;
                dise[1].D4 = dise[1].D1;
                dise[1].D3 = dise[1].D6;
                dise[1].D6 = a;
                dise[1].D1 = b;
                break;
        }
    }
    
    static bool Confir(Dise[] dise)
    {
        if (dise[0].D1 == dise[1].D1 && dise[0].D2 == dise[1].D2 && dise[0].D3 == dise[1].D3 && dise[0].D4 == dise[1].D4 &&
            dise[0].D5 == dise[1].D5 && dise[0].D6 == dise[1].D6)
        {           
            return true;
        }       
        else
        {
            return false;
        }
    }

    static void Main(string[] args)
    {       
        var dise = new Dise[2];   //サイコロの情報を持Aつ変数       

        for(int i = 0; i < 2; i++)
        {
            string[] input = Console.ReadLine().Split(' ');  //サイコロの目
            dise[i].D1 = int.Parse(input[0]);
            dise[i].D2 = int.Parse(input[1]);
            dise[i].D3 = int.Parse(input[2]);
            dise[i].D4 = int.Parse(input[3]);
            dise[i].D5 = int.Parse(input[4]);
            dise[i].D6 = int.Parse(input[5]);
        }
        
        bool flag = false;

        flag = Confir(dise);

        if (!flag)
        {
            for (int i = 0; i < 4; i++)
            {
                Rotate(dise, 'W');
                for (int j = 0; j < 4; j++)
                {
                    Rotate(dise, 'N');
                    Rotate(dise, 'W');
                    Rotate(dise, 'S');
                    flag = Confir(dise);
                    if (flag)
                    {
                        break;
                    }
                }
                if (flag)
                {
                    break;
                }
            }
        }

        if (!flag)
        {
            for (int i = 0; i < 4; i++)
            {
                Rotate(dise, 'N');
                for (int j = 0; j < 4; j++)
                {
                    Rotate(dise, 'N');
                    Rotate(dise, 'W');
                    Rotate(dise, 'S');
                    flag = Confir(dise);
                    if (flag)
                    {
                        break;
                    }
                }
                if (flag)
                {
                    break;
                }
            }
        }

        if (flag)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
        
    }
}