import sys

def input(): return sys.stdin.readline().strip()



def resolve():

    n=int(eval(input()))

    l=[int(eval(input())) for i in range(n)]

    biggest = max(l)

    lsort=sorted(l)

    niban=lsort[-2]

    for j in range(n):

        if l[j]!=biggest:

            print(biggest)

        else:

            print(niban)

resolve()
import sys

def input(): return sys.stdin.readline().strip()

def resolve():

    n=int(eval(input()))

    l=[int(eval(input())) for i in range(n)]

    l1=sorted(l,reverse=True)

    for j in range(n):

        if l[j]!=l1[0]:

            print((l1[0]))

        else:

            print((l1[1]))

resolve()
import sys


def input():
    return sys.stdin.readline().strip()


def resolve():
    n = int(eval(input()))
    l = [int(eval(input())) for i in range(n)]
    biggest = max(l)
    lsort = sorted(l)
    niban = lsort[-2]
    for j in range(n):
        if l[j] != biggest:
            print(biggest)
        else:
            print(niban)


resolve()

import sys


def input():
    return sys.stdin.readline().strip()


def resolve():
    n = int(eval(input()))
    l = [int(eval(input())) for i in range(n)]
    l1 = sorted(l, reverse=True)
    for j in range(n):
        if l[j] != l1[0]:
            print((l1[0]))
        else:
            print((l1[1]))


resolve()

-    biggest = max(l) -    lsort = sorted(l) -    niban = lsort[-2] +    l1 = sorted(l, reverse=True) -        if l[j] != biggest: -            print(biggest) +        if l[j] != l1[0]: +            print((l1[0])) -            print(niban) +            print((l1[1]))