#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* common define */
/* TODO create common.h */
#define U1 unsigned char
#define S1 char
#define	S4 int
#define DU double
#define VD void

#define TRUE              (1)
#define FALSE             (0)

/* define */
#define	MAX_COMMAND_BYTES	(1)
#define MAX_COMMAND_COUNT	(100)
#define NUM_KIND_OF_COMMAND	(6)
#define NUM_FACE_OF_DICE	(6)

typedef struct st_dice
{
	S4 s4_top;
	S4 s4_north;
	S4 s4_east;
	S4 s4_west;
	S4 s4_south;
	S4 s4_bottom;
}ST_DICE;

typedef struct st_commands_string
{
	S4 s4_command_count;
	U1 u1_commands_string[MAX_COMMAND_COUNT][MAX_COMMAND_BYTES + 1];
}ST_COMMANDS_STRING;

typedef VD(*COMMNAD_FUNC_TYPE)(ST_DICE*);

typedef struct st_command
{
	U1 u1_command_string[MAX_COMMAND_BYTES + 1];
	COMMNAD_FUNC_TYPE st_command_func;
}ST_COMMAND;

static S4 s4_s_is_same_dice(ST_DICE*, ST_DICE*);
static VD vd_s_move_dice_to_answer_question(ST_DICE*, S4, S4);
static VD vd_s_move_dice_multiply(ST_COMMANDS_STRING*, ST_DICE*);
static VD vd_s_move_dice(U1[MAX_COMMAND_BYTES + 1], ST_DICE*);
static VD vd_s_North(ST_DICE*);
static VD vd_s_East(ST_DICE*);
static VD vd_s_West(ST_DICE*);
static VD vd_s_South(ST_DICE*);
static VD vd_s_Right(ST_DICE*);
static VD vd_s_Left(ST_DICE*);
static VD vd_s_create_dice(ST_DICE*);

const ST_COMMAND st_c_command[NUM_KIND_OF_COMMAND] =
{
	{ "N", vd_s_North },
	{ "E", vd_s_East },
	{ "W", vd_s_West },
	{ "S", vd_s_South },
	{ "R", vd_s_Right },
	{ "L", vd_s_Left }
};

S4 main()
{
	ST_DICE st_t_dice1;
	ST_DICE st_t_dice2;
	S4 s4_t_is_same_dice;

	/* Input the face number of dices */
	vd_s_create_dice(&st_t_dice1);
	vd_s_create_dice(&st_t_dice2);

	/* Judge if the dices are same. */
	s4_t_is_same_dice = s4_s_is_same_dice(&st_t_dice1, &st_t_dice2);

	/* answer the question. */
	if (s4_t_is_same_dice == (S4)TRUE)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

	return((S4)0);
}

