n = int(input())
a = {}
#b = []
mx = -10000
#mx1 = -10000
for i in range(n):
    num = int(input())
    if num in a.keys():
        a[num] += 1
    else:
        a[num] = 1
    if mx < num:
        mx = num
        m = i

k = max(a.keys())
if len(a) > 1:
    #t = sorted(list(a.keys()))[-2]
    b = list(a.keys())
    b.pop(m)
    t = max(b)

if a[k] > 1:
    for i in range(n):
        print(k)
else:
    for i in range(n):
        if i == m:
            print(t)
        else:
            print(k)
