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 Dice
{
    public int[] Number { get; set; }

    private int[] tmp = new int[6];

    public void SetNumber(int[] a)
    {
        for (int i = 0; i < 6; i++)
        {
            Number[i] = a[i];
        }
    }

    public void Rotate(char c)
    {

        switch (c)
        {
            case 'N':
                tmp[0] = Number[1];
                tmp[1] = Number[5];
                tmp[2] = Number[2];
                tmp[3] = Number[3];
                tmp[4] = Number[0];
                tmp[5] = Number[4];
                SetNumber(tmp);
                break;
            case 'E':
                tmp[0] = Number[3];
                tmp[1] = Number[1];
                tmp[2] = Number[0];
                tmp[3] = Number[5];
                tmp[4] = Number[4];
                tmp[5] = Number[2];
                SetNumber(tmp);
                break;
            case 'W':
                tmp[0] = Number[2];
                tmp[1] = Number[1];
                tmp[2] = Number[5];
                tmp[3] = Number[0];
                tmp[4] = Number[4];
                tmp[5] = Number[3];
                SetNumber(tmp);
                break;
            case 'S':
                tmp[0] = Number[4];
                tmp[1] = Number[0];
                tmp[2] = Number[2];
                tmp[3] = Number[3];
                tmp[4] = Number[5];
                tmp[5] = Number[1];
                SetNumber(tmp);
                break;
            default:
                break;
        }
    }

    public void Spin()
    {
        tmp[0] = Number[0];
        tmp[1] = Number[2];
        tmp[2] = Number[4];
        tmp[3] = Number[1];
        tmp[4] = Number[3];
        tmp[5] = Number[5];
        SetNumber(tmp);
    }

    public void SetTop(int a)
    {
        if (a == Number[0])
        {

        }
        else if (a == Number[1])
        {
            Rotate('N');
        }
        else if (a == Number[2])
        {
            Rotate('W');
        }
        else if (a == Number[3])
        {
            Rotate('E');
        }
        else if (a == Number[4])
        {
            Rotate('S');
        }
        else if (a == Number[5])
        {
            Rotate('N');
            Rotate('N');
        }
    }

    public void SetFront(int a)
    {
        if (a == Number[0])
        {
            Rotate('S');
        }
        else if (a == Number[1])
        {
        }
        else if (a == Number[2])
        {
            Spin();
        }
        else if (a == Number[3])
        {
            Spin();
            Spin();
            Spin();
        }
        else if (a == Number[4])
        {
            Spin();
            Spin();
        }
        else if (a == Number[5])
        {
            Rotate('N');
        }
    }

    public static bool Equals(Dice x, Dice y)
    {
        y.SetTop(x.Number[0]);
        y.SetFront(x.Number[1]);
        for (int i = 0; i < 6; i++)
        {
            if (x.Number[i] != y.Number[i])
            {
                return false;
            }
        }
        return true;
    }
}

class MyClass
{
    public static void Main(string[] args)
    {
        var dice1 = new Dice()
        { Number = Console.ReadLine().Split().Select(int.Parse).ToArray() };
        var dice2 = new Dice()
        { Number = Console.ReadLine().Split().Select(int.Parse).ToArray() };
        Console.WriteLine(Dice.Equals(dice1,dice2) ? "Yes" : "No");
    }
}