n=gets.to_i
a=Array.new(n)
for i in 0...n
    a[i]=gets.to_i
end

left=Array.new(n)
right=Array.new(n)

left[0]=a[0]
for i in 1...n
    left[i]=[left[i-1],a[i]].max
end

right[n-1]=a[n-1]
for i in (0...n-1).reverse_each
    right[i]=[right[i+1],a[i]].max
end

for i in 0...n
    if i==0
        p right[i+1]
    elsif i==n-1
        p left[n-2]
    else
        p [left[i-1],right[i+1]].max
    end
end