N = int(input())
A = [0]*N
for i in range(N):
  A[i] = int(input())
#print(A)
M = max(A)
ind = A.index(M)
print(ind)
A.pop(ind)
m = max(A)
for i in range(N):
  #print(i)
  if i != ind:
    print(M)
  else:
    print(m)
    