n=int(input())

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

b=sorted(a)

ans=[b[-1]]*n

ans[a.index(b[-1])]=b[-2]

print(*ans,sep="\n")

from copy import deepcopy

n,*a=list(map(int,open(0).read().split()))

b=deepcopy(a)

b.sort()

c=b[-1]

for i in a:

    if i==b[-1]:

        print((b[-2]))

    else:

        print(c)
n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)
ans = [b[-1]] * n
ans[a.index(b[-1])] = b[-2]
print(*ans, sep="\n")

from copy import deepcopy

n, *a = list(map(int, open(0).read().split()))
b = deepcopy(a)
b.sort()
c = b[-1]
for i in a:
    if i == b[-1]:
        print((b[-2]))
    else:
        print(c)

-n = int(input()) -a = [int(input()) for _ in range(n)] -b = sorted(a) -ans = [b[-1]] * n -ans[a.index(b[-1])] = b[-2] -print(*ans, sep="\n") +from copy import deepcopy + +n, *a = list(map(int, open(0).read().split())) +b = deepcopy(a) +b.sort() +c = b[-1] +for i in a: +    if i == b[-1]: +        print((b[-2])) +    else: +        print(c)