my_max=0

my_sec=0

cnt=0

n=int(eval(input()))

a=[0]*n

r_n =list(range(n))

for i in r_n:

  a[i]=int(eval(input()))

  if my_max<a[i]:

    my_max=a[i]

  elif my_sec<a[i]:

    my_sec=a[i]

    

for i in r_n:

  if my_max==a[i]:

    cnt+=1

    

for i in r_n:

  if my_sec!=0:

    if my_max!=a[i]:

      print(my_max)

    elif cnt>1:

      print(my_max)

    else:

      print(my_sec)

  else:

    print(my_max)

  

  

 
import sys

input=sys.stdin.readline

n=int(eval(input()))

max1=0

max2=0

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

for i in a:

    if i>=max1:

        max2=max1

        max1=i

    elif i>=max2:

        max2=i

if max2==0:

    for i in range(n):

        print(max1)

    exit()

for i in a:

    if i==max1:

        print(max2)

    else:

        print(max1)

    
my_max = 0
my_sec = 0
cnt = 0
n = int(eval(input()))
a = [0] * n
r_n = list(range(n))
for i in r_n:
    a[i] = int(eval(input()))
    if my_max < a[i]:
        my_max = a[i]
    elif my_sec < a[i]:
        my_sec = a[i]
for i in r_n:
    if my_max == a[i]:
        cnt += 1
for i in r_n:
    if my_sec != 0:
        if my_max != a[i]:
            print(my_max)
        elif cnt > 1:
            print(my_max)
        else:
            print(my_sec)
    else:
        print(my_max)

import sys

input = sys.stdin.readline
n = int(eval(input()))
max1 = 0
max2 = 0
a = [int(eval(input())) for i in range(n)]
for i in a:
    if i >= max1:
        max2 = max1
        max1 = i
    elif i >= max2:
        max2 = i
if max2 == 0:
    for i in range(n):
        print(max1)
    exit()
for i in a:
    if i == max1:
        print(max2)
    else:
        print(max1)

-my_max = 0 -my_sec = 0 -cnt = 0 +import sys + +input = sys.stdin.readline -a = [0] * n -r_n = list(range(n)) -for i in r_n: -    a[i] = int(eval(input())) -    if my_max < a[i]: -        my_max = a[i] -    elif my_sec < a[i]: -        my_sec = a[i] -for i in r_n: -    if my_max == a[i]: -        cnt += 1 -for i in r_n: -    if my_sec != 0: -        if my_max != a[i]: -            print(my_max) -        elif cnt > 1: -            print(my_max) -        else: -            print(my_sec) +max1 = 0 +max2 = 0 +a = [int(eval(input())) for i in range(n)] +for i in a: +    if i >= max1: +        max2 = max1 +        max1 = i +    elif i >= max2: +        max2 = i +if max2 == 0: +    for i in range(n): +        print(max1) +    exit() +for i in a: +    if i == max1: +        print(max2) -        print(my_max) +        print(max1)