N = int(eval(input()))



A = [0]*N



for i in range(N):

    A[i] = int(eval(input()))

    

    

a = sorted(A)



Max = a[len(a)-1]

PreMax = a[len(a)-2]



for i in range(N):

    

    if A[i] < Max:

        print(Max)

    else:

        print(PreMax)
N  = int(eval(input()))

A=[0] * N



for i in range(N):

    A[i] = int(eval(input()))



right = [0]

left =[0]



for a in A:

    left.append(max(a,left[-1]))

    

for a in reversed(A):

    right.append(max(a,right[-1]))



    

for i in range(N):

    ans = max(left[i], right[N-i-1] )

    print(ans)

N = int(eval(input()))
A = [0] * N
for i in range(N):
    A[i] = int(eval(input()))
a = sorted(A)
Max = a[len(a) - 1]
PreMax = a[len(a) - 2]
for i in range(N):
    if A[i] < Max:
        print(Max)
    else:
        print(PreMax)

N = int(eval(input()))
A = [0] * N
for i in range(N):
    A[i] = int(eval(input()))
right = [0]
left = [0]
for a in A:
    left.append(max(a, left[-1]))
for a in reversed(A):
    right.append(max(a, right[-1]))
for i in range(N):
    ans = max(left[i], right[N - i - 1])
    print(ans)

-a = sorted(A) -Max = a[len(a) - 1] -PreMax = a[len(a) - 2] +right = [0] +left = [0] +for a in A: +    left.append(max(a, left[-1])) +for a in reversed(A): +    right.append(max(a, right[-1])) -    if A[i] < Max: -        print(Max) -    else: -        print(PreMax) +    ans = max(left[i], right[N - i - 1]) +    print(ans)