N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
  
maxA = sorted(set(A), reverse=True)
maxA1 = maxA[0]
maxA2 = 0 if len(maxA) == 1 else maxA[1]

for i in range(N):
  if A[i] == maxA1 and maxA2 != 0:
    print(maxA2)
  else:
    print(maxA1)
    