n = int(input())
arr = [int(input()) for i in range(n)]

numset = set(arr)
maxval = max(numset)

if len(numset) == 1:
    for i in range(n):
        print(maxval)
else:
    numset.remove(maxval)
    semimax = max(numset)
    for i in range(n):
        if arr[i] == maxval and not arr[i] in arr:
            print(semimax)
        else:
            print(maxval)