N = int(eval(input()))

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



ans = []

front_max_list, back_max_list = [0], [0]



for i in range(N):

    front_max_list.append(max(front_max_list[i], A[i]))

    back_max_list.append(max(back_max_list[i], A[N - i - 1]))



for i in range(N):

    print((max(front_max_list[i], back_max_list[N - i - 1])))

N = int(eval(input()))

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



A_ = sorted(A.copy(), reverse=True)

max_num = [A_[0], A_[1]]



for i in range(N):

    if A[i] != max_num[0]:

        print((max_num[0]))

    else:

        print((max_num[1]))

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
ans = []
front_max_list, back_max_list = [0], [0]
for i in range(N):
    front_max_list.append(max(front_max_list[i], A[i]))
    back_max_list.append(max(back_max_list[i], A[N - i - 1]))
for i in range(N):
    print((max(front_max_list[i], back_max_list[N - i - 1])))

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A_ = sorted(A.copy(), reverse=True)
max_num = [A_[0], A_[1]]
for i in range(N):
    if A[i] != max_num[0]:
        print((max_num[0]))
    else:
        print((max_num[1]))

-ans = [] -front_max_list, back_max_list = [0], [0] +A_ = sorted(A.copy(), reverse=True) +max_num = [A_[0], A_[1]] -    front_max_list.append(max(front_max_list[i], A[i])) -    back_max_list.append(max(back_max_list[i], A[N - i - 1])) -for i in range(N): -    print((max(front_max_list[i], back_max_list[N - i - 1]))) +    if A[i] != max_num[0]: +        print((max_num[0])) +    else: +        print((max_num[1]))