open System let InRange ll ul i j = ( ll <= i ) && ( i < ul ) && ( ll <= j ) && ( j < ul ) type Sol() = member this.Solve() = let N = stdin.ReadLine() |> int let dx = [1;0;-1;0] let dy = [0;1;0;-1] let rec f i j t n (a:int [] [] ) = // printfn "%d %d %d %d" i j t n if a.[i].[j] <> 0 then () else a.[i].[j] <- n let ny = i + dy.[t] let nx = j + dx.[t] if (InRange 0 N ny nx) && (a.[ny].[nx] = 0) then f ny nx t (n+1) a else f (i + dy.[(t+1)%4]) (j + dx.[(t+1)%4]) ((t+1)%4) (n+1) a let A = Array.zeroCreate N for i = 0 to (N-1) do A.[i] <- Array.zeroCreate N f 0 0 0 1 A for i = 0 to (N-1) do String.Join(" ", (A.[i] |> Array.map (sprintf "%03d"))) |> printfn "%s" () let mySol = new Sol() mySol.Solve()