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

ans = max(lint)
index = [i for i, x in enumerate(lint) if x == max(lint)]

if len(index) >= 2:
    for i in range(n):
        print(ans)
elif len(index) == 1:
    for i in range(0, index[0], 1):
        print(ans)
    a = lint.pop(index[0])
    print(max(lint))
    lint.append(a)
    for i in range(index[0] + 1, n, 1):
        print(ans)