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;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var dice1 = new Dice(Console.ReadLine().Split(' ').Select(int.Parse).ToArray());
            var dice2 = new Dice(Console.ReadLine().Split(' ').Select(int.Parse).ToArray());

            for(var i = 0; i < dice1.Sides.Length; ++i)
            {
                for(var k= 0; k < dice1.Sides.Length; ++k)
                {
                    if(dice1.FromTopFront(dice1[i], dice1[k]) != dice2.FromTopFront(dice1[i], dice1[k]))
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
            }
            Console.WriteLine("Yes");
        }
    }

    internal class Dice
    {
        private int[] _num = new int[7];
        private int[] _rev = new int[101]; //0 <= SideInt <= 100
        public int[] Sides { private set; get; }

        public int this[int i]
        {
            get { return Sides[i]; }
        }

        private int Num(int i)
        {
            if (i == 0) return 0;
            return this[i - 1];
        }


        public Dice(int[] v)
        {
            Sides = v;
            for(var i = 0; i < v.Length; ++i)
            {
                _rev[v[i]] = i + 1;
            }
        }

        internal int FromTopFront(int top, int front)
        {
            return Num(Right(_rev[top], _rev[front]));
        }

        private int Right(int t, int f)
        {
            int x = 0;

            if (t == 2 && f == 3 || t == 3 && f == 5 || t == 4 && f == 2 || t == 5 && f == 4)
                x = 1;
            else if (t == 1 && f == 4 || t == 3 && f == 1 || t == 4 && f == 6 || t == 6 && f == 3)
                x = 2;
            else if (t == 1 && f == 2 || t == 2 && f == 6 || t == 5 && f == 1 || t == 6 && f == 5)
                x = 3;
            else if (t == 1 && f == 5 || t == 2 && f == 1 || t == 5 && f == 6 || t == 6 && f == 2)
                x = 4;
            else if (t == 1 && f == 3 || t == 3 && f == 6 || t == 4 && f == 1 || t == 6 && f == 4)
                x = 5;
            else if (t == 2 && f == 4 || t == 3 && f == 2 || t == 4 && f == 5 || t == 5 && f == 3)
                x = 6;

            return x;
        }
    }
}