local N = io.read("n")
local A = {}
for i=1,N do
    A[i] = io.read("n")
end
local max_ltoi = {}
local max_itor = {}
max_ltoi[0] = -1
max_itor[N+1] = -1
for i=1,N do
    max_ltoi[i] = math.max(max_ltoi[i-1], A[i])
end
for i=N,1,-1 do
    max_itor[i] = math.max(max_itor[i+1], A[i])
end
for i=1,N do
    local m = math.max(max_ltoi[i-1], max_itor[i+1])
    print(m)
end