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 = list(map(int, sys.stdin.read().split()))

  max1 = max(lst)

  idx = lst.index(max1)

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

  print(('\n'.join(str(max1) if j != max1 else str(max2) for j in lst)))





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 = list(map(int, sys.stdin.read().split()))
    max1 = max(lst)
    idx = lst.index(max1)
    max2 = max(lst[:idx] + lst[idx + 1 :])
    print(("\n".join(str(max1) if j != max1 else str(max2) for j in lst)))


if __name__ == "__main__":
    main()

-    n, *lst = map(int, sys.stdin.read().split()) +    n, *lst = list(map(int, sys.stdin.read().split())) -    if max2 < max1: -        print(*[max1 if j != max1 else max2 for j in lst], sep="\n") -    else: -        print(*[max1] * n, sep="\n") +    print(("\n".join(str(max1) if j != max1 else str(max2) for j in lst)))