N = int(eval(input()))

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

A_max = 0

for i in range(N):

  A_max = max(A_max,A[i])

cnt = 0

for j in range(N):

  if A_max == A[j]:

    cnt += 1

  if cnt == 2:

    for _ in range(N):

      print(A_max)

    exit()

A[A.index(A_max)] = 0

A_second = 0

for l in range(N):

  A_second = max(A_second,A[l])

for m in range(N):

  print((A_second if A[m] == 0 else A_max))
N = int(eval(input()))

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

B = sorted(A)

bool = 1 if B[-1] == B[-2] else 0

for i in range(N):

  if bool:

    print((B[-1]))

  else:

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

      print((B[-2]))

    else:

      print((B[-1]))
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A_max = 0
for i in range(N):
    A_max = max(A_max, A[i])
cnt = 0
for j in range(N):
    if A_max == A[j]:
        cnt += 1
    if cnt == 2:
        for _ in range(N):
            print(A_max)
        exit()
A[A.index(A_max)] = 0
A_second = 0
for l in range(N):
    A_second = max(A_second, A[l])
for m in range(N):
    print((A_second if A[m] == 0 else A_max))

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

-A_max = 0 +B = sorted(A) +bool = 1 if B[-1] == B[-2] else 0 -    A_max = max(A_max, A[i]) -cnt = 0 -for j in range(N): -    if A_max == A[j]: -        cnt += 1 -    if cnt == 2: -        for _ in range(N): -            print(A_max) -        exit() -A[A.index(A_max)] = 0 -A_second = 0 -for l in range(N): -    A_second = max(A_second, A[l]) -for m in range(N): -    print((A_second if A[m] == 0 else A_max)) +    if bool: +        print((B[-1])) +    else: +        if A[i] == B[-1]: +            print((B[-2])) +        else: +            print((B[-1]))