#include #include #include #include #include #include #include void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { // Print the distance along with the sequence of moves. int ti, tj, d, moves; char *s = malloc( sizeof(char) * 3*n ); ti = i_start; tj = j_start; moves = 0; int status = 1; while( 1 ) { if( ti < 0 || ti >= n || tj < 0 || tj >= n ) { printf( "Impossible" ); status = 0; break; } else if( ti > i_end ) { if( tj <= j_end ) { strcat( s, "UR " ); ti = ti - 2; tj = tj + 1; ++moves; } if( tj > j_end ) { strcat( s, "UL " ); ti = ti - 2; tj = tj - 1; ++moves; } } else if( ti < i_end ) { if( tj <= j_end ) { strcat( s, "LR " ); ti = ti + 2; tj = tj + 1; ++moves; } if( tj > j_end ) { strcat( s, "LL " ); ti = ti + 2; tj = tj - 1; ++moves; } } else if( ti == i_end ) { d = tj - j_end; if( d % 2 != 0 ) { printf( "Impossible" ); status = 0; break; } else if( d < 0 ) { strcat( s, "R " ); tj = tj + 2; ++moves; } else if( d > 0 ) { strcat( s, "L " ); tj = tj - 2; ++moves; } else if( d == 0) { break; } } } if( status == 1 ) { printf( "%d\n", moves ); printf( "%s\n", s ); } } int main() { int n; scanf("%i", &n); int i_start; int j_start; int i_end; int j_end; scanf("%i %i %i %i", &i_start, &j_start, &i_end, &j_end); printShortestPath(n, i_start, j_start, i_end, j_end); return 0; }