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.Linq;

class Problem {
    class Dice {
        public int Top    { get; private set; }
        public int South  { get; private set; }
        public int East   { get; private set; }
        public int West   { get; private set; }
        public int North  { get; private set; }
        public int Bottom { get; private set; }
        public Dice(int[] nums) {
            Top    = nums[0];
            South  = nums[1];
            East   = nums[2];
            West   = nums[3];
            North  = nums[4];
            Bottom = nums[5];
        }
        public void Roll(string coms) {
            foreach (var com in coms) {
                var tmp = Top;
                switch (com) {
                    case 'E': Top = West;  West  = Bottom; Bottom = East;  East  = tmp; break;
                    case 'N': Top = South; South = Bottom; Bottom = North; North = tmp; break;
                    case 'S': Top = North; North = Bottom; Bottom = South; South = tmp; break;
                    case 'W': Top = East;  East  = Bottom; Bottom = West;  West  = tmp; break;
                }
            }
        }
        public void RollY(string coms) {
            foreach (var com in coms) {
                var tmp = South;
                switch (com) {
                    case 'R': South = West; West = North; North = East; East = tmp; break;
                    case 'L': South = East; East = North; North = West; West = tmp; break;
                }
            }
        }
        public char Position(int num) {
            return num == Top   ? 'T' :
                   num == South ? 'S' :
                   num == East  ? 'E' :
                   num == West  ? 'W' :
                   num == North ? 'N' : 'B';
        }
    }
    
    public static void Main() {
        var d1 = new Dice(Console.ReadLine().Split().Select(int.Parse).ToArray());
        var d2 = new Dice(Console.ReadLine().Split().Select(int.Parse).ToArray());
        switch (d1.Position(d2.Top)) {
            case 'T': break;
            case 'S': d1.Roll("N"); break;
            case 'E': d1.Roll("W"); break;
            case 'W': d1.Roll("E"); break;
            case 'N': d1.Roll("S"); break;
            case 'B': d1.Roll("NN"); break;
        }
        switch (d1.Position(d2.South)) {
            case 'S': break;
            case 'E': d1.RollY("L"); break;
            case 'W': d1.RollY("R"); break;
            case 'N': d1.RollY("RR"); break;
        }
        Console.WriteLine(d1.Top    == d2.Top   &&
            	  d1.South  == d2.South &&
            	  d1.East   == d2.East  &&
            	  d1.West   == d2.West  &&
            	  d1.North  == d2.North &&
            	  d1.Bottom == d2.Bottom   ? "Yes" : "No");
    }
}