N = int(input())
AList = [input() for i in range(N)]
max_AList = max(AList)
max2nd_AList = sorted(AList)[1]

for i in range(N) :
    if AList[i] == max_AList :
        print(max2nd_AList)
    else :
        print(max_AList)