import sys

sys.setrecursionlimit(10**6)

def MI():

    return list(map(int,input().split()))

def I():

    return int(eval(input()))

def LI():

    return [int(i) for i in input().split()]



n=I()

a,b=[],[]

for i in range(n):

    a.append(I())

b=sorted(a)[::-1]

M=b[0]

m=b[1]

ans=0

for i in range(n):

    if a[i]==M:

        ans=m

    else:

        ans=M

    print(ans)

n=int(eval(input()))

a=[]

for i in range(n):

  a.append(int(eval(input())))

b=sorted(a)

m,M=b[-2:]

for i in range(n): print((m if a[i]==M else M))
import sys

sys.setrecursionlimit(10**6)


def MI():
    return list(map(int, input().split()))


def I():
    return int(eval(input()))


def LI():
    return [int(i) for i in input().split()]


n = I()
a, b = [], []
for i in range(n):
    a.append(I())
b = sorted(a)[::-1]
M = b[0]
m = b[1]
ans = 0
for i in range(n):
    if a[i] == M:
        ans = m
    else:
        ans = M
    print(ans)

n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
b = sorted(a)
m, M = b[-2:]
for i in range(n):
    print((m if a[i] == M else M))

-import sys - -sys.setrecursionlimit(10**6) - - -def MI(): -    return list(map(int, input().split())) - - -def I(): -    return int(eval(input())) - - -def LI(): -    return [int(i) for i in input().split()] - - -n = I() -a, b = [], [] +n = int(eval(input())) +a = [] -    a.append(I()) -b = sorted(a)[::-1] -M = b[0] -m = b[1] -ans = 0 +    a.append(int(eval(input()))) +b = sorted(a) +m, M = b[-2:] -    if a[i] == M: -        ans = m -    else: -        ans = M -    print(ans) +    print((m if a[i] == M else M))