n = int(eval(input()))

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



l = 0

L = [l]

for a in A:

    l = max(l, a)

    L.append(l)



r = 0

R = [r]

for a in A[::-1]:

    r = max(r, a)

    R.append(r)

R.reverse()



for i in range(n):

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

n = int(eval(input()))

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

A_ = sorted(A, reverse=True)

a0, a1 = A_[0], A_[1]

for a in A:

    if a == a0:

        print(a1)

    else:

        print(a0)

n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]
l = 0
L = [l]
for a in A:
    l = max(l, a)
    L.append(l)
r = 0
R = [r]
for a in A[::-1]:
    r = max(r, a)
    R.append(r)
R.reverse()
for i in range(n):
    print((max(L[i], R[i + 1])))

n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]
A_ = sorted(A, reverse=True)
a0, a1 = A_[0], A_[1]
for a in A:
    if a == a0:
        print(a1)
    else:
        print(a0)

-l = 0 -L = [l] +A_ = sorted(A, reverse=True) +a0, a1 = A_[0], A_[1] -    l = max(l, a) -    L.append(l) -r = 0 -R = [r] -for a in A[::-1]: -    r = max(r, a) -    R.append(r) -R.reverse() -for i in range(n): -    print((max(L[i], R[i + 1]))) +    if a == a0: +        print(a1) +    else: +        print(a0)