import sys

from operator import itemgetter



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





def main():

    N, *A = map(int, read().split())

    

    B = [(i, a) for i, a in enumerate(A)]

    B.sort(key=itemgetter(1))

    ans = [0] * N

    for i, a in B[:-1]:

        ans[i] = B[-1][1]

        

    ans[B[-1][0]] = B[-2][1]

    

    print(*ans, sep='\n')

    

    return





if __name__ == '__main__':

    main()

import sys

from operator import itemgetter



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





def main():

    N, *A = list(map(int, read().split()))



    a_max = max(A)

    max_count = A.count(a_max)

    for a in A:

        if a != a_max:

            print(a_max)

        elif max_count > 1:

            print(a_max)

        else:

            B = A[:]

            B.remove(a_max)

            print((max(B)))



    return





if __name__ == '__main__':

    main()

import sys
from operator import itemgetter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    B = [(i, a) for i, a in enumerate(A)]
    B.sort(key=itemgetter(1))
    ans = [0] * N
    for i, a in B[:-1]:
        ans[i] = B[-1][1]
    ans[B[-1][0]] = B[-2][1]
    print(*ans, sep="\n")
    return


if __name__ == "__main__":
    main()

import sys
from operator import itemgetter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = list(map(int, read().split()))
    a_max = max(A)
    max_count = A.count(a_max)
    for a in A:
        if a != a_max:
            print(a_max)
        elif max_count > 1:
            print(a_max)
        else:
            B = A[:]
            B.remove(a_max)
            print((max(B)))
    return


if __name__ == "__main__":
    main()

-    N, *A = map(int, read().split()) -    B = [(i, a) for i, a in enumerate(A)] -    B.sort(key=itemgetter(1)) -    ans = [0] * N -    for i, a in B[:-1]: -        ans[i] = B[-1][1] -    ans[B[-1][0]] = B[-2][1] -    print(*ans, sep="\n") +    N, *A = list(map(int, read().split())) +    a_max = max(A) +    max_count = A.count(a_max) +    for a in A: +        if a != a_max: +            print(a_max) +        elif max_count > 1: +            print(a_max) +        else: +            B = A[:] +            B.remove(a_max) +            print((max(B)))