import copy
N = int(input())
As = []
for i in range(N):
    As.append(int(input()))
for j in range(N):
    instAs = copy.copy(As)
    instAs.pop(j)
    print(max(instAs))import copy
N = int(input())
As = []
for i in range(N):
    As.append(int(input()))
maxA = max(As)
instA = As.copy()
instA.remove(maxA)
secA = max(instA)
for i in range(N):
    if As[i] == maxA:
        print(secA)
    else:
        print(maxA)