Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in

    let rec loop acc =
        let step2 q =
            if q = 0 then acc else (
                let rec loop2 i acc =
                    if i = n then loop acc else
                        let c = a.(i) / n in
                        let () = a.(i) <- a.(i) - c * n + q - c in
                        loop2 (i + 1) (acc + c)
                in
                loop2 0 acc
            )
        in
        let rec loop2 i q =
            if i = n then step2 q else loop2 (i + 1) (q + a.(i) / n)
        in
        loop2 0 0
    in
    loop 0 |> Printf.printf "%d\n"
)