N = int(eval(input()))

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



# http://tjkendev.github.io/procon-library/python/range_query/rmq_segment_tree.html

# N: 処理する区間の長さ

N0 = 2**(N-1).bit_length()

INF = 2**31-1

data = [0]*(2*N0)



# a_k の値を x に更新

def update(k, x):

    k += N0-1

    data[k] = x

    while k >= 0:

        k = (k - 1) // 2

        data[k] = max(data[2*k+1], data[2*k+2])



# 区間[l, r)の最小値

def query(l, r):

    L = l + N0

    R = r + N0

    s = 0

    while L < R:

        if R & 1:

            R -= 1

            s = max(s, data[R-1])



        if L & 1:

            s = max(s, data[L-1])

            L += 1

        L >>= 1

        R >>= 1

    return s





for i, a in enumerate(A):

    update(i, a)



l, r = 0, 1

for _ in range(N):

    a, b = query(0, l), query(r, N)

    print((max(a, b)))

    l += 1

    r += 1

N = int(eval(input()))

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



B = sorted(A)

f, s = B[-1], B[-2]



for a in A:

    if a == f:

        print(s)

    else:

        print(f)
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
# http://tjkendev.github.io/procon-library/python/range_query/rmq_segment_tree.html
# N: 処理する区間の長さ
N0 = 2 ** (N - 1).bit_length()
INF = 2**31 - 1
data = [0] * (2 * N0)
# a_k の値を x に更新
def update(k, x):
    k += N0 - 1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = max(data[2 * k + 1], data[2 * k + 2])


# 区間[l, r)の最小値
def query(l, r):
    L = l + N0
    R = r + N0
    s = 0
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R - 1])
        if L & 1:
            s = max(s, data[L - 1])
            L += 1
        L >>= 1
        R >>= 1
    return s


for i, a in enumerate(A):
    update(i, a)
l, r = 0, 1
for _ in range(N):
    a, b = query(0, l), query(r, N)
    print((max(a, b)))
    l += 1
    r += 1

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

-# http://tjkendev.github.io/procon-library/python/range_query/rmq_segment_tree.html -# N: 処理する区間の長さ -N0 = 2 ** (N - 1).bit_length() -INF = 2**31 - 1 -data = [0] * (2 * N0) -# a_k の値を x に更新 -def update(k, x): -    k += N0 - 1 -    data[k] = x -    while k >= 0: -        k = (k - 1) // 2 -        data[k] = max(data[2 * k + 1], data[2 * k + 2]) - - -# 区間[l, r)の最小値 -def query(l, r): -    L = l + N0 -    R = r + N0 -    s = 0 -    while L < R: -        if R & 1: -            R -= 1 -            s = max(s, data[R - 1]) -        if L & 1: -            s = max(s, data[L - 1]) -            L += 1 -        L >>= 1 -        R >>= 1 -    return s - - -for i, a in enumerate(A): -    update(i, a) -l, r = 0, 1 -for _ in range(N): -    a, b = query(0, l), query(r, N) -    print((max(a, b))) -    l += 1 -    r += 1 +B = sorted(A) +f, s = B[-1], B[-2] +for a in A: +    if a == f: +        print(s) +    else: +        print(f)