n = int(input())
A = []
for i in range(n):
  a = int(input())
  A.append(a)
m = max(A)
m2 = sorted(set(A))[-2]
c = A.count(m)

bool = False
if c == 1:
  bool = True

for i in A:
  if bool and i==m:
    print(m2)
  else:
    print(m)