
import math




def main():
    n = int(input())
    lista = []
    for i in range(0, n):
        lista.append(int(input()))
    print(lista)
    maxim1 = -999999
    maxim2 = -9999999
    for element in lista:
        if element > maxim1:
            maxim2 = maxim1
            maxim1 = element
        elif element < maxim1 and element > maxim2:
            maxim2 = element
    
    for element in lista:
        if element == maxim1:
            print(maxim1)
        else:
            print(maxim2)



if __name__ == "__main__":
    main()