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;
namespace AOJ
{
    internal class Program
    {
        public static void Main(string[] args) { new Program().solve(); }
        void solve() {
            var d1 = new DiceClass();
            var d2 = new DiceClass();
            d1.Dice = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            d2.Dice = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var f = d1.IsSameDice(d2.Dice);
            Console.WriteLine(f ? "Yes" : "No");
        }
    }
    class DiceClass
    {
        //above figure is |0|
        //front figure is |1|
        //     N
        //    |0|
        //W |3|1|2|4| E
        //    |5|
        //     S
        public int[] Dice = new int[6];
        public int Above { get { return Dice[0]; } }
        private int[] genArr(params int[] a) {
            return new int[] { Dice[a[0]], Dice[a[1]], Dice[a[2]], Dice[a[3]], Dice[a[4]], Dice[a[5]] };
        }
        public int[] Roll(char dir) {
            switch (dir) {
                case 'N': return genArr(1, 5, 2, 3, 0, 4);
                case 'W': return genArr(2, 1, 5, 0, 4, 3);
                case 'E': return genArr(3, 1, 0, 5, 4, 2);
                case 'S': return genArr(4, 0, 2, 3, 5, 1);
                default: return new int[0];
            }
        }
        //NNNN WNNN WNNN ENNN ENNN WNNN
        public void SetRoll(string dir) {
            foreach (var c in dir) SetRoll(c);
        }
        public void SetRoll(char dir) {
            Dice = Roll(dir);
        }
        public bool IsSameDice(int[] d) {
            foreach(var o in "NNNNWNNNWNNNENNNENNNWNNN") {
                SetRoll(o);
                if (Dice.SequenceEqual(d)) return true;
            }
            return false;
        }
        public void Show() {
            Console.WriteLine("     N");
            Console.WriteLine("    |" + Dice[0] + "|");
            Console.WriteLine("W |" + Dice[3] + "|" + Dice[1] + "|" + Dice[2] + "|" + Dice[4] + "| E");
            Console.WriteLine("    |" + Dice[5] + "|");
            Console.WriteLine("     S");
        }
        public int Right(int above, int front) {
            Func<int, int, bool> f = (a, b) => Dice[a] == above && Dice[b] == front;
            if (f(1, 2) || f(2, 4) || f(4, 3) || f(3, 1)) return Dice[0];
            if (f(0, 3) || f(3, 5) || f(5, 2) || f(2, 0)) return Dice[1];
            if (f(0, 1) || f(1, 5) || f(5, 4) || f(4, 0)) return Dice[2];
            if (f(1, 0) || f(0, 4) || f(4, 5) || f(5, 1)) return Dice[3];
            if (f(0, 2) || f(2, 5) || f(5, 3) || f(3, 0)) return Dice[4];
            return Dice[5];
        }
    }
}