def main():

    n,*a = map(int,open('abc134_c.txt').read().split())
    b = sorted(a)
    max = b[-1]
    maxs= b[-2]

    for i in range(n):
        if a[i] == max:
            print(maxs)
        else:
            print(max)
    return()

if __name__=='__main__':
    main()