import sys



def solve(n, d):

    d_sorted = sorted(d, reverse=True)

    for i in range(n):

        print(d_sorted[0] if d[i] != d_sorted[0] else d_sorted[1])





if __name__ == '__main__':



    n = int(sys.stdin.readline().strip())

    d = []

    for i in range(n):

        d.append(int(sys.stdin.readline().strip()))

    solve(n, d)
import sys



input = sys.stdin.readline

N = int(eval(input()))



A = []

for _ in range(N):

    A.append(int(eval(input())))



for i, a in enumerate(sorted(A, reverse=True)):

    if i == 0:

        first = a

    elif i == 1:

        second = a

    else:

        break

# print(first, second)



for a in A:

    if a == first:

        print(second)

    else:

        print(first)
import sys


def solve(n, d):
    d_sorted = sorted(d, reverse=True)
    for i in range(n):
        print(d_sorted[0] if d[i] != d_sorted[0] else d_sorted[1])


if __name__ == "__main__":
    n = int(sys.stdin.readline().strip())
    d = []
    for i in range(n):
        d.append(int(sys.stdin.readline().strip()))
    solve(n, d)

import sys

input = sys.stdin.readline
N = int(eval(input()))
A = []
for _ in range(N):
    A.append(int(eval(input())))
for i, a in enumerate(sorted(A, reverse=True)):
    if i == 0:
        first = a
    elif i == 1:
        second = a
    else:
        break
# print(first, second)
for a in A:
    if a == first:
        print(second)
    else:
        print(first)

- -def solve(n, d): -    d_sorted = sorted(d, reverse=True) -    for i in range(n): -        print(d_sorted[0] if d[i] != d_sorted[0] else d_sorted[1]) - - -if __name__ == "__main__": -    n = int(sys.stdin.readline().strip()) -    d = [] -    for i in range(n): -        d.append(int(sys.stdin.readline().strip())) -    solve(n, d) +input = sys.stdin.readline +N = int(eval(input())) +A = [] +for _ in range(N): +    A.append(int(eval(input()))) +for i, a in enumerate(sorted(A, reverse=True)): +    if i == 0: +        first = a +    elif i == 1: +        second = a +    else: +        break +# print(first, second) +for a in A: +    if a == first: +        print(second) +    else: +        print(first)