def main(A):
    maxInt = max(A)
    secondInt = sorted(A)[-2]

    for a in A:
        if a == maxInt:
            print(secondInt)
        else:
            print(maxInt)

if __name__ == '__main__':
    N = int(input())
    A = [input() for _ in range(N)]
    main(A)
