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;

class program
{

    public static void Main()
    {
        var faces = new int[6];
        var nums = Console.ReadLine().Split(' ');

        for (var i = 0; i < 6; i++)
        {
            faces[i] = int.Parse(nums[i]);
        }

        var dice1 = new Dice(faces);

        nums = Console.ReadLine().Split(' ');

        for (var i = 0; i < 6; i++)
        {
            faces[i] = int.Parse(nums[i]);
        }

        var dice2 = new Dice(faces);

        if (dice1.Equal(dice2))
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }

    }
}

public class Dice
{
    public int front { get; set; }
    private int back { get; set; } // rear
    private int up { get; set; }
    private int down { get; set; }
    private int left { get; set; }
    private int right { get; set; }

    public Dice(int[] faces)
    {
        this.front = faces[0];
        this.down = faces[1];
        this.right = faces[2];
        this.left = faces[3];
        this.up = faces[4];
        this.back = faces[5];
    }

    public int findRightNum(int front, int down)
    {
        for (int i = 0; i < 5; i++)
        {
            if (front == this.front) break;

            if (i < 3) // 0..2
            {
                doE();
            }
            else if (i == 3)
            {
                doN();
            }
            else // 4
            {
                doS(); doS();
            }

        }

        for (int i = 0; i < 3; i++)
        {
            if (down == this.down) break;
            doRotateR();
        }

        return this.right;
    }

    public void next(string command)
    {
        switch (command)
        {
            case "N":
                doN();
                break;
            case "E":
                doE();
                break;
            case "S":
                doS();
                break;
            case "W":
                doW();
                break;
        }
    }

    private void doN()
    {
        var buf = this.down;
        this.down = this.back;
        this.back = this.up;
        this.up = this.front;
        this.front = buf;
    }

    private void doE()
    {
        var buf = this.left;
        this.left = this.back;
        this.back = this.right;
        this.right = this.front;
        this.front = buf;
    }

    private void doS()
    {
        var buf = this.up;
        this.up = this.back;
        this.back = this.down;
        this.down = this.front;
        this.front = buf;
    }

    private void doW()
    {
        var buf = this.right;
        this.right = this.back;
        this.back = this.left;
        this.left = this.front;
        this.front = buf;
    }

    private void doRotateR()
    {
        var buf = this.up;
        this.up = this.left;
        this.left = this.down;
        this.down = this.right;
        this.right = buf;
    }

    public bool Equal(Dice dice)
    {
        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                dice.doRotateR();
                if (EqualDice(dice))
                {
                    return true;
                }
            };

            if (i < 3) // 0..2
            {
                doE();
                for (int j = 0; j < 4; j++) { 
                    dice.doRotateR(); 
                    if (EqualDice(dice)) { 
                        return true; 
                    } 
                };
            }
            else if (i == 3)
            {
                doN();
                for (int j = 0; j < 4; j++)
                {
                    dice.doRotateR();
                    if (EqualDice(dice))
                    {
                        return true;
                    }
                };
            }
            else // 4
            {
                doS(); doS();
                for (int j = 0; j < 4; j++)
                {
                    dice.doRotateR();
                    if (EqualDice(dice))
                    {
                        return true;
                    }
                };
            }
        }
        return false;
    }

    public bool EqualDice(Dice dice)
    {
        if (this.front == dice.front &&
            this.left == dice.left &&
            this.right == dice.right &&
            this.down == dice.down &&
            this.up == dice.up &&
            this.back == dice.back)
        {
            return true;
        }

        return false;
    }
}