a = int(eval(input()))

b = [int(eval(input())) for _ in range(a)]

c = [0] * a

c[0] = b[0]

c[1] = max(b[1], c[0])

d = [0] * a

d[0] = b[-1]

d[1] = max(b[-2], d[0])

for i in range(2, len(b)):

    c[i] = max(c[i-1], b[i])

    d[i] = max(d[i-1], b[-i-1])

c.insert(0, 0)

d.insert(0, 0)

for i in range(len(c)-1):

    print((max(c[i], d[-i-2])))

a = int(eval(input()))

b = [int(eval(input())) for _ in range(a)]

c = b.copy()

c = sorted(c, reverse=True)

for i in b:

    if i == c[0]:

        print((c[1]))

    else:

        print((c[0]))

a = int(eval(input()))
b = [int(eval(input())) for _ in range(a)]
c = [0] * a
c[0] = b[0]
c[1] = max(b[1], c[0])
d = [0] * a
d[0] = b[-1]
d[1] = max(b[-2], d[0])
for i in range(2, len(b)):
    c[i] = max(c[i - 1], b[i])
    d[i] = max(d[i - 1], b[-i - 1])
c.insert(0, 0)
d.insert(0, 0)
for i in range(len(c) - 1):
    print((max(c[i], d[-i - 2])))

a = int(eval(input()))
b = [int(eval(input())) for _ in range(a)]
c = b.copy()
c = sorted(c, reverse=True)
for i in b:
    if i == c[0]:
        print((c[1]))
    else:
        print((c[0]))

-c = [0] * a -c[0] = b[0] -c[1] = max(b[1], c[0]) -d = [0] * a -d[0] = b[-1] -d[1] = max(b[-2], d[0]) -for i in range(2, len(b)): -    c[i] = max(c[i - 1], b[i]) -    d[i] = max(d[i - 1], b[-i - 1]) -c.insert(0, 0) -d.insert(0, 0) -for i in range(len(c) - 1): -    print((max(c[i], d[-i - 2]))) +c = b.copy() +c = sorted(c, reverse=True) +for i in b: +    if i == c[0]: +        print((c[1])) +    else: +        print((c[0]))