import sys

sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline

from itertools import permutations,  combinations, accumulate

from functools import *

from collections import deque, defaultdict, Counter

from heapq import heapify, heappop, heappush, heappushpop



INF = float('inf')

NIL = - 1





N = int(eval(input()))

A = [int(eval(input())) for _ in range(N)]



max_a = max(A)

max_idx = [i for i, x in enumerate(A) if x == max_a]



if len(max_idx) > 1:

    for i in range(N):

        print(max_a)

    exit()

else:

    for i in max_idx:

        A[i] = NIL

    second_max = max(A)



    for i in range(N):

        if i in max_idx:

            print(second_max)

        else:

            print(max_a)

import sys

sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline

from itertools import permutations,  combinations, accumulate

from functools import *

from collections import deque, defaultdict, Counter

from heapq import heapify, heappop, heappush, heappushpop



INF = float('inf')

NIL = - 1





N = int(eval(input()))

A = [int(eval(input())) for _ in range(N)]

sort_a = sorted(A, reverse=True)



for a in A:

    print((sort_a[0] if a != sort_a[0] else sort_a[1]))



# max_a = max(A)

# max_idx = [i for i, x in enumerate(A) if x == max_a]

#

# if len(max_idx) > 1:

#     for i in range(N):

#         print(max_a)

#     exit()

# else:

#     for i in max_idx:

#         A[i] = NIL

#     second_max = max(A)

#

#     for i in range(N):

#         if i in max_idx:

#             print(second_max)

#         else:

#             print(max_a)

import sys

sys.setrecursionlimit(10**9)
input = sys.stdin.readline
from itertools import permutations, combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float("inf")
NIL = -1
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
max_a = max(A)
max_idx = [i for i, x in enumerate(A) if x == max_a]
if len(max_idx) > 1:
    for i in range(N):
        print(max_a)
    exit()
else:
    for i in max_idx:
        A[i] = NIL
    second_max = max(A)
    for i in range(N):
        if i in max_idx:
            print(second_max)
        else:
            print(max_a)

import sys

sys.setrecursionlimit(10**9)
input = sys.stdin.readline
from itertools import permutations, combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float("inf")
NIL = -1
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
sort_a = sorted(A, reverse=True)
for a in A:
    print((sort_a[0] if a != sort_a[0] else sort_a[1]))
# max_a = max(A)
# max_idx = [i for i, x in enumerate(A) if x == max_a]
#
# if len(max_idx) > 1:
#     for i in range(N):
#         print(max_a)
#     exit()
# else:
#     for i in max_idx:
#         A[i] = NIL
#     second_max = max(A)
#
#     for i in range(N):
#         if i in max_idx:
#             print(second_max)
#         else:
#             print(max_a)

-max_a = max(A) -max_idx = [i for i, x in enumerate(A) if x == max_a] -if len(max_idx) > 1: -    for i in range(N): -        print(max_a) -    exit() -else: -    for i in max_idx: -        A[i] = NIL -    second_max = max(A) -    for i in range(N): -        if i in max_idx: -            print(second_max) -        else: -            print(max_a) +sort_a = sorted(A, reverse=True) +for a in A: +    print((sort_a[0] if a != sort_a[0] else sort_a[1])) +# max_a = max(A) +# max_idx = [i for i, x in enumerate(A) if x == max_a] +# +# if len(max_idx) > 1: +#     for i in range(N): +#         print(max_a) +#     exit() +# else: +#     for i in max_idx: +#         A[i] = NIL +#     second_max = max(A) +# +#     for i in range(N): +#         if i in max_idx: +#             print(second_max) +#         else: +#             print(max_a)