# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    Ap = copy.copy(A)
    set(Ap)
    Ap.sort(reverse=True)
    Am = max(A)
    for i in range(N):
        if i != A.index(Am) or A.count(Am)>1:
            print(Am)
        else:
            print(Ap[1])
if __name__ == '__main__':
    main()