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;

namespace Project
{
	class Dice
	{
		public int face;
		public int N;
		public int E;
		public int S;
		public int W;
		public int back;

		public Dice(int a1, int a2, int a3, int a4, int a5, int a6)
		{
			face = a1;
			N = a5;
			E = a3;
			S = a2;
			W = a4;
			back = a6;
		}
		public void roll(char D)
		{
			int pface = face;
			int pN = N;
			int pE = E;
			int pW = W;
			int pS = S;
			int pback = back;
			switch (D)
			{
				case 'N':
					face = pS;
					N = pface;
					S = pback;
					back = pN;
					break;
				case 'E':
					face = pW;
					E = pface;
					W = pback;
					back = pE;
					break;
				case 'W':
					face = pE;
					E = pback;
					W = pface;
					back = pW;
					break;
				case 'S':
					face = pN;
					N = pback;
					S = pface;
					back = pS;
					break;
			}
		}
	}

	class MainClass
	{
		public static void Main(string[] args)
		{
			string[] s = Console.ReadLine().Split(' ');
			int[] a = new int[6];
			for (int i = 0; i < 6; i++)
			{
				a[i] = int.Parse(s[i]);
			}
			Dice dice1 = new Dice(a[0], a[1], a[2], a[3], a[4], a[5]);
			s = Console.ReadLine().Split(' ');
			for (int i = 0; i < 6; i++)
			{
				a[i] = int.Parse(s[i]);
			}
			Dice dice2 = new Dice(a[0], a[1], a[2], a[3], a[4], a[5]);
			int count = 0;
			while (count < 10)
			{
				if (checkdice(dice1, dice2)) break;
				dice1.roll('N');
				if (checkdice(dice1, dice2)) break;
				dice1.roll('N');
				if (checkdice(dice1, dice2)) break;
				dice1.roll('N');
				if (checkdice(dice1, dice2)) break;
				dice1.roll('N');
				if (count == 4) dice1.roll('N');
				dice1.roll('W');
				count++;
			}
			if(count == 10) Console.WriteLine("No");
			else Console.WriteLine("Yes");


		}

		public static bool checkdice(Dice dice1, Dice dice2)
		{
			if (dice1.face == dice2.face && dice1.N == dice2.N && dice1.E == dice2.E && dice1.S == dice2.S && dice1.W == dice2.W && dice1.back == dice2.back) return true;
			else return false;
		}

	}
}