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





def main():

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

  max1 = max(lst)

  idx = lst.index(max1)

  max2 = max(lst[:idx] + lst[idx+1:])

  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


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


def main():
    n, *lst = map(int, sys.stdin.read().split())
    max1 = max(lst)
    idx = lst.index(max1)
    max2 = max(lst[:idx] + lst[idx + 1 :])
    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()

-    copy = sorted(lst) -    max1, max2 = copy[-1], copy[-2] +    max1 = max(lst) +    idx = lst.index(max1) +    max2 = max(lst[:idx] + lst[idx + 1 :])