

n = int(eval(input()))

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



a_max = max(a)

b = a.copy()

b.remove(a_max)

a_max_second = max(b)



for a_i in a:

    if a_i != a_max:

        print(a_max)

    else:

        print(a_max_second)
def main():

    N = int(eval(input()))

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

    L = [0]*(N+1)

    for i, a in enumerate(A, start=1):

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



    R = [0]*(N+2)

    for i in range(N)[::-1]:

        R[i] = max(R[i+1], A[i])



    for i in range(N):

        print((max(L[i], R[i+1])))





if __name__ == '__main__':

    main()

n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
a_max = max(a)
b = a.copy()
b.remove(a_max)
a_max_second = max(b)
for a_i in a:
    if a_i != a_max:
        print(a_max)
    else:
        print(a_max_second)

def main():
    N = int(eval(input()))
    A = [int(eval(input())) for i in range(N)]
    L = [0] * (N + 1)
    for i, a in enumerate(A, start=1):
        L[i] = max(L[i - 1], a)
    R = [0] * (N + 2)
    for i in range(N)[::-1]:
        R[i] = max(R[i + 1], A[i])
    for i in range(N):
        print((max(L[i], R[i + 1])))


if __name__ == "__main__":
    main()

-n = int(eval(input())) -a = [int(eval(input())) for i in range(n)] -a_max = max(a) -b = a.copy() -b.remove(a_max) -a_max_second = max(b) -for a_i in a: -    if a_i != a_max: -        print(a_max) -    else: -        print(a_max_second) +def main(): +    N = int(eval(input())) +    A = [int(eval(input())) for i in range(N)] +    L = [0] * (N + 1) +    for i, a in enumerate(A, start=1): +        L[i] = max(L[i - 1], a) +    R = [0] * (N + 2) +    for i in range(N)[::-1]: +        R[i] = max(R[i + 1], A[i]) +    for i in range(N): +        print((max(L[i], R[i + 1]))) + + +if __name__ == "__main__": +    main()