#!/usr/bin/env python3

import sys





def solve(N: int, A: "List[int]"):

    left = [A[0]] * N

    right = [A[-1]] * N



    for i in range(1,N):

        if(A[i] > left[i-1]):

            left[i] = A[i]

        else:

            left[i] = left[i-1]



    for i in reversed(list(range(0,N-1))):

        if(A[i] > right[i+1]):

            right[i] = A[i]

        else:

            right[i] = right[i+1]



    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])))





    return





# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

def main():

    def iterate_tokens():

        for line in sys.stdin:

            for word in line.split():

                yield word

    tokens = iterate_tokens()

    N = int(next(tokens))  # type: int

    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"

    solve(N, A)



if __name__ == '__main__':

    main()

#!/usr/bin/env python3

import sys





def solve(N: int, A: "List[int]"):

    x = sorted(A)

    for i in A:

        if(i == x[-1]):

            print((x[-2]))

        else:

            print((x[-1]))

            

    return





# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

def main():

    def iterate_tokens():

        for line in sys.stdin:

            for word in line.split():

                yield word

    tokens = iterate_tokens()

    N = int(next(tokens))  # type: int

    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"

    solve(N, A)



if __name__ == '__main__':

    main()

#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    left = [A[0]] * N
    right = [A[-1]] * N
    for i in range(1, N):
        if A[i] > left[i - 1]:
            left[i] = A[i]
        else:
            left[i] = left[i - 1]
    for i in reversed(list(range(0, N - 1))):
        if A[i] > right[i + 1]:
            right[i] = A[i]
        else:
            right[i] = right[i + 1]
    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])))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == "__main__":
    main()

#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    x = sorted(A)
    for i in A:
        if i == x[-1]:
            print((x[-2]))
        else:
            print((x[-1]))
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == "__main__":
    main()

-    left = [A[0]] * N -    right = [A[-1]] * N -    for i in range(1, N): -        if A[i] > left[i - 1]: -            left[i] = A[i] +    x = sorted(A) +    for i in A: +        if i == x[-1]: +            print((x[-2])) -            left[i] = left[i - 1] -    for i in reversed(list(range(0, N - 1))): -        if A[i] > right[i + 1]: -            right[i] = A[i] -        else: -            right[i] = right[i + 1] -    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]))) +            print((x[-1])) -# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template) +# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)