#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N = int(input())

    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)
    AA = sorted(A)
    m = AA[-1]
    m2 = AA[-2]
    maxIndex = [i for i, x in enumerate(A) if x == m]
    
    for i in range(N):
        if i not in maxIndex or len(maxIndex) > 1:
            print(m)
        else:
            print(m2)


if __name__ == '__main__':
    main()
