n=int(eval(input()))

#l=[int(input()) for i in range(n)]

l=[]

mydic={}

for i in range(n) :

  s=int(eval(input()))

  l.append(s)

  if not s in list(mydic.keys()) :

    mydic[s]=1

  else :

    mydic[s]=mydic[s]+1

l2=sorted(l,reverse=True)

#print(l)

#print(mydic)

mx=l2[0]

for i in range(n) :

  if l[i]==mx :

    if mydic[mx]==1 :

      print((l2[1]))

    else:

      print(mx)

  else :

    print(mx)
n=int(eval(input()))

dic={}

mx=0

al=[]

for i in range(n):

    a=int(eval(input()))

    al.append(a)



order=sorted(al,reverse=True)

mx1=order[0]

mx2=order[1]



for a in al:

    if a==mx1:

        print(mx2)

    else:

        print(mx1)

n = int(eval(input()))
# l=[int(input()) for i in range(n)]
l = []
mydic = {}
for i in range(n):
    s = int(eval(input()))
    l.append(s)
    if not s in list(mydic.keys()):
        mydic[s] = 1
    else:
        mydic[s] = mydic[s] + 1
l2 = sorted(l, reverse=True)
# print(l)
# print(mydic)
mx = l2[0]
for i in range(n):
    if l[i] == mx:
        if mydic[mx] == 1:
            print((l2[1]))
        else:
            print(mx)
    else:
        print(mx)

n = int(eval(input()))
dic = {}
mx = 0
al = []
for i in range(n):
    a = int(eval(input()))
    al.append(a)
order = sorted(al, reverse=True)
mx1 = order[0]
mx2 = order[1]
for a in al:
    if a == mx1:
        print(mx2)
    else:
        print(mx1)

-# l=[int(input()) for i in range(n)] -l = [] -mydic = {} +dic = {} +mx = 0 +al = [] -    s = int(eval(input())) -    l.append(s) -    if not s in list(mydic.keys()): -        mydic[s] = 1 +    a = int(eval(input())) +    al.append(a) +order = sorted(al, reverse=True) +mx1 = order[0] +mx2 = order[1] +for a in al: +    if a == mx1: +        print(mx2) -        mydic[s] = mydic[s] + 1 -l2 = sorted(l, reverse=True) -# print(l) -# print(mydic) -mx = l2[0] -for i in range(n): -    if l[i] == mx: -        if mydic[mx] == 1: -            print((l2[1])) -        else: -            print(mx) -    else: -        print(mx) +        print(mx1)