import sys

n, *lst = list(map(int, sys.stdin.read().split()))

copy = sorted(lst)

max1, max2 = copy[-1], copy[-2]



if max2 < max1:

  for j in lst:

    if j != max1:

      print(max1)

    else:

      print(max2)

else:

  for j in lst:

    print(max1)
import sys





def main():

  n, *lst = map(int, sys.stdin.read().split())

  copy = sorted(lst)

  max1, max2 = copy[-1], copy[-2]

  if max2 < max1:

    print(*[max1 if j != max1 else max2 for j in lst], sep='\n')

  else:

    print(*[max1]*n, sep='\n')



    

if __name__ == '__main__':

  main()

import sys

n, *lst = list(map(int, sys.stdin.read().split()))
copy = sorted(lst)
max1, max2 = copy[-1], copy[-2]
if max2 < max1:
    for j in lst:
        if j != max1:
            print(max1)
        else:
            print(max2)
else:
    for j in lst:
        print(max1)

import sys


def main():
    n, *lst = map(int, sys.stdin.read().split())
    copy = sorted(lst)
    max1, max2 = copy[-1], copy[-2]
    if max2 < max1:
        print(*[max1 if j != max1 else max2 for j in lst], sep="\n")
    else:
        print(*[max1] * n, sep="\n")


if __name__ == "__main__":
    main()

-n, *lst = list(map(int, sys.stdin.read().split())) -copy = sorted(lst) -max1, max2 = copy[-1], copy[-2] -if max2 < max1: -    for j in lst: -        if j != max1: -            print(max1) -        else: -            print(max2) -else: -    for j in lst: -        print(max1) + +def main(): +    n, *lst = map(int, sys.stdin.read().split()) +    copy = sorted(lst) +    max1, max2 = copy[-1], copy[-2] +    if max2 < max1: +        print(*[max1 if j != max1 else max2 for j in lst], sep="\n") +    else: +        print(*[max1] * n, sep="\n") + + +if __name__ == "__main__": +    main()