N = int(eval(input()))

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



lmax = [0]

rmax = [0]



for i in range(N-1):

    lmax.append(max(lmax[i], a[i]))

    rmax.append(max(rmax[i], a[-(i+1)]))



for i in range(N):

    print((max(lmax[i], rmax[-(i+1)])))
import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines



def main():

    N,*A = list(map(int, read().split()))



    A_ = sorted(A)

    m = max(A)



    for a in A:

        if a == m:

            print((A_[-2]))

        else:

            print(m)





if __name__ == "__main__":

    main()

N = int(eval(input()))
a = [int(eval(input())) for i in range(N)]
lmax = [0]
rmax = [0]
for i in range(N - 1):
    lmax.append(max(lmax[i], a[i]))
    rmax.append(max(rmax[i], a[-(i + 1)]))
for i in range(N):
    print((max(lmax[i], rmax[-(i + 1)])))

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    N, *A = list(map(int, read().split()))
    A_ = sorted(A)
    m = max(A)
    for a in A:
        if a == m:
            print((A_[-2]))
        else:
            print(m)


if __name__ == "__main__":
    main()

-N = int(eval(input())) -a = [int(eval(input())) for i in range(N)] -lmax = [0] -rmax = [0] -for i in range(N - 1): -    lmax.append(max(lmax[i], a[i])) -    rmax.append(max(rmax[i], a[-(i + 1)])) -for i in range(N): -    print((max(lmax[i], rmax[-(i + 1)]))) +import sys + +read = sys.stdin.read +readline = sys.stdin.readline +readlines = sys.stdin.readlines + + +def main(): +    N, *A = list(map(int, read().split())) +    A_ = sorted(A) +    m = max(A) +    for a in A: +        if a == m: +            print((A_[-2])) +        else: +            print(m) + + +if __name__ == "__main__": +    main()