import math

def main(): 

    n = int(input())
    a = [int(input()) for _ in range(n)]

    max_value = max(a)
    max_list = [i for i, x in enumerate(a) if x == max_value]
    
    a.pop(max_list[0])
    second_max = max(a)

    for i in range(n):
        if i not in max_list:
            print(max_value)
        else:
            print(second_max)




if __name__ == "__main__":
    main() 