[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let n = read int
    let xs = List.init n (fun _ -> read int)
    let bs = List.scan max 0 xs
    let cs = List.rev xs |> List.scan max 0 |> List.rev |> List.tail
    for i in Seq.map2 max bs cs do
        printfn "%i" i
    0