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: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP1_11_C
{
    class Dice
    {
        public Dice()
        {
            Top = 0;
            Front = 1;
            Right = 2;
        }

        public void RotateNorth()
        {
            var temp = Inverse(Top);
            Top = Front;
            Front = temp;
        }


        public void RotateSouth()
        {
            var temp = Inverse(Front);
            Front = Top;
            Top = temp;
        }


        public void RotateEast()
        {
            var temp = Inverse(Right);
            Right = Top;
            Top = temp;
        }


        public void RotateWest()
        {
            var temp = Inverse(Top);
            Top = Right;
            Right = temp;
        }


        public enum Surface { TOP, BOTTOM, FRONT, BACK, RIGHT, LEFT, NONE }

        public Surface Match(int surface)
        {
            if (surface == Top) return Surface.TOP;
            if (surface == Bottom) return Surface.BOTTOM;
            if (surface == Front) return Surface.FRONT;
            if (surface == Back) return Surface.BACK;
            if (surface == Right) return Surface.RIGHT;
            if (surface == Left) return Surface.LEFT;

            return Surface.NONE;
        }


        public bool RotateToTop(int top)
        {
            switch (Match(top))
            {
                case Surface.TOP: break;
                case Surface.BOTTOM: RotateNorth(); RotateNorth(); break;
                case Surface.FRONT: RotateNorth(); break;
                case Surface.BACK: RotateSouth(); break;
                case Surface.RIGHT: RotateWest(); break;
                case Surface.LEFT: RotateEast(); break;
            }

            return Top == top;
        }


        public bool RotateToTopAndFront(int top, int front)
        {
            if (RotateToTop(top) == false)
            {
                return false;
            }

            switch (Match(front))
            {
                case Surface.RIGHT: RotateRightOfZCoords(); break;
                case Surface.BACK: RotateRightOfZCoords(); RotateRightOfZCoords(); break;
                case Surface.LEFT: RotateLeftOfZCoords();  break;
            }

            return Top == top && Front == front;
        }


        public void RotateRightOfZCoords()
        {
            var temp = Back;
            Front = Right;
            Right = temp;
        }


        public void RotateLeftOfZCoords()
        {
            var temp = Left;
            Right = Front;
            Front = temp;
        }



        public int RightOf(int front)
        {
            switch (Match(front))
            {
                case Surface.FRONT: return Right;
                case Surface.RIGHT: return Back;
                case Surface.BACK: return Left;
                case Surface.LEFT: return Front;
            }
            return -1;
        }


        public int Top { get; private set; }


        public int Front { get; private set; }


        public int Right { get; private set; }


        public int Bottom { get { return Inverse(Top); } }


        public int Back { get { return Inverse(Front); } }


        public int Left { get { return Inverse(Right); } }



        public int Inverse(int surface)
        {
            return 5 - surface;
        }


        public IEnumerable<int> Surfaces()
        {
            yield return Top;
            yield return Front;
            yield return Right;
            yield return Left;
            yield return Back;
            yield return Bottom;
        }


        public static bool EqualsAliasOfDice(string[] alias1, string[] alias2)
        {
            var dice1 = new Dice();
            var dice2 = new Dice();

            var top = -1;
            var front = -1;
            for (var i = 0; i < alias1.Length; ++i) 
            {
                if (alias1[0] == alias2[i]) {
                    top = i;
                }
                if (alias1[1] == alias2[i]) {
                    front = i;
                }
            }

            if (dice2.RotateToTopAndFront(top, front) == false)
            {
                return false;
            }

            var orderedAlias1 = dice1.Surfaces().Select(n => alias1[n]);
            var orderedAlias2 = dice2.Surfaces().Select(n => alias2[n]);
            return Enumerable.SequenceEqual(orderedAlias1, orderedAlias2);
        }
    }



    class Program
    {
        static void Main(string[] args)
        {
            var a1 = Console.ReadLine().Split(' ');
            var a2 = Console.ReadLine().Split(' ');

            Console.WriteLine(Dice.EqualsAliasOfDice(a1, a2) ? "Yes" : "No");
        }
    }
}