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;
using System.Text;
using System.Text.RegularExpressions;

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            var oneLine = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var dice = new Dice(oneLine);

            var twoLine = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var dice2 = new Dice(twoLine);

            if (dice.Right == dice2.Front || dice.Left == dice2.Back)
            {
                dice.RotateVertical(Direction.N);
            }
            else if (dice.Left == dice2.Front || dice.Right == dice2.Back)
            {
                dice.RotateVertical(Direction.S);
            }

            for (int i = 0; i < 4; i++)
            {
                if (dice.Top == dice2.Top)
                {
                    break;
                }

                dice.RotateHorizon(Direction.W);
            }


            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (dice.Top == dice2.Top &&
                        dice.Front == dice2.Front &&
                        dice.Bottom == dice2.Bottom &&
                        dice.Back == dice2.Back)
                    {
                        goto RotateVertical;
                    }
                    dice.RotateHorizon(Direction.N);
                }

                if (dice.Top == dice2.Top &&
                    dice.Front == dice2.Front &&
                    dice.Bottom == dice2.Bottom &&
                    dice.Back == dice2.Back)
                {
                    goto RotateVertical;
                }

                dice.RotateVertical(Direction.N);
                dice.RotateVertical(Direction.N);
            }

            RotateVertical:

            for (int i = 0; i < 4; i++)
            {
                if (dice.Right == dice2.Right &&
                    dice.Back == dice2.Back &&
                    dice.Left == dice2.Left &&
                    dice.Front == dice2.Front)
                {
                    break;
                }
                dice.RotateVertical(Direction.N);
            }

            Console.WriteLine(dice == dice2 ? "Yes" : "No");
        }
    }

    public class Dice
    {
        public int Top { get; private set; }
        public int Right { get; private set; }
        public int Front { get; private set; }
        public int Left { get; private set; }
        public int Bottom { get; private set; }
        public int Back { get; private set; }


        public Dice(IList<int> numbers)
        {
            //this.Number = numbers.ToArray();
            this.Top = numbers[0];
            this.Back = numbers[1];
            this.Right = numbers[2];
            this.Left = numbers[3];
            this.Front = numbers[4];
            this.Bottom = numbers[5];
        }


        public void RotateHorizon(Direction direction)
        {
            var tmp = this.Top;
            switch (direction)
            {
                case Direction.N:
                    this.Top = this.Back;
                    this.Back = this.Bottom;
                    this.Bottom = this.Front;
                    this.Front = tmp;
                    break;
                case Direction.E:
                    this.Top = this.Left;
                    this.Left = this.Bottom;
                    this.Bottom = this.Right;
                    this.Right = tmp;
                    break;
                case Direction.W:
                    this.Top = this.Right;
                    this.Right = this.Bottom;
                    this.Bottom = this.Left;
                    this.Left = tmp;
                    break;
                case Direction.S:
                    this.Top = this.Front;
                    this.Front = this.Bottom;
                    this.Bottom = this.Back;
                    this.Back = tmp;
                    break;
                default:
                    break;
            }
        }

        public void RotateVertical(Direction direction)
        {
            var tmp = this.Right;
            switch (direction)
            {
                case Direction.N:
                    this.Right = this.Back;
                    this.Back = this.Left;
                    this.Left = this.Front;
                    this.Front = tmp;
                    break;
                case Direction.S:
                    this.Right = this.Front;
                    this.Front = this.Left;
                    this.Left = this.Back;
                    this.Back = tmp;
                    break;
                default:
                    break;
            }
        }

        public static bool operator ==(Dice d, Dice d2)
        {
            return d.Top == d2.Top &&
                   d.Right == d2.Right &&
                   d.Bottom == d2.Bottom &&
                   d.Left == d2.Left &&
                   d.Front == d2.Front &&
                   d.Back == d2.Back;
        }

        public static bool operator !=(Dice d, Dice d2)
        {
            return !(d == d2);
        }
    }

    /// <summary>
    /// ダイスを転がす方向
    /// </summary>
    public enum Direction
    {
        N,
        E,
        W,
        S
    }

}