N = int(eval(input()))

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

s_data = sorted(data)



for i in range(N):

    if s_data[N-1] == data[i]:

        print((s_data[N-2]))

    else:

        print((s_data[N-1]))

n = int(eval(input()))

data = []

for _ in range(n):

  data.append( int(eval(input())) )



data_s = sorted(data)



for d in data:

  if d == data_s[-1]:

    print((data_s[-2]))

  else:

    print((data_s[-1]))



# print(data)

# print(data_s)

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

n = int(eval(input()))
data = []
for _ in range(n):
    data.append(int(eval(input())))
data_s = sorted(data)
for d in data:
    if d == data_s[-1]:
        print((data_s[-2]))
    else:
        print((data_s[-1]))
# print(data)
# print(data_s)

-N = int(eval(input())) -data = [int(eval(input())) for _ in range(N)] -s_data = sorted(data) -for i in range(N): -    if s_data[N - 1] == data[i]: -        print((s_data[N - 2])) +n = int(eval(input())) +data = [] +for _ in range(n): +    data.append(int(eval(input()))) +data_s = sorted(data) +for d in data: +    if d == data_s[-1]: +        print((data_s[-2])) -        print((s_data[N - 1])) +        print((data_s[-1])) +# print(data) +# print(data_s)