n = int(eval(input()))

li = [0]*n

for i in range(n):

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

a = 0

b = 0



for i in li:

    if i > a:

        b = a

        a = i

    elif i > b:

        b = i



for i in li:

    if i == a:

        print(b)

    else:

        print(a)

import sys

input = sys.stdin.readline



n = int(eval(input()))

li = [0]*n

for i in range(n):

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

a = 0

b = 0



for i in li:

    if i > a:

        b = a

        a = i

    elif i > b:

        b = i



for i in li:

    if i == a:

        print(b)

    else:

        print(a)

n = int(eval(input()))
li = [0] * n
for i in range(n):
    li[i] = int(eval(input()))
a = 0
b = 0
for i in li:
    if i > a:
        b = a
        a = i
    elif i > b:
        b = i
for i in li:
    if i == a:
        print(b)
    else:
        print(a)

import sys

input = sys.stdin.readline
n = int(eval(input()))
li = [0] * n
for i in range(n):
    li[i] = int(eval(input()))
a = 0
b = 0
for i in li:
    if i > a:
        b = a
        a = i
    elif i > b:
        b = i
for i in li:
    if i == a:
        print(b)
    else:
        print(a)

+import sys + +input = sys.stdin.readline