N = int(eval(input()))

arr = [0] * N

for i in range(N):

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



sorted_list = sorted(arr)

max = sorted_list[N-1]

sub_max = sorted_list[N-2]

max_count = arr.count(max)



if max_count == 1:

    max_index = arr.index(max)

    for i in range(N):

        if i == max_index:

            print(sub_max)

        else:

            print(max)

else:

    for _ in range(N):

        print(max)



N = int(eval(input()))

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

arr2 = sorted(arr)

max1 = arr2[-1]

max2 = arr2[-2]

for i in range(N):

    if arr[i] == max1:

        print(max2)

    else:

        print(max1)
N = int(eval(input()))
arr = [0] * N
for i in range(N):
    arr[i] = int(eval(input()))
sorted_list = sorted(arr)
max = sorted_list[N - 1]
sub_max = sorted_list[N - 2]
max_count = arr.count(max)
if max_count == 1:
    max_index = arr.index(max)
    for i in range(N):
        if i == max_index:
            print(sub_max)
        else:
            print(max)
else:
    for _ in range(N):
        print(max)

N = int(eval(input()))
arr = [int(eval(input())) for _ in range(N)]
arr2 = sorted(arr)
max1 = arr2[-1]
max2 = arr2[-2]
for i in range(N):
    if arr[i] == max1:
        print(max2)
    else:
        print(max1)

-arr = [0] * N +arr = [int(eval(input())) for _ in range(N)] +arr2 = sorted(arr) +max1 = arr2[-1] +max2 = arr2[-2] -    arr[i] = int(eval(input())) -sorted_list = sorted(arr) -max = sorted_list[N - 1] -sub_max = sorted_list[N - 2] -max_count = arr.count(max) -if max_count == 1: -    max_index = arr.index(max) -    for i in range(N): -        if i == max_index: -            print(sub_max) -        else: -            print(max) -else: -    for _ in range(N): -        print(max) +    if arr[i] == max1: +        print(max2) +    else: +        print(max1)