N = int(input())
A = [input() for i in range(N)]
ans = 0
wk = A[:]
Max1 = max(A)
wk.remove(Max1)
Max2 = max(wk)
wk.clear()
indexes = [i for i, x in enumerate(A) if x == Max1]
for i in range(N):
    ans = Max2 if len(indexes) < 2 and A[i] == Max1 else Max1
    print(ans)