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;

public class Program
{
    /// <summary>
    /// プログラムエントリポイント
    /// </summary>
    public static void Main()
    {

        //サイコロの目入力　１つ目
        string[] aryStrDice1 = Console.ReadLine().Split(' ');

        //サイコロの目入力　２つ目
        string[] aryStrDice2 = Console.ReadLine().Split(' ');

        //Diceクラス生成
        Dice insDice = new Dice(aryStrDice1, aryStrDice2);

        //引数なしinsDice.rollDice()の戻り値がtrueならYes,falseならNoを出力
        Console.WriteLine( insDice.rollDice() ? "Yes" : "No" );
        
    }

}

/// <summary>
/// Diceクラス
/// </summary>
class Dice
{

    int[] aryIntDice1 = new int[6];
    int[] aryIntDice2 = new int[6];

    /// <summary>
    /// コンストラクタ
    /// </summary>
    /// <param name="aryStrDice1">サイコロの目　１個目</param>
    /// <param name="aryStrDice2">サイコロの目　２個目</param>
    public Dice(string[] aryStrDice1, string[] aryStrDice2)
    {
        //引数string[]二つをint[]の置き換える
        for (int i = 0; i < 6; i++)
        {
            aryIntDice1[i] = int.Parse(aryStrDice1[i]);
            aryIntDice2[i] = int.Parse(aryStrDice2[i]);
        }
    }

    /// <summary>
    /// サイコロ１を動かしてすべての目があっているか判断
    /// </summary>
    /// <returns>bool</returns>
    public bool rollDice()
    {
        //E方向,N方向に4回ずつ動かしたいので 2回繰り返す
        for (int x = 0; x < 2; x++)
        {
            // E,N方向に4回動かす
            for (int i = 0; i < 4; i++)
            {
                //サイコロどうしが同じか判断
                if (checkAllDice())
                {
                    return true;
                }

                // x が0の間 E 方向に動かす
                if (x == 0) 
                {
                    runOperationE();
                }
                // x が0以外の間 N 方向に動かす
                else
                {
                    runOperationN();
                }

                // サイコロを4回右回転させる
                for (int j = 0; j < 4; j++)
                {
                    //サイコロどうしが同じか判断
                    if (checkAllDice())
                    {
                        return true;
                    }

                    //右回転させる
                    runOperationR();

                }

            }
        }
        return false;
    }

    /// <summary>
    /// サイコロ１とサイコロ２のすべての目が同じか判断
    /// </summary>
    /// <returns>bool</returns>
    private bool checkAllDice()
    {
        if (aryIntDice1[0] == aryIntDice2[0] && aryIntDice1[1] == aryIntDice2[1] &&
             aryIntDice1[2] == aryIntDice2[2] && aryIntDice1[3] == aryIntDice2[3] &&
                aryIntDice1[4] == aryIntDice2[4] && aryIntDice1[5] == aryIntDice2[5])
        {
            return true;
        }
        return false;
    }

    /// <summary>
    /// サイコロを命令に従って動かす E方向
    /// </summary>
    private void runOperationE()
    {
        int tmpStorage = aryIntDice1[0];
        aryIntDice1[0] = aryIntDice1[3];
        aryIntDice1[3] = aryIntDice1[5];
        aryIntDice1[5] = aryIntDice1[2];
        aryIntDice1[2] = tmpStorage;
    }
    /// <summary>
    /// サイコロを命令に従って動かす N方向
    /// </summary>
    private void runOperationN()
    {
        int tmpStorage = aryIntDice1[0];
        aryIntDice1[0] = aryIntDice1[1];
        aryIntDice1[1] = aryIntDice1[5];
        aryIntDice1[5] = aryIntDice1[4];
        aryIntDice1[4] = tmpStorage;
    }
    /// <summary>
    /// サイコロを命令に従って動かす S方向
    /// </summary>
    private void runOperationS()
    {
        int tmpStorage = aryIntDice1[0];
        aryIntDice1[0] = aryIntDice1[4];
        aryIntDice1[4] = aryIntDice1[5];
        aryIntDice1[5] = aryIntDice1[1];
        aryIntDice1[1] = tmpStorage;
    }
    /// <summary>
    /// サイコロを命令に従って動かす W方向
    /// </summary>
    private void runOperationW()
    {
        int tmpStorage = aryIntDice1[0];
        aryIntDice1[0] = aryIntDice1[2];
        aryIntDice1[2] = aryIntDice1[5];
        aryIntDice1[5] = aryIntDice1[3];
        aryIntDice1[3] = tmpStorage;
    }

    /// <summary>
    /// サイコロを命令に従って動かす 右ロール
    /// </summary>
    private void runOperationR()
    {
        int tmpStorage = aryIntDice1[1];
        aryIntDice1[1] = aryIntDice1[2];
        aryIntDice1[2] = aryIntDice1[4];
        aryIntDice1[4] = aryIntDice1[3];
        aryIntDice1[3] = tmpStorage;
    }

}