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.Linq;
//using System.Collections.Generic;

class Test
{
    static void Main()
    {
        Dice dice1 = new Dice(Console.ReadLine());
        Dice dice2 = new Dice(Console.ReadLine());

        string move = "PPPPNPPPPNPPPPNPPPPEPPPPEEPPPP";
        int flag = 0;

        for (int i = 0; i < move.Length; i++)
        {
            //if (ReferenceEquals(dice1, dice2))
            if (dice1.d1 == dice2.d1 && dice1.d2 == dice2.d2 && dice1.d3 == dice2.d3 && dice1.d4 == dice2.d4 && dice1.d5 == dice2.d5 && dice1.d6 == dice2.d6)
            {
                Console.WriteLine("Yes");
                flag = 1;
                break;
            }

            switch (move[i])
            {
                case 'N':
                    dice2.North();
                    break;
                case 'E':
                    dice2.East();
                    break;
                case 'W':
                    dice2.West();
                    break;
                case 'S':
                    dice2.South();
                    break;
                case 'P':
                    dice2.Spin();
                    break;
            }
        }

        if (flag == 0) Console.WriteLine("No");
    }
}

class Dice
{
    string[] ss;
    public string d1, d2, d3, d4, d5, d6;

    public Dice(string s)
    {
        this.ss = s.Split();
        d1 = ss[0];
        d2 = ss[1];
        d3 = ss[2];
        d4 = ss[3];
        d5 = ss[4];
        d6 = ss[5];
    }

    string tmp;

    public void North()
    {
        tmp = d1;
        d1 = d2;
        d2 = d6;
        d6 = d5;
        d5 = tmp;
    }

    public void East()
    {
        tmp = d1;
        d1 = d4;
        d4 = d6;
        d6 = d3;
        d3 = tmp;
    }

    public void West()
    {
        tmp = d1;
        d1 = d3;
        d3 = d6;
        d6 = d4;
        d4 = tmp;
    }

    public void South()
    {
        tmp = d1;
        d1 = d5;
        d5 = d6;
        d6 = d2;
        d2 = tmp;
    }

    public void Spin()
    {
        tmp = d2;
        d2 = d4;
        d4 = d5;
        d5 = d3;
        d3 = tmp;
    }
}