let rec fix f x = f (fix f) x
let ans =
  Scanf.scanf "%d" @@ fun n ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let w0 =
    (0, min a.(0) a.(n-1) + 1) |> fix (fun f (l, r) ->
      if l+1 >= r then l else
        let m = (l+r) / 2 in
        let w = Array.fold_left (fun w h -> h - w) m a in
        if w < m then f (l, m) else f (m, r))
  in
  let wn, h' = Array.fold_left (fun (w, acc) h -> (h-w, (2*w)::acc)) (w0, []) a in
  List.rev h' |> List.iter (Printf.printf "%d ");
  print_newline ()
 