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

			bool f = false;
			for (int i = 0; i < 6; i++) {
				Dice dice2 = new Dice(faces2);
				switch (i) {
				case 0:
					break;
				case 1:
					dice2.MoveS();
					break;
				case 2:
					dice2.MoveN();
					break;
				case 3:
					dice2.MoveW();
					break;
				case 4:
					dice2.MoveE();
					break;
				case 5:
					dice2.MoveN();
					dice2.MoveN();
					break;
				}
				for (int j = 0; j < 4; j++) {
					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) {
						f = true;
						break;
					}
					dice2.MoveCW();
				}
				if (f) { break; }
			}
			if (f) {
				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;
		}
	}
}