#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]"):
    s = [A[0]] * (N)
    e = [A[N-1]] * (N)
    for i in range(1, N):
        s[i] = max(s[i-1], A[i])
    for i in reversed(range(0, N-1)):
        e[i] = max(e[i+i], A[i])

    for i in range(N):
        if i == 0:
            print(e[1])
        elif i == N-1:
            print(s[N-2])
        else:
            print(max(s[i-1], e[i+1]))
        
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()
