import math

N = int(input())
A = [int(input()) for i in range(N)]

B = list(set(sorted(A)))
print(B)

for i in range(N):
    if A[i] != B[-1]:
        print(B[-1])
    else:
        if B[0] != B[-1]:
            print(B[-2])
        else:
            print(B[0])
