N = int(input())
An = list()
for i in range(N):
    An.append(input())
MaxIndex = An.index(max(An))
SecondIndex = An.index(sorted(An)[-2])
for i in range(N):
    if i == MaxIndex:
        print(An[SecondIndex])
    else:
        print(An[MaxIndex])