n = int(eval(input()))

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

b = a[:]

b.sort(reverse=True)

for i in range(n):

  if a[i] == b[0]:

    print((b[1]))

  else:

    print((b[0]))
def main():

    n = int(eval(input()))

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

    b = sorted(a)

    for i in range(n):

      if a[i] == b[-1]:

        print((b[-2]))

      else:

        print((b[-1]))

 

main()
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = a[:]
b.sort(reverse=True)
for i in range(n):
    if a[i] == b[0]:
        print((b[1]))
    else:
        print((b[0]))

def main():
    n = int(eval(input()))
    a = [int(eval(input())) for _ in range(n)]
    b = sorted(a)
    for i in range(n):
        if a[i] == b[-1]:
            print((b[-2]))
        else:
            print((b[-1]))


main()

-n = int(eval(input())) -a = [int(eval(input())) for _ in range(n)] -b = a[:] -b.sort(reverse=True) -for i in range(n): -    if a[i] == b[0]: -        print((b[1])) -    else: -        print((b[0])) +def main(): +    n = int(eval(input())) +    a = [int(eval(input())) for _ in range(n)] +    b = sorted(a) +    for i in range(n): +        if a[i] == b[-1]: +            print((b[-2])) +        else: +            print((b[-1])) + + +main()