N=int(eval(input()))

A=[]

for i in range(N):

    A.append(int(eval(input())))

R=[]

max_ = 0

for i in range(N):

    max_ = max(max_, A[i])

    R.append(max_)

L=[]

max_ = 0

for i in reversed(list(range(N))):

    max_ = max(max_, A[i])

    L.append(max_)

L = list(reversed(L))

print((L[1]))

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

    print((max(R[i-1], L[i+1])))

print((R[N-2]))
n=int(eval(input()))

max1 = 0

max2 = 0

A=[]

for _ in range(n):

    num = int(eval(input()))

    if num == max(num, max1):

        max2 = max1

        max1 = num

    elif num == max(num, max2):

        max2 = num

    A.append(num)

for a in A:

    if a == max1:

        print(max2)

    else:

        print(max1)
N = int(eval(input()))
A = []
for i in range(N):
    A.append(int(eval(input())))
R = []
max_ = 0
for i in range(N):
    max_ = max(max_, A[i])
    R.append(max_)
L = []
max_ = 0
for i in reversed(list(range(N))):
    max_ = max(max_, A[i])
    L.append(max_)
L = list(reversed(L))
print((L[1]))
for i in range(1, N - 1):
    print((max(R[i - 1], L[i + 1])))
print((R[N - 2]))

n = int(eval(input()))
max1 = 0
max2 = 0
A = []
for _ in range(n):
    num = int(eval(input()))
    if num == max(num, max1):
        max2 = max1
        max1 = num
    elif num == max(num, max2):
        max2 = num
    A.append(num)
for a in A:
    if a == max1:
        print(max2)
    else:
        print(max1)

-N = int(eval(input())) +n = int(eval(input())) +max1 = 0 +max2 = 0 -for i in range(N): -    A.append(int(eval(input()))) -R = [] -max_ = 0 -for i in range(N): -    max_ = max(max_, A[i]) -    R.append(max_) -L = [] -max_ = 0 -for i in reversed(list(range(N))): -    max_ = max(max_, A[i]) -    L.append(max_) -L = list(reversed(L)) -print((L[1])) -for i in range(1, N - 1): -    print((max(R[i - 1], L[i + 1]))) -print((R[N - 2])) +for _ in range(n): +    num = int(eval(input())) +    if num == max(num, max1): +        max2 = max1 +        max1 = num +    elif num == max(num, max2): +        max2 = num +    A.append(num) +for a in A: +    if a == max1: +        print(max2) +    else: +        print(max1)