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

namespace ITP1_11_C
{
	class Program
	{
		// faces[] = { 0, 1, 2, 3, 4, 5, 6 };
		//   0
		// 3 1 2 4
		//   5
		static void Main(string[] args)
		{
			string s1 = Console.ReadLine();
			string[] faces1 = s1.Split();

			string s2 = Console.ReadLine();
			string[] faces2 = s2.Split();

			Dice dice1 = new Dice(faces1);
			Dice dice2 = new Dice(faces2);
			// 上面を探す
			int c = 0;
			while (dice1.Top != dice2.Top) {
				if (c < 3) {
					dice1.MoveN();
				} else if (c < 4) {
					dice1.MoveE();
				} else if (c < 5) {
					dice1.MoveE();
					dice1.MoveE();
				} else if (c < 6) {
					break;
				}
				c++;
			}
			// 正面を探す
			c = 0;
			while (dice1.South != dice2.South) {
				if (c < 3) {
					dice1.MoveCW();
				} else {
					break;
				}
				c++;
			}
			// 同一か確認
			if (dice1.Top == dice2.Top && dice1.Bottom == dice2.Bottom &&
				dice1.North == dice2.North && dice1.South == dice2.South &&
				dice1.East == dice2.East && dice1.West == dice2.West) {
				Console.WriteLine("Yes");
			} else {
				Console.WriteLine("No");
			}

			// Console.WriteLine("Hit Any Key");
			// Console.ReadLine();
		}
	}

	class Dice
	{
		//   1
		// 4 2 3 5
		//   6
		public string Top { get; private set; }
		public string North { get; private set; }
		public string South { get; private set; }
		public string East { get; private set; }
		public string West { get; private set; }
		public string Bottom { get; private set; }
		public Dice(string[] faces)
		{
			Top = faces[0];
			North = faces[4];
			South = faces[1];
			East = faces[2];
			West = faces[3];
			Bottom = faces[5];
		}
		public void MoveN()
		{
			// T<-S<-B<-N<-T
			string tmp = Top;
			Top = South;
			South = Bottom;
			Bottom = North;
			North = tmp;
		}
		public void MoveS()
		{
			// T<-N<-B<-S<-T
			string tmp = Top;
			Top = North;
			North = Bottom;
			Bottom = South;
			South = tmp;
		}
		public void MoveE()
		{
			// T<-W<-B<-E<-T
			string tmp = Top;
			Top = West;
			West = Bottom;
			Bottom = East;
			East = tmp;
		}
		public void MoveW()
		{
			// T<-E<-B<-W<-T
			string tmp = Top;
			Top = East;
			East = Bottom;
			Bottom = West;
			West = tmp;
		}
		public void MoveCW()
		{
			// N<-W<-S<-E<-N
			string tmp = North;
			North = West;
			West = South;
			South = East;
			East = tmp;
		}
		public void MoveCCW()
		{
			// N<-E<-S<-W<-N
			string tmp = North;
			North = East;
			East = South;
			South = West;
			West = tmp;
		}
	}
}