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

public class Program
{

    public void Proc()
    {
        Dice d1 = new Dice(Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray());
        Dice d2 = new Dice(Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray());
        string ans = "No";
        if(d1.IsSame(d2)) {
            ans = "Yes";
        }
        Console.WriteLine(ans);
    }

    private class Dice {
        DiceState state = new DiceState(1, 2, 3);
        public int[] Label;
        public Dice(int[] label) {
            this.Label = label;
        }
        public int GetTopNum() {
            return this.Label[this.state.Top - 1];
        }
        public void Move(String str) {
            foreach(char c in str) {
                if(c == 'N') {
                    this.state = this.Move(this.state, MoveDir.N);
                } else if(c == 'S') {
                    this.state = this.Move(this.state, MoveDir.S);
                } else if( c== 'E') {
                    this.state = this.Move(this.state, MoveDir.E);
                } else {
                    this.state = this.Move(this.state, MoveDir.W);
				}
            }
        }

        public int GetRightNum(int topNum, int frontNum) {
            int topIdx = this.Label.ToList().IndexOf(topNum) + 1;
            int frontIdx = this.Label.ToList().IndexOf(frontNum) + 1;
            int rightIdx = GetRight(topIdx, frontIdx);
            this.state = new DiceState(topIdx, frontIdx, rightIdx);
            return this.Label[rightIdx - 1];
        }

        public bool IsSame(Dice target) {
            if(!this.Label.All(a=>target.Label.Count(b=>b==a) == 1)) {
                return false;
            }
            int topNum = this.GetTopNum();
            int frontNum = this.Label[this.state.Front - 1];
            int rightNum = this.Label[this.state.Rigt - 1];

            if(rightNum != target.GetRightNum(topNum, frontNum)) {
                return false;
            }
            this.Move("NN");
            target.Move("NN");
            return this.GetTopNum() == target.GetTopNum() && this.Label[this.state.Front - 1] == target.Label[target.state.Front - 1]; 
		}

        public static int GetRight(int top, int front) {
            if((top == 1 && front == 2)||(top == 2 && front == 6) || (top == 6 && front == 5) || (top == 5 && front == 1)) {
                return 3;
            }
            if((top == 1 && front == 3) || (top == 3 && front == 6) || (top == 6 && front == 4) || (top == 4 && front == 1)) {
                return 5;
            }
            if((top == 4 && front == 2) || (top == 2 && front == 3) || (top == 3 && front == 5) || (top == 5 && front == 4)) {
                return 1;
            }
            return 7 - GetRight(front, top);
		}

		private DiceState Move(DiceState current, MoveDir md)
		{
			DiceState ret = new DiceState(current.Top, current.Front, current.Rigt);
			if (md == MoveDir.N)
			{
				ret.Top = current.Front;
				ret.Front = 7 - current.Top;
			}
			if (md == MoveDir.S)
			{
				ret.Top = 7 - current.Front;
				ret.Front = current.Top;
			}
			if (md == MoveDir.E)
			{
				ret.Top = 7 - current.Rigt;
				ret.Rigt = current.Top;
			}
            if (md == MoveDir.W)
			{
				ret.Top = current.Rigt;
				ret.Rigt = 7 - current.Top;
			}
			return ret;
		}


	}


    private struct DiceState {
        public int Top;
        public int Front;
        public int Rigt;
        public DiceState(int t, int f, int r) {
            this.Top = t;
            this.Front = f;
            this.Rigt = r;
        }
    }

    enum MoveDir {
        N,
        S,
        E,
        W
    }

    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"




1 2 3 4 5 6
6 5 4 3 2 1


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}