import copy
N = int(input())

A = [0]*N

for r in range(N):
  A[r] = int(input())
Elias_A = copy.copy(A)
A.sort()
Sorted_A = copy.copy(A)
  
for r in range(N):
  if N >= 3:
    if A[r] == Sorted_A[N-1]: print(A[r])
    elif A[r] == Sorted_A[N-2]: print(A[r])
    elif A[r] == sorted_A[N-3]: print(A[r])
    else:
      A.remove(Elias_A[r])
      print(A[N-2])
      A = copy.copy(Sorted_A)
  else:
    A.remove(Elias_A[r])
    print(A[N-2])
    A = copy.copy(Sorted_A)