#!/bin/python3 import sys # movements stored as position_name, xDif, yDif #movements = [('UL',(-1,-2)), # ('UR',(1,-2)), # ('R',(2,0)), # ('LR',(1,2)), # ('LL',(-1,2)), # ('L',(-2,0)) # ] #mov_str = [mov[0] for mov in movements] mov_str = ['UL','UR','R','LR','LL','L'] mov_positions = [(-1,-2),(1,-2),(2,0),(1,2),(-1,2),(-2,0)] #mov_positions = [mov[1] for mov in movements] def legal(i,j,n): return (i > -1 and i < n and j>-1 and j 0: if dx > 0 and i_start+2= 0): mov = 'LL' elif dx < 0 and i_start+2=0: mov = 'LL' elif dy < 0: if dx > 0 and i_start-2>=0 and j_start+1=0 and j_start+1=0 and j_start -1 >= 0): mov = 'UL' elif dx < 0: mov = 'UL' elif dy == 0: if dx > 0 and dx%2==0: mov = 'R' elif dx < 0 and dx%2==0: mov = 'L' if mov == '': impossible() #else: #print("Movement is ", mov) mov_pos = mov_positions[mov_str.index(mov)] new_i_pos = i_start + mov_pos[1] new_j_pos = j_start + mov_pos[0] #print("From ",i_start,',',j_start,' going to ',i_end,',',j_end,' through ',new_i_pos,',',new_j_pos) return mov, new_i_pos, new_j_pos def printShortestPath(n,i_start, j_start, i_end,j_end): reach = reachable(i_start, j_start, i_end, j_end) #print("Is reachable? ", reach) if reach: movements = [] while(not reached(i_start, j_start, i_end, j_end)): newMovement,new_i_starting_pos, new_j_starting_pos = move(n,i_start, j_start, i_end, j_end) movements.append(newMovement) i_start = new_i_starting_pos j_start = new_j_starting_pos if not legal(i_start, j_start,n): print("Thats illegal bro!") sys.exit() if (reached(i_start, j_start, i_end, j_end)): print(len(movements)) print( ' '.join(movements)) else: impossible() if __name__ == "__main__": n = int(input().strip()) i_start, j_start, i_end, j_end = input().strip().split(' ') i_start, j_start, i_end, j_end = [int(i_start), int(j_start), int(i_end), int(j_end)] printShortestPath(n, i_start, j_start, i_end, j_end)