N = int(input())

A = []

for n in range(N):
    A.append([n, int(input())])
print(A)
As = sorted(A, reverse=True, key=lambda x: x[1])
print(As)
    

for n in range(N):
    i = 0    
    if n == 0:
        if A[0] == As[0]:
            print(As[1][1])
        else:           
            print(As[0][1])
    else:
        while i < n:
            if A[n] == As[i]:
                i+=1
                print(As[i][1])
                break

            elif A[n][1] > As[i][1]:
                    i += 1
            else:
                print(As[i][1])
                break
