N=int(eval(input()))

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

max_val1=sorted(A)[-1]

max_val2=sorted(A)[-2]

for x in A:

  print((max_val2 if x==max_val1 else max_val1))

N=int(eval(input()))

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



lmax=[0]*N

rmax=[0]*N



for i in range(1,N):

  lmax[i]=max(lmax[i-1],A[i-1])

for i in range(N-2,-1,-1):

  rmax[i]=max(rmax[i+1],A[i+1])



for i in range(N):

  print((max(lmax[i],rmax[i])))

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
max_val1 = sorted(A)[-1]
max_val2 = sorted(A)[-2]
for x in A:
    print((max_val2 if x == max_val1 else max_val1))

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
lmax = [0] * N
rmax = [0] * N
for i in range(1, N):
    lmax[i] = max(lmax[i - 1], A[i - 1])
for i in range(N - 2, -1, -1):
    rmax[i] = max(rmax[i + 1], A[i + 1])
for i in range(N):
    print((max(lmax[i], rmax[i])))

-A = [int(eval(input())) for i in range(N)] -max_val1 = sorted(A)[-1] -max_val2 = sorted(A)[-2] -for x in A: -    print((max_val2 if x == max_val1 else max_val1)) +A = [int(eval(input())) for _ in range(N)] +lmax = [0] * N +rmax = [0] * N +for i in range(1, N): +    lmax[i] = max(lmax[i - 1], A[i - 1]) +for i in range(N - 2, -1, -1): +    rmax[i] = max(rmax[i + 1], A[i + 1]) +for i in range(N): +    print((max(lmax[i], rmax[i])))