import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

long M;

long query(long[] A, long lhs, long rhs, long clhs, long crhs, long current = 1)
{
    if (lhs == rhs)
        return long.min;
    if (rhs <= clhs || crhs <= lhs)
        return long.min;
    if (lhs <= clhs && crhs <= rhs)
        return A[current];
    long m = (lhs + rhs) / 2;
    long cm = (clhs + crhs) / 2;
    long l = query(A, lhs, rhs, clhs, cm, current * 2);
    long r = query(A, lhs, rhs, cm, crhs, current * 2 + 1);
    return max(l, r);
}

void main()
{
    long N = lread();
    M = 2 ^^ (cast(long) ceil(log2(N)));
    auto A = new long[](2 * M);
    A[] = long.min;
    foreach (i; 0 .. N)
    {
        A[A.length - M + i] = lread();
    }
    foreach_reverse (d; 0 .. cast(long) ceil(log2(N)))
    {
        foreach (i; 0 .. 2 ^^ d)
        {
            long p = 2 ^^ d + i;
            A[p] = max(A[p * 2], A[p * 2 + 1]);
        }
    }
    foreach (i; 0 .. N)
    {
        writeln(query(A, 0, i, 0, M).max(query(A, i + 1, M, 0, M)));
    }
}
