import copy

n = int(input())

lis = []
for _ in range(n):
    lis.append(int(input()))
    
slis = sorted(copy.deepcopy(lis), reverse=True)
    
m = max(lis)
s = sorted(set(slis), reverse=True)
s.remove(m)
if s:
    sm  = max(s)
else:
    sm = m

for i in range(n):
    if lis[i] != m:
        print(m)
    else:
        print(sm)
