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

b = sorted(a)

max = b[-1]

maxs= b[-2]



for i in range(n):

    if a[i] == max:

        print(maxs)

    else:

        print(max)

def main():



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

    b = sorted(a)

    max = b[-1]

    maxs= b[-2]



    for i in range(n):

        if a[i] == max:

            print(maxs)

        else:

            print(max)

    return()



if __name__=='__main__':

    main()
n, *a = list(map(int, open(0).read().split()))
b = sorted(a)
max = b[-1]
maxs = b[-2]
for i in range(n):
    if a[i] == max:
        print(maxs)
    else:
        print(max)

def main():
    n, *a = list(map(int, open(0).read().split()))
    b = sorted(a)
    max = b[-1]
    maxs = b[-2]
    for i in range(n):
        if a[i] == max:
            print(maxs)
        else:
            print(max)
    return ()


if __name__ == "__main__":
    main()

-n, *a = list(map(int, open(0).read().split())) -b = sorted(a) -max = b[-1] -maxs = b[-2] -for i in range(n): -    if a[i] == max: -        print(maxs) -    else: -        print(max) +def main(): +    n, *a = list(map(int, open(0).read().split())) +    b = sorted(a) +    max = b[-1] +    maxs = b[-2] +    for i in range(n): +        if a[i] == max: +            print(maxs) +        else: +            print(max) +    return () + + +if __name__ == "__main__": +    main()