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

max_ind = [i for i, a in enumerate(s) if a == max(s)]
max_num = max(s)

if len(max_ind) > 1:
    for i in range(N):
        print(max_num)

else:
    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)
