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;
using System.Collections.Generic;

class Program
{
    public class Dice
    {
        public int[] Face {get; set;}
        public Dice Nua(char dir)
        {
            int[] _f = Face.Clone() as int[];
            var f = Face;
            Face = _f;
            switch (dir)
            {
                case 'N':
                {
                    Face[0] = f[1];
                    Face[1] = f[5];
                    Face[5] = f[4];
                    Face[4] = f[0];
                }
                break;
                case 'E':
                {
                    Face[2] = f[0];
                    Face[0] = f[3];
                    Face[3] = f[5];
                    Face[5] = f[2];
                }
                break;
                case 'W':
                {
                    Face[3] = f[0];
                    Face[0] = f[2];
                    Face[2] = f[5];
                    Face[5] = f[3];
                }
                break;
                case 'S':
                {
                    Face[1] = f[0];
                    Face[5] = f[1];
                    Face[4] = f[5];
                    Face[0] = f[4];
                }
                break;
            }
            _f = Face;
            Face = f;
            return new Dice { Face = _f};
        }
        public override bool Equals(Object obj) 
        {
            var o = obj as Dice;
            if (o == null)
                return false;
            return Enumerable.SequenceEqual(Face, o.Face);
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
    static void Main(string[] args)
    {
        var aid = new Dice { Face = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray()};
        var k = 1;
        for (int i = 0; i < k; i++)
        {
            var aif = new Dice { Face = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray()};
            var bf = false;
            //5^4 = 625
            foreach (var f0 in "_NSWE")
            {
                if (bf)
                    break;
                foreach (var f1 in "_NSWE")
                {
                    if (bf)
                        break;
                    foreach (var f2 in "_NSWE")
                    {
                        if (bf)
                            break;
                        foreach (var f3 in "_NSWE")
                        {
                            var rolled = aid.Nua(f0).Nua(f1).Nua(f2).Nua(f3);
                            if (rolled.Equals(aif))
                            {
                                Console.WriteLine("Yes");
                                bf = true;
                                break;
                            }    
                        }
                    }
                }
            }
            if (!bf)
                Console.WriteLine("No");
        }
    }
}