import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = [input() for _ in range(n)]
    max_a2, max_a = sorted(a)[-2:]
    print('\n'.join([max_a if i != max_a else max_a2 for i in a]))

if __name__ == '__main__':
    main()
