n = int(eval(input()))

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

sorted_a_list = sorted(a_list)

max_num = sorted_a_list[-1]

second_max_num = sorted_a_list[-2]



result = [0]*n

for i in range(n):

    if a_list[i] == max_num:

        result[i] = second_max_num

    else:

        result[i] = max_num



for i in range(n):

    print((result[i]))
import sys

from collections import defaultdict

from heapq import *

sys.setrecursionlimit(10**8)



input = sys.stdin.readline



def main():

    """ main """

    N = int(eval(input()))

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

    AS_dup = AS[:]

    AS.sort()

    for i in range(N):

        if AS_dup[i] == AS[-1]:

            print((AS[-2]))

        else:

            print((AS[-1]))





if __name__ == '__main__':

    main()
n = int(eval(input()))
a_list = [int(eval(input())) for _ in range(n)]
sorted_a_list = sorted(a_list)
max_num = sorted_a_list[-1]
second_max_num = sorted_a_list[-2]
result = [0] * n
for i in range(n):
    if a_list[i] == max_num:
        result[i] = second_max_num
    else:
        result[i] = max_num
for i in range(n):
    print((result[i]))

import sys
from collections import defaultdict
from heapq import *

sys.setrecursionlimit(10**8)
input = sys.stdin.readline


def main():
    """main"""
    N = int(eval(input()))
    AS = [int(eval(input())) for _ in range(N)]
    AS_dup = AS[:]
    AS.sort()
    for i in range(N):
        if AS_dup[i] == AS[-1]:
            print((AS[-2]))
        else:
            print((AS[-1]))


if __name__ == "__main__":
    main()

-n = int(eval(input())) -a_list = [int(eval(input())) for _ in range(n)] -sorted_a_list = sorted(a_list) -max_num = sorted_a_list[-1] -second_max_num = sorted_a_list[-2] -result = [0] * n -for i in range(n): -    if a_list[i] == max_num: -        result[i] = second_max_num -    else: -        result[i] = max_num -for i in range(n): -    print((result[i])) +import sys +from collections import defaultdict +from heapq import * + +sys.setrecursionlimit(10**8) +input = sys.stdin.readline + + +def main(): +    """main""" +    N = int(eval(input())) +    AS = [int(eval(input())) for _ in range(N)] +    AS_dup = AS[:] +    AS.sort() +    for i in range(N): +        if AS_dup[i] == AS[-1]: +            print((AS[-2])) +        else: +            print((AS[-1])) + + +if __name__ == "__main__": +    main()