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;

public class Dice
{
	private int[] labels;
	public const int TOP = 0;
	public const int FRONT = 1;
	public const int RIGHT = 2;
	public const int LEFT = 3;
	public const int BACK = 4;
	public const int BOTTOM = 5;
	public Dice( int[] labels )
	{
		this.labels = labels;
	}
	public void roll( string cmds )
	{
		int t;
		for( int i=0; i<cmds.Length; i++ ) {
			if( 'E' == cmds[i] ) {
			t = this.labels[TOP];
				this.labels[TOP] = this.labels[LEFT];
				this.labels[LEFT] = this.labels[BOTTOM];
				this.labels[BOTTOM] = this.labels[RIGHT];
				this.labels[RIGHT] = t;
			} else if( 'S' == cmds[i] ) {
				t = this.labels[TOP];
				this.labels[TOP] = this.labels[BACK];
				this.labels[BACK] = this.labels[BOTTOM];
				this.labels[BOTTOM] = this.labels[FRONT];
				this.labels[FRONT] = t;
			} else if( 'W' == cmds[i] ) {
				t = this.labels[TOP];
				this.labels[TOP] = this.labels[RIGHT];
				this.labels[RIGHT] = this.labels[BOTTOM];
				this.labels[BOTTOM] = this.labels[LEFT];
				this.labels[LEFT] = t;
			} else if( 'N' == cmds[i] ) {
				t = this.labels[TOP];
				this.labels[TOP] = this.labels[FRONT];
				this.labels[FRONT] = this.labels[BOTTOM];
				this.labels[BOTTOM] = this.labels[BACK];
				this.labels[BACK] = t;        
			} else if( 'M' == cmds[i] ) {
				t = this.labels[FRONT];
				this.labels[FRONT] = this.labels[RIGHT];
				this.labels[RIGHT] = this.labels[BACK];
				this.labels[BACK] = this.labels[LEFT];
				this.labels[LEFT] = t;        
			}	
		}
	}
	public int getLabel( int face )
	{
		return this.labels[face];
	}
	public bool isEqual( Dice another )
	{
		string cmds = "SWWWSMMM";
		int i;
		for( i=0; i<5; i++ ) {
			if( another.getLabel( Dice.TOP ) == this.getLabel( Dice.TOP ) ) { break; }
			this.roll( cmds[i].ToString() );			
		}
		for( i=5; i<8; i++ ) {
			if( another.getLabel( Dice.FRONT ) == this.getLabel( Dice.FRONT ) ) { break; }
			this.roll( cmds[i].ToString() );			
		}
		for( i=Dice.TOP; i<=Dice.BOTTOM; i++ ) {
			if( another.getLabel( i ) != this.getLabel( i ) ) { break; }		
		}
		return (6 == i)?true:false;
	}
	
}

public class Test
{
	public static void Main( )
	{

		int[] labels = Array.ConvertAll( Console.ReadLine().Split( ' ' ), int.Parse );
		Dice dice = new Dice( labels );
		labels = Array.ConvertAll( Console.ReadLine().Split( ' ' ), int.Parse );
		Dice dice2 = new Dice( labels );
		if( dice.isEqual( dice2 ) ) {
			Console.WriteLine( "Yes" );			
		} else {
			Console.WriteLine( "No" );
		}
	}
}