package main import "fmt" import "strings" var n, iS, jS, iF, jF int var offsets = []struct{ name string i, j int }{ {"UL", -2, -1}, {"UR", -2, 1}, {"R", 0, 2}, {"LR", 2, 1}, {"LL", 2, -1}, {"L", 0, -2}, } var results []string type qElem struct { path []string visited map[int]bool i,j int next, prev *qElem } var qHead, qTail *qElem func newVisited(visit int, visited map[int]bool) map[int]bool { res := make(map[int]bool) for k, v := range visited { res[k] = v } res[visit] = true return res } func main() { fmt.Scan(&n, &iS, &jS, &iF, &jF) qHead = &qElem{nil, make(map[int]bool), iS, jS, nil, nil} qTail = qHead for qHead != nil { elem := qHead qHead = qHead.next if qHead == nil { qTail = nil } //fmt.Printf("%v\n %v\n %v\n", elem, qHead, qTail) if elem.i == iF && elem.j == jF { results = elem.path break } vPos := elem.i << 32 | elem.j if elem.visited[vPos] { continue } visited := newVisited(vPos, elem.visited) for _, d := range offsets { nextI := elem.i + d.i nextJ := elem.j + d.j if nextI >=0 && nextI < n && nextJ >=0 && nextJ < n { newElem := &qElem{append(elem.path, d.name), visited, nextI, nextJ, nil, nil} if qTail == nil { qTail = newElem qHead = qTail } else { newElem.prev = qTail qTail.next = newElem qTail = newElem } } } } if results == nil { fmt.Printf("Impossible") } else { fmt.Printf("%d\n%s", len(results), strings.Join(results, " ")) } }