import numpy as np



N = int(eval(input()))

A_s = []

for i in range(N):

  A_s.append(int(eval(input())))

  

A_s = np.array(A_s)

  

m_index = A_s.argmax()

sort_A_s = sorted(A_s)

m_value = A_s[m_index]

m_second = sort_A_s[N-2]



for i in range(N):

  if i != m_index:

    print(m_value)

  else:

    print(m_second)
#include <bits/stdc++.h>

N = int(eval(input()))

A = [int(eval(input())) for _ in range(N)]

first, second = sorted(A)[::-1][:2]

for a in A:

    print((first if a != first else second))

import numpy as np

N = int(eval(input()))
A_s = []
for i in range(N):
    A_s.append(int(eval(input())))
A_s = np.array(A_s)
m_index = A_s.argmax()
sort_A_s = sorted(A_s)
m_value = A_s[m_index]
m_second = sort_A_s[N - 2]
for i in range(N):
    if i != m_index:
        print(m_value)
    else:
        print(m_second)

# include <bits/stdc++.h>
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
first, second = sorted(A)[::-1][:2]
for a in A:
    print((first if a != first else second))

-import numpy as np - +# include <bits/stdc++.h> -A_s = [] -for i in range(N): -    A_s.append(int(eval(input()))) -A_s = np.array(A_s) -m_index = A_s.argmax() -sort_A_s = sorted(A_s) -m_value = A_s[m_index] -m_second = sort_A_s[N - 2] -for i in range(N): -    if i != m_index: -        print(m_value) -    else: -        print(m_second) +A = [int(eval(input())) for _ in range(N)] +first, second = sorted(A)[::-1][:2] +for a in A: +    print((first if a != first else second))