def slove():

    import sys

    import copy

    input = sys.stdin.readline

    n = int(input().rstrip('\n'))

    a = [int(input().rstrip('\n')) for _ in range(n)]

    b = copy.deepcopy(a)

    b.sort(reverse=True)

    for v in a:

        if v == b[0]:

            print((b[1]))

        else:

            print((b[0]))





if __name__ == '__main__':

    slove()

def slove():

    import sys

    input = sys.stdin.readline

    n = int(input().rstrip('\n'))

    a = [int(input().rstrip('\n')) for _ in range(n)]

    b = sorted(a, reverse=True)

    for i in range(len(a)):

        if a[i] == b[0]:

            print((b[1]))

        else:

            print((b[0]))





if __name__ == '__main__':

    slove()

def slove():
    import sys
    import copy

    input = sys.stdin.readline
    n = int(input().rstrip("\n"))
    a = [int(input().rstrip("\n")) for _ in range(n)]
    b = copy.deepcopy(a)
    b.sort(reverse=True)
    for v in a:
        if v == b[0]:
            print((b[1]))
        else:
            print((b[0]))


if __name__ == "__main__":
    slove()

def slove():
    import sys

    input = sys.stdin.readline
    n = int(input().rstrip("\n"))
    a = [int(input().rstrip("\n")) for _ in range(n)]
    b = sorted(a, reverse=True)
    for i in range(len(a)):
        if a[i] == b[0]:
            print((b[1]))
        else:
            print((b[0]))


if __name__ == "__main__":
    slove()

-    import copy -    b = copy.deepcopy(a) -    b.sort(reverse=True) -    for v in a: -        if v == b[0]: +    b = sorted(a, reverse=True) +    for i in range(len(a)): +        if a[i] == b[0]: