let read_n () = Scanf.scanf "%d " (fun i -> i)

let () =
  let n = read_n () in
  let a = Array.init n (fun _ -> read_n ()) in
  let rec doit v =
    Array.fast_sort (-) a;
    if a.(n-1) < n then v
    else if a.(0) >= n then begin
      let d = a.(0) - (n - 1) in
      for i = 0 to n - 1 do a.(i) <- a.(i) - d done;
      doit (v + d * n)
    end else begin
      let d = a.(n-1) / n in
      for i = 0 to n - 2 do a.(i) <- a.(i) + d done;
      a.(n-1) <- a.(n-1) mod n;
      doit (v + d)
    end in
  doit 0 |> Printf.printf "%d\n"