def exception_handling(N: int, A: list)->list:
    max_num_1, max_num_2 = 0, 0
    max_1, max_2 = 0, 0

    for a in A:
        if a > max_1:
            max_1 = a
            max_num_1 = 1
        elif a == max_1:
            max_num_1 += 1
        elif a > max_2:
            max_2 = a
            max_num_2 = 1
        elif a == max_2:
            max_num_2 += 1

    if max_num_1 > 1:
        return [max_1] * N
    return [max_2 if a == max_1 else max_1 for a in A]


if __name__ == "__main__":
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = exception_handling(N, A)
    for a in ans:
        print(a)