static S4 s4_s_is_same_dice(ST_DICE* st_ap_first_dice, ST_DICE* st_ap_second_dice)
{
	S4 s4_t_dice_index;
	S4 s4_t_dice_index2;
	S4 s4_t_is_same_dice;

	s4_t_is_same_dice = (S4)FALSE;
	s4_t_dice_index = (S4)0;
	s4_t_dice_index2 = (S4)0;

	/* Rotate the second dice to meet the top face. */
	/* try to rorate to north to meet the top face. */
	s4_t_dice_index = (S4)0;
	while ((s4_t_dice_index < (S4)4) &&		/* rotate 4 times to rotate original dice postion. */
		(s4_t_is_same_dice != (S4)TRUE))
	{
		if (st_ap_first_dice->s4_top == st_ap_second_dice->s4_top)
		{
			s4_t_dice_index2 = (S4)0;
			/* Check the dices if others face are same */
			while ((s4_t_dice_index2 < (S4)4) &&
				(s4_t_is_same_dice != (S4)TRUE))
			{
				if ((st_ap_first_dice->s4_north != st_ap_second_dice->s4_north) ||
					(st_ap_first_dice->s4_south != st_ap_second_dice->s4_south) ||
					(st_ap_first_dice->s4_east != st_ap_second_dice->s4_east) ||
					(st_ap_first_dice->s4_west != st_ap_second_dice->s4_west) ||
					(st_ap_first_dice->s4_bottom != st_ap_second_dice->s4_bottom))
				{
					s4_t_is_same_dice = (S4)FALSE;
				}
				else
				{
					s4_t_is_same_dice = (S4)TRUE;
				}
				vd_s_Right(st_ap_second_dice);
				s4_t_dice_index2++;
			}
		}
		vd_s_North(st_ap_second_dice);
		s4_t_dice_index++;
	}

	/* try the east and west */
	s4_t_dice_index = (S4)0;
	while ((s4_t_dice_index < (S4)4) &&
		(s4_t_is_same_dice != (S4)TRUE))
	{
		if (st_ap_first_dice->s4_top == st_ap_second_dice->s4_top)
		{
			s4_t_dice_index2 = (S4)0;
			/* Check the dices if others face are same */
			while ((s4_t_dice_index2 < (S4)4) &&
				(s4_t_is_same_dice != (S4)TRUE))
			{
				if ((st_ap_first_dice->s4_north != st_ap_second_dice->s4_north) ||
					(st_ap_first_dice->s4_south != st_ap_second_dice->s4_south) ||
					(st_ap_first_dice->s4_east != st_ap_second_dice->s4_east) ||
					(st_ap_first_dice->s4_west != st_ap_second_dice->s4_west) ||
					(st_ap_first_dice->s4_bottom != st_ap_second_dice->s4_bottom))
				{
					s4_t_is_same_dice = (S4)FALSE;
				}
				else
				{
					s4_t_is_same_dice = (S4)TRUE;
				}
				vd_s_Right(st_ap_second_dice);
				s4_t_dice_index2++;
			}
		}
		vd_s_East(st_ap_second_dice);
		s4_t_dice_index++;
	}

	return(s4_t_is_same_dice);
}

static VD vd_s_move_dice_to_answer_question(ST_DICE* st_ap_dice, S4 s4_a_question_dice_top, S4 s4_a_question_dice_front)
{
	S4 s4_t_dice_index;

	/* Move the dice to meet top */
	s4_t_dice_index = (S4)0;
	while ((s4_t_dice_index < (S4)3) &&
		(st_ap_dice->s4_top != s4_a_question_dice_top))
	{
		vd_s_North(st_ap_dice);
		s4_t_dice_index++;
	}
	s4_t_dice_index = (S4)0;
	while ((s4_t_dice_index < (S4)3) &&
		(st_ap_dice->s4_top != s4_a_question_dice_top))
	{
		vd_s_West(st_ap_dice);
		s4_t_dice_index++;
	}

	/* Move the dice to meet front */
	s4_t_dice_index = (S4)0;
	while ((s4_t_dice_index < (S4)3) &&
		(st_ap_dice->s4_south != s4_a_question_dice_front))
	{
		vd_s_Right(st_ap_dice);
		s4_t_dice_index++;
	}

	return;
}

static VD vd_s_move_dice_multiply(ST_COMMANDS_STRING* st_ap_commands_string, ST_DICE* st_ap_dice)
{
	S4 s4_t_commandIndex;

	/* Move the dice */
	for (s4_t_commandIndex = (S4)0; s4_t_commandIndex < st_ap_commands_string->s4_command_count; s4_t_commandIndex++)
	{
		(VD)vd_s_move_dice(st_ap_commands_string->u1_commands_string[s4_t_commandIndex], st_ap_dice);
	}

	return;
}

static VD vd_s_move_dice(U1 u1_ap_command_string[MAX_COMMAND_BYTES + 1], ST_DICE* st_ap_dice)
{
	S4 s4_t_command_index;
	S4 s4_t_isMatch;

	/* Excecute command. */
	for (s4_t_command_index = (S4)0; s4_t_command_index < (S4)NUM_KIND_OF_COMMAND; s4_t_command_index++)
	{
		s4_t_isMatch = strcmp(u1_ap_command_string, st_c_command[s4_t_command_index].u1_command_string);
		if (s4_t_isMatch == (S4)0)
		{
			st_c_command[s4_t_command_index].st_command_func(st_ap_dice);
		}
	}
	return;
}

