n = int(eval(input()))

a = [int(eval(input())) for i in range(n)]



m = max(a)

count = a.count(m)



if count != 1:

    for i in range(n):

        print(m)



else:

    switch = 0

    for i in range(n-1):

        if a[i] == m:

            a.remove(m)

            m2max = max(a)

            print(m2max)

            a.append(m)

            switch = 1

        else:

            print(m)

    

    if switch == 1:

        print(m)

    else:

        a.remove(m)

        m2max = max(a)

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

s=[int(eval(input())) for _ in range(n)]

lst=sorted(s,reverse=True)

max1=lst[0]

max2=lst[1]

for i in range(n):

    if s[i]==max1:

        print(max2)

    else:

        print(max1)
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
m = max(a)
count = a.count(m)
if count != 1:
    for i in range(n):
        print(m)
else:
    switch = 0
    for i in range(n - 1):
        if a[i] == m:
            a.remove(m)
            m2max = max(a)
            print(m2max)
            a.append(m)
            switch = 1
        else:
            print(m)
    if switch == 1:
        print(m)
    else:
        a.remove(m)
        m2max = max(a)
        print(m2max)

n = int(eval(input()))
s = [int(eval(input())) for _ in range(n)]
lst = sorted(s, reverse=True)
max1 = lst[0]
max2 = lst[1]
for i in range(n):
    if s[i] == max1:
        print(max2)
    else:
        print(max1)

-a = [int(eval(input())) for i in range(n)] -m = max(a) -count = a.count(m) -if count != 1: -    for i in range(n): -        print(m) -else: -    switch = 0 -    for i in range(n - 1): -        if a[i] == m: -            a.remove(m) -            m2max = max(a) -            print(m2max) -            a.append(m) -            switch = 1 -        else: -            print(m) -    if switch == 1: -        print(m) +s = [int(eval(input())) for _ in range(n)] +lst = sorted(s, reverse=True) +max1 = lst[0] +max2 = lst[1] +for i in range(n): +    if s[i] == max1: +        print(max2) -        a.remove(m) -        m2max = max(a) -        print(m2max) +        print(max1)