main = interact $ unlines . map (show' . magic_square . read') . init . lines
 where
  read' n = replicate (read n) (replicate (read n) 0)
  show' = init . unlines . map (concat . map (justifyr 4 . show)) 

magic_square sq = add_number (center (length sq) + 1) (center (length sq)) 1 sq
 where center n = div n 2 + 1

add_number l c x sq
 | x > (length sq)^2 = sq
 | c > length sq = add_number l 1 x sq
 | c < 1 = add_number l (length sq) x sq
 | l > length sq = add_number 1 c x sq
 | sq!!(l-1)!!(c-1) /= 0 = add_number (succ l) (pred c) x sq
 | otherwise = add_number (succ l) (succ c) (succ x) (insert_number l c x sq)

insert_number l c x sq = let ls = replace c x (sq!!(l-1)) in replace l ls sq
replace i r xs = let (xs1,(x:xs2)) = splitAt (i-1) xs in xs1 ++ (r:xs2)
justifyr n = reverse . take n . (++ (replicate n ' ')) . reverse