static VD vd_s_North(ST_DICE* st_ap_dice)
{
	S4 s4_t_temp;
	s4_t_temp = st_ap_dice->s4_north;
	st_ap_dice->s4_north = st_ap_dice->s4_top;
	st_ap_dice->s4_top = st_ap_dice->s4_south;
	st_ap_dice->s4_south = st_ap_dice->s4_bottom;
	st_ap_dice->s4_bottom = s4_t_temp;
}

static VD vd_s_East(ST_DICE* st_ap_dice)
{
	S4 s4_t_temp;
	s4_t_temp = st_ap_dice->s4_east;
	st_ap_dice->s4_east = st_ap_dice->s4_top;
	st_ap_dice->s4_top = st_ap_dice->s4_west;
	st_ap_dice->s4_west = st_ap_dice->s4_bottom;
	st_ap_dice->s4_bottom = s4_t_temp;
}

static VD vd_s_West(ST_DICE* st_ap_dice)
{
	S4 s4_t_temp;
	s4_t_temp = st_ap_dice->s4_west;
	st_ap_dice->s4_west = st_ap_dice->s4_top;
	st_ap_dice->s4_top = st_ap_dice->s4_east;
	st_ap_dice->s4_east = st_ap_dice->s4_bottom;
	st_ap_dice->s4_bottom = s4_t_temp;
}

static VD vd_s_South(ST_DICE* st_ap_dice)
{
	S4 s4_t_temp;
	s4_t_temp = st_ap_dice->s4_south;
	st_ap_dice->s4_south = st_ap_dice->s4_top;
	st_ap_dice->s4_top = st_ap_dice->s4_north;
	st_ap_dice->s4_north = st_ap_dice->s4_bottom;
	st_ap_dice->s4_bottom = s4_t_temp;

}

static VD vd_s_Right(ST_DICE* st_ap_dice)
{
	S4 s4_t_temp;
	s4_t_temp = st_ap_dice->s4_north;
	st_ap_dice->s4_north = st_ap_dice->s4_west;
	st_ap_dice->s4_west = st_ap_dice->s4_south;
	st_ap_dice->s4_south = st_ap_dice->s4_east;
	st_ap_dice->s4_east = s4_t_temp;
}

static VD vd_s_Left(ST_DICE* st_ap_dice)
{
	S4 s4_t_temp;
	s4_t_temp = st_ap_dice->s4_north;
	st_ap_dice->s4_north = st_ap_dice->s4_east;
	st_ap_dice->s4_east = st_ap_dice->s4_south;
	st_ap_dice->s4_south = st_ap_dice->s4_west;
	st_ap_dice->s4_west = s4_t_temp;
}

static VD vd_s_create_dice(ST_DICE* st_ap_dice)
{
	S4 s4_t_index_dice_number;
	S4 s4_t_dice_nubmers[NUM_FACE_OF_DICE + 1];

	/* Input the dice numbers. */
	for (s4_t_index_dice_number = (S4)1; s4_t_index_dice_number <= (S4)NUM_FACE_OF_DICE; s4_t_index_dice_number++)
	{
		(VD)scanf("%d", &(s4_t_dice_nubmers[s4_t_index_dice_number]));
		(void)getchar();
	}
	st_ap_dice->s4_top = s4_t_dice_nubmers[1];
	st_ap_dice->s4_south = s4_t_dice_nubmers[2];
	st_ap_dice->s4_east = s4_t_dice_nubmers[3];
	st_ap_dice->s4_west = s4_t_dice_nubmers[4];
	st_ap_dice->s4_north = s4_t_dice_nubmers[5];
	st_ap_dice->s4_bottom = s4_t_dice_nubmers[6];
}



Measured memory_bytes: 2100