open System let checkPossibility ((ex: int), (ey: int)) (sx, sy) = if Math.Abs(ex - sx) % 2 = 0 && (Math.Abs(ey - sy) + ((Math.Abs(ex - sx) / 2) % 2)) % 2 = 0 then true else false let solveChess n (ex, ey) startPos = let possible = checkPossibility (ex, ey) startPos if possible then let mutable has = false let mutable way = [] let rec movePiece (lx, ly) pos (visited: string list) (moves: Set<(int * int)>) = match pos with | (a, b) when a < 0 || b < 0 || a >= n || b >= n || Set.contains (a, b) moves -> () | (a, b) when Math.Abs(lx - ex) - Math.Abs(a - ex) < -1 || Math.Abs(ly - ey) - Math.Abs(b - ey) < -1 -> () | (a, b) when a = ex && b = ey -> if not has || way.Length > visited.Length then has <- true way <- visited | (a, b) -> movePiece (a, b) (a-2, b-1) ("UL"::visited) <| Set.add (a,b) moves movePiece (a, b) (a-2, b+1) ("UR"::visited) <| Set.add (a,b) moves movePiece (a, b) (a, b+2) ("R"::visited) <| Set.add (a,b) moves movePiece (a, b) (a+2, b+1) ("LR"::visited) <| Set.add (a,b) moves movePiece (a, b) (a+2, b-1) ("LL"::visited) <| Set.add (a,b) moves movePiece (a, b) (a, b-2) ("L"::visited) <| Set.add (a,b) moves movePiece startPos startPos [] Set.empty if has then printfn "%d" way.Length printfn "%s" <| (way |> List.rev |> List.reduce (fun a b -> a + " " + b)) else printfn "Impossible" else printfn "Impossible" [] let main argv = let n = Console.ReadLine() |> int let xs = Console.ReadLine().Split(' ') |> Array.map int let startPos = (xs.[0], xs.[1]) let endPos = (xs.[2], xs.[3]) solveChess n endPos startPos Console.ReadLine() |> ignore 0 // return an integer exit code