# -*- coding: utf-8 -*-



N = int(eval(input()))



values = [0]*N

value_count_map = {}

max_value = 0

next_max_value = max_value



for i in range(N):

    in_value = int(eval(input()))

    values[i] = in_value

    value_count = 0

    if in_value in value_count_map:

        value_count = value_count_map[in_value]

    value_count_map[in_value] = value_count + 1



    if in_value > max_value:

        next_max_value = max_value

        max_value = in_value

    elif in_value > next_max_value:

        next_max_value = in_value



max_value_count = value_count_map[max_value]



for row in range(N):

    if values[row] == max_value and max_value_count == 1:

        print(next_max_value)

    else:

        print(max_value)

# -*- coding: utf-8 -*-



N = int(eval(input()))



values = [0]*N

max_value_count = 0

max_value = 0

next_max_value = max_value



for i in range(N):

    in_value = int(eval(input()))

    values[i] = in_value



    if in_value == max_value:

        max_value_count = max_value_count + 1

    elif in_value > max_value:

        next_max_value = max_value

        max_value = in_value

        max_value_count = 1

    elif in_value > next_max_value:

        next_max_value = in_value



for row in range(N):

    if values[row] == max_value and max_value_count == 1:

        print(next_max_value)

    else:

        print(max_value)

# -*- coding: utf-8 -*-
N = int(eval(input()))
values = [0] * N
value_count_map = {}
max_value = 0
next_max_value = max_value
for i in range(N):
    in_value = int(eval(input()))
    values[i] = in_value
    value_count = 0
    if in_value in value_count_map:
        value_count = value_count_map[in_value]
    value_count_map[in_value] = value_count + 1
    if in_value > max_value:
        next_max_value = max_value
        max_value = in_value
    elif in_value > next_max_value:
        next_max_value = in_value
max_value_count = value_count_map[max_value]
for row in range(N):
    if values[row] == max_value and max_value_count == 1:
        print(next_max_value)
    else:
        print(max_value)

# -*- coding: utf-8 -*-
N = int(eval(input()))
values = [0] * N
max_value_count = 0
max_value = 0
next_max_value = max_value
for i in range(N):
    in_value = int(eval(input()))
    values[i] = in_value
    if in_value == max_value:
        max_value_count = max_value_count + 1
    elif in_value > max_value:
        next_max_value = max_value
        max_value = in_value
        max_value_count = 1
    elif in_value > next_max_value:
        next_max_value = in_value
for row in range(N):
    if values[row] == max_value and max_value_count == 1:
        print(next_max_value)
    else:
        print(max_value)

-value_count_map = {} +max_value_count = 0 -    value_count = 0 -    if in_value in value_count_map: -        value_count = value_count_map[in_value] -    value_count_map[in_value] = value_count + 1 -    if in_value > max_value: +    if in_value == max_value: +        max_value_count = max_value_count + 1 +    elif in_value > max_value: +        max_value_count = 1 -max_value_count = value_count_map[max_value]