#!/bin/python3 import sys # # def printShortestPath( # index limit n , row_i_start, col_j_start # goal|target position , row_i_end, col_j_end , is_DeBug_Mode = 1 == 0 ): """ Print the distance along with the sequence of moves. """ def is_Reachable_Row( start_Row_i: int , end_Row_i: int , is_DeBug_Mode: bool = 1 == 0 ) -> bool: """ helper """ return start_Row_i % 2 == end_Row_i % 2 # def is_Reachable_Cell_1( start_Row_i: int , start_Col_j: int , end_Row_i: int , end_Col_j: int , is_DeBug_Mode: bool = 1 == 1 ) -> bool: """!is_UnReachable_Cell_1( start_Row_i, start_Col_j, end_Row_i, end_Col_j ) """ return ( ( start_Row_i + 2 - end_Row_i ) % 4 != 0 or ( start_Col_j - end_Col_j ) % 2 != 0 ) # def is_Reachable_Cell_2( start_Row_i: int , start_Col_j: int , end_Row_i: int , end_Col_j: int , is_DeBug_Mode: bool = 1 == 1 ) -> bool: """!is_UnReachable_Cell_2( start_Row_i, start_Col_j, end_Row_i, end_Col_j ) """ return ( ( start_Row_i - end_Row_i ) % 4 != 0 or ( start_Col_j + 1 - end_Col_j ) % 2 != 0 ) # if ( is_Reachable_Row( row_i_start, row_i_end ) and is_Reachable_Cell_1( row_i_start, col_j_start, row_i_end, col_j_end ) and is_Reachable_Cell_2( row_i_start, col_j_start, row_i_end, col_j_end ) ): #pass moves = ( #( name, row, col _OffSet, description, ordinal ) ( "UL", -2, -1, "UpperLeft", 1 ) , ( "UR", 2, -1, "UpperRight", 2 ) , ( "R", 0, 2, "Right", 3 ) , ( "LR", 2, 1, "LowerRight", 4 ) , ( "LL", 2, -1,"LowerLeft", 5 ) , ( "L", 0, -2, "Left", 6 ) ) moves_Size = len( moves ) #moves_Max_i = len( moves ) - 1 min_Distance = 4 min_Path = "UL UL UL L" explored = { ( row_i_start, col_j_start ) }#set( ) in_Stack = set( )#{} stack = [#list() ( #moves[ 0 ] 0 , ( row_i_start, col_j_start ) # type: str ? because immutable , ""#list() , 0 ) ] loop_Guard = 200 * 100 # while ( len( stack ) > 0 and loop_Guard > 0 ): # loop_Guard -= 1 # pop last ( #move move_i , ( start_Row, start_Col ) # type: str ? , path , thier ) = stack.pop( ) # if start_Row == row_i_end and col_j_end == start_Col: # done stack.clear() # update min_Distance = thier#len( path ) min_Path = path.lstrip()#" ".join( map( str, path ) ) else: # continue BFS for m_i in range( move_i, moves_Size, 1 ): #move ( m_name, m_row_OffSet, m_col_OffSet #, description, ordinal , _, _ ) = moves[ m_i ] move_Row = start_Row + m_row_OffSet move_Col = start_Col + m_col_OffSet if is_DeBug_Mode and 1 == 1: print( "{:d}:{}( {:d}, {:d} ) vs. 0 and n:{:d}".format( m_i, m_name, move_Row, move_Col, n ) , file = sys.stderr ) # if 0 <= move_Row < n and 0 <= move_Col < n: # within board if is_DeBug_Mode and 1 == 1: print("\twithin board", file = sys.stderr ) # if ( move_Row, move_Col ) in explored: if is_DeBug_Mode and 1 == 1: print("\t\tin explored", file = sys.stderr ) else: if ( move_Row, move_Col ) in in_Stack: if is_DeBug_Mode and 1 == 1: print("\t\tin_Stack", file = sys.stderr ) else: in_Stack.add( ( move_Row, move_Col ) ) stack.append( ( m_i , ( move_Row, move_Col ) , path + " " + m_name , thier + 1 ) ) else: # out of board # skip if is_DeBug_Mode and 1 == 1: print("\tout of board", file = sys.stderr ) # update explored.add( ( start_Row, start_Col ) ) # print( min_Distance ) print( min_Path ) else: print( "Impossible" ) # return None # if __name__ == "__main__": # is_DeBug_Mode = 1 == 0 n = int( input().strip() ) ( i_start, j_start, i_end, j_end ) = map( int, input().strip().split(' ') ) #( i_start, j_start, i_end, j_end ) = [ # int( i_start ), int( j_start ), int( i_end ), int( j_end ) #] if is_DeBug_Mode and 1 == 1: print( "n:{:d}, i_start:{:d}, j_start:{:d}, i_end:{:d}, j_end:{:d}".format( n, i_start, j_start, i_end, j_end ) , file = sys.stderr ) printShortestPath( n, i_start, j_start, i_end, j_end )