N = int(eval(input()))

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



k = max(list(range(N)), key=lambda i: A[i])

for i in range(N):

    if i != k:

        print((A[k]))

    else:

        print((

            max(

                max(A[:k], default=0),

                max(A[(k + 1):], default=0)

            )

        ))

N = int(eval(input()))

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



# 最大値をとるインデックスを求めておく

k = max(list(range(N)), key=lambda i: A[i])

ans = '\n'.join(

    str(

        max(A[:k] + A[k + 1:]) if i == k else

        A[k]

    )

    for i in range(N)

)



print(ans)

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
k = max(list(range(N)), key=lambda i: A[i])
for i in range(N):
    if i != k:
        print((A[k]))
    else:
        print((max(max(A[:k], default=0), max(A[(k + 1) :], default=0))))

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
# 最大値をとるインデックスを求めておく
k = max(list(range(N)), key=lambda i: A[i])
ans = "\n".join(str(max(A[:k] + A[k + 1 :]) if i == k else A[k]) for i in range(N))
print(ans)

+# 最大値をとるインデックスを求めておく -for i in range(N): -    if i != k: -        print((A[k])) -    else: -        print((max(max(A[:k], default=0), max(A[(k + 1) :], default=0)))) +ans = "\n".join(str(max(A[:k] + A[k + 1 :]) if i == k else A[k]) for i in range(N)) +print(ans)