N = int(eval(input()))

A = [int(eval(input())) for _ in range(N)]

B = sorted(A)



for i in range(N):

  if A[i] == B[-1]:

    print((B[-2]))

  else:

    print((B[-1]))
N = int(input())

A = [int(input()) for _ in range(N)]

second, first = sorted(A)[-2:]



ans = [second if a==first else first for a in A]

[print(a) for a in ans]

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A)
for i in range(N):
    if A[i] == B[-1]:
        print((B[-2]))
    else:
        print((B[-1]))

N = int(input())
A = [int(input()) for _ in range(N)]
second, first = sorted(A)[-2:]
ans = [second if a == first else first for a in A]
[print(a) for a in ans]

-N = int(eval(input())) -A = [int(eval(input())) for _ in range(N)] -B = sorted(A) -for i in range(N): -    if A[i] == B[-1]: -        print((B[-2])) -    else: -        print((B[-1])) +N = int(input()) +A = [int(input()) for _ in range(N)] +second, first = sorted(A)[-2:] +ans = [second if a == first else first for a in A] +[print(a) for a in ans]