import numpy as np
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 = [i for i, a in enumerate(s) if a == max(s)]
max_num = max(s)
max2_num = sorted(set(s))[-2]

for i in range(N):
    if (np.array(max_ind) == i).any():
        print(max2_num)
    else:
        print(max_num)
