n = int(eval(input()))

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

maxVal = max(numList)

workList = numList[:]

workList.remove(maxVal)

secondVal = max(workList)

for num in numList:

  if num != maxVal:

    print(maxVal)

  else:

    print(secondVal)
import sys

input = sys.stdin.readline

 

def main():

    N = int(eval(input()))

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

    max_val = max(A)

    AA = A[:]

    AA.remove(max_val)

    second_max_val = max(AA)

    for a in A:

        if a != max_val:

            print(max_val)

        else:

            print(second_max_val)

 

if __name__ == '__main__':

    main()
n = int(eval(input()))
numList = [int(eval(input())) for _ in range(n)]
maxVal = max(numList)
workList = numList[:]
workList.remove(maxVal)
secondVal = max(workList)
for num in numList:
    if num != maxVal:
        print(maxVal)
    else:
        print(secondVal)

import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]
    max_val = max(A)
    AA = A[:]
    AA.remove(max_val)
    second_max_val = max(AA)
    for a in A:
        if a != max_val:
            print(max_val)
        else:
            print(second_max_val)


if __name__ == "__main__":
    main()

-n = int(eval(input())) -numList = [int(eval(input())) for _ in range(n)] -maxVal = max(numList) -workList = numList[:] -workList.remove(maxVal) -secondVal = max(workList) -for num in numList: -    if num != maxVal: -        print(maxVal) -    else: -        print(secondVal) +import sys + +input = sys.stdin.readline + + +def main(): +    N = int(eval(input())) +    A = [int(eval(input())) for _ in range(N)] +    max_val = max(A) +    AA = A[:] +    AA.remove(max_val) +    second_max_val = max(AA) +    for a in A: +        if a != max_val: +            print(max_val) +        else: +            print(second_max_val) + + +if __name__ == "__main__": +    main()