import copy

n = int(input())
a = [int(input()) for _ in range(n)]
a_down = sorted(a, reverse=True)
for i in range(n):
    a_down_copy = copy.deepcopy(a_down)
    while a[i] == max(a_down_copy):
        if max(a_down_copy) == min(a_down_copy):
            break
        a_down_copy.pop(0)
    print(max(a_down_copy))
