import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A_sorted = sorted(A, reverse=True)
    A_max = A_sorted[0]
    found_semi_max = False
    for i in range(N):
        if A_max != A_sorted[i]:
            A_semi_max = A_sorted[i]
            found_semi_max = True
            break
    
    for i in range(N):
        if A[i] == A_max and found_semi_max:
            print(A_semi_max)
        else:
            print(A_max)
main()