N = int(input()) #1行目のNを取得する
s = [input() for i in range(N)] #複数行の数値の入力を取得


# for i in range(N):
#     buf = s.copy()
#     buf.pop(i)
#     ans = max(buf)
#     print(ans)


max_ind = s.index(max(s))
max_num = max(s)
s.pop(max_ind)
max2_num = max(s)

for i in range(N):
    if i == max_ind:
        print(max2_num)
    else:
        print(max_num)
