n = int(eval(input()))

a = []

for i in range(n):

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



max1 = max(a)

max2 = sorted(a)[-2]



if a.count(max1) >= 2:

    for i in range(n):

        print(max1)

elif a.count(max1) == 1:

    for i in range(n):

        if a[i] == max1:

            print(max2)

        else:

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

a = []



for i in range(n):

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



a2 = []

a2 = a.copy()

a2.sort()



mx = max(a)

mx2 = list(reversed(a2))[1]

mc = a.count(mx)





if mc > 1:

  for i in range(n):

    print(mx)



else:

  for i in range(n):

    if a[i] == mx:

      print(mx2)

    else:

      print(mx)

n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
max1 = max(a)
max2 = sorted(a)[-2]
if a.count(max1) >= 2:
    for i in range(n):
        print(max1)
elif a.count(max1) == 1:
    for i in range(n):
        if a[i] == max1:
            print(max2)
        else:
            print(max1)

n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
a2 = []
a2 = a.copy()
a2.sort()
mx = max(a)
mx2 = list(reversed(a2))[1]
mc = a.count(mx)
if mc > 1:
    for i in range(n):
        print(mx)
else:
    for i in range(n):
        if a[i] == mx:
            print(mx2)
        else:
            print(mx)

-max1 = max(a) -max2 = sorted(a)[-2] -if a.count(max1) >= 2: +a2 = [] +a2 = a.copy() +a2.sort() +mx = max(a) +mx2 = list(reversed(a2))[1] +mc = a.count(mx) +if mc > 1: -        print(max1) -elif a.count(max1) == 1: +        print(mx) +else: -        if a[i] == max1: -            print(max2) +        if a[i] == mx: +            print(mx2) -            print(max1) +            print(mx)