let rec solve acc xs n = function
  | [] -> acc
  | y :: ys ->
      if y <= n - 1 then solve acc (y :: xs) n ys
      else
        let cost = y / n in
        solve (acc + cost) [] n (List.rev_append (List.map (( + ) cost) xs) (y mod n :: List.map (( + ) cost) ys))
let solve = solve 0 []

let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  solve n (Array.to_list as_)
  |> Printf.printf "%d\n"