n = int(eval(input()))

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



left = [0] * n

for i in range(n):

    if i == 0:

        left[i] = a[i]

    else:

        left[i] = max(left[i - 1], a[i])



right = [0] * n

for i in range(n - 1, -1, -1):

    if i == n - 1:

        right[i] = a[i]

    else:

        right[i] = max(right[i + 1], a[i])



for i in range(n):

    if i == 0:

        print((right[1]))

    elif i == n - 1:

        print((left[n - 2]))

    else:

        print((max(left[i - 1], right[i + 1])))

def main():

    from operator import itemgetter

    import sys

    input = sys.stdin.readline



    N = int(eval(input()))

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



    it = iter(sorted(enumerate(A, start=1), key=itemgetter(1), reverse=True))

    i, ma1 = next(it)

    _, ma2 = next(it)



    for j in range(1, N + 1):

        if j == i:

            print(ma2)

        else:

            print(ma1)





if __name__ == '__main__':

    main()

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
left = [0] * n
for i in range(n):
    if i == 0:
        left[i] = a[i]
    else:
        left[i] = max(left[i - 1], a[i])
right = [0] * n
for i in range(n - 1, -1, -1):
    if i == n - 1:
        right[i] = a[i]
    else:
        right[i] = max(right[i + 1], a[i])
for i in range(n):
    if i == 0:
        print((right[1]))
    elif i == n - 1:
        print((left[n - 2]))
    else:
        print((max(left[i - 1], right[i + 1])))

def main():
    from operator import itemgetter
    import sys

    input = sys.stdin.readline
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]
    it = iter(sorted(enumerate(A, start=1), key=itemgetter(1), reverse=True))
    i, ma1 = next(it)
    _, ma2 = next(it)
    for j in range(1, N + 1):
        if j == i:
            print(ma2)
        else:
            print(ma1)


if __name__ == "__main__":
    main()

-n = int(eval(input())) -a = [int(eval(input())) for _ in range(n)] -left = [0] * n -for i in range(n): -    if i == 0: -        left[i] = a[i] -    else: -        left[i] = max(left[i - 1], a[i]) -right = [0] * n -for i in range(n - 1, -1, -1): -    if i == n - 1: -        right[i] = a[i] -    else: -        right[i] = max(right[i + 1], a[i]) -for i in range(n): -    if i == 0: -        print((right[1])) -    elif i == n - 1: -        print((left[n - 2])) -    else: -        print((max(left[i - 1], right[i + 1]))) +def main(): +    from operator import itemgetter +    import sys + +    input = sys.stdin.readline +    N = int(eval(input())) +    A = [int(eval(input())) for _ in range(N)] +    it = iter(sorted(enumerate(A, start=1), key=itemgetter(1), reverse=True)) +    i, ma1 = next(it) +    _, ma2 = next(it) +    for j in range(1, N + 1): +        if j == i: +            print(ma2) +        else: +            print(ma1) + + +if __name__ == "__main__": +    main()