import sys

input = sys.stdin.readline



N=int(eval(input()))

a=[0]*N



max1=[0,0]

max2=[0,0]

for i in range(N):

    a=int(eval(input()))

    if max1[0]<=a:

        max2=max1

        max1=[a,i]

    elif max2[0]<=a:

        max2=[a,i]



for i in range(N):

    if i==max1[1]:

        print((max2[0]))

    else:

        print((max1[0]))
import sys

input = sys.stdin.readline



def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))



def main():

    mod=10**9+7

    N=I()

    A=[0]*N

    Mi=-1

    M=0

    for i in range(N):

        A[i]=I()

        if A[i]>M:

            Mi=i

            M=A[i]

            

    A[Mi]=0

    

    for i in range(N):

        if i!=Mi:

            print(M)

        else:

            print((max(A)))



main()

import sys

input = sys.stdin.readline
N = int(eval(input()))
a = [0] * N
max1 = [0, 0]
max2 = [0, 0]
for i in range(N):
    a = int(eval(input()))
    if max1[0] <= a:
        max2 = max1
        max1 = [a, i]
    elif max2[0] <= a:
        max2 = [a, i]
for i in range(N):
    if i == max1[1]:
        print((max2[0]))
    else:
        print((max1[0]))

import sys

input = sys.stdin.readline


def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


def main():
    mod = 10**9 + 7
    N = I()
    A = [0] * N
    Mi = -1
    M = 0
    for i in range(N):
        A[i] = I()
        if A[i] > M:
            Mi = i
            M = A[i]
    A[Mi] = 0
    for i in range(N):
        if i != Mi:
            print(M)
        else:
            print((max(A)))


main()

-N = int(eval(input())) -a = [0] * N -max1 = [0, 0] -max2 = [0, 0] -for i in range(N): -    a = int(eval(input())) -    if max1[0] <= a: -        max2 = max1 -        max1 = [a, i] -    elif max2[0] <= a: -        max2 = [a, i] -for i in range(N): -    if i == max1[1]: -        print((max2[0])) -    else: -        print((max1[0])) + + +def I(): +    return int(eval(input())) + + +def MI(): +    return list(map(int, input().split())) + + +def LI(): +    return list(map(int, input().split())) + + +def main(): +    mod = 10**9 + 7 +    N = I() +    A = [0] * N +    Mi = -1 +    M = 0 +    for i in range(N): +        A[i] = I() +        if A[i] > M: +            Mi = i +            M = A[i] +    A[Mi] = 0 +    for i in range(N): +        if i != Mi: +            print(M) +        else: +            print((max(A))) + + +main()