CodeEff/ECCO huggingface dataset:
# Original solution
n=int(eval(input()))
lists=[]

for i in range(n):
    lists.append(int(eval(input())))

for i in range(n):
    if i==0:
        newlist=lists[1:]
        print((max(newlist)))
    if i>=1:
        newlist=lists[:i]+lists[i+1:]
        print((max(newlist)))

# Optimized solution
n=int(eval(input()))
lists=[int(eval(input())) for i in range(n)]
liscop=lists.copy()
lists=sorted(lists)
for i in liscop:
    if i==lists[-1]:
        print((lists[-2]))
    else:
        print((lists[-1]))
# Original solution
import copy
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
ans = 0
for i, l in enumerate(a):
    tmp = copy.deepcopy(a)
    tmp.pop(i)
    print((max(tmp)))

# Optimized solution
import copy
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
ans = max(a)
n_a = copy.deepcopy(a)
n_a.remove(ans)
s_ans = max(n_a)
if s_ans == ans:
    for i in a:
        print(ans)
else:
    for i in a:
        if i == ans:
            print(s_ans)
        else:
            print(ans)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for v in range(N)]

for i in range(N):
    L = A[:]
    A.pop(i)
    m = max(A)
    print(m)
    A = L[:]


# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for v in range(N)]

L = A[:]
m1 = max(A)
m1i = A.index(m1)
A.pop(m1i)
m2 = max(A)
m2i = A.index(m2)
A.pop(m2i)

for i in range(N):
    if (L[i] == m1):
        print(m2)
    else:
        print(m1)
# Original solution
n = int(eval(input()))
s = {}
for i in range(n):
    s[i] = int(eval(input()))

for i in range(n):
    temp = s[i]
    s.pop(i)
    max_v = max(s.values())
    print(max_v)
    s[i]=temp

# Optimized solution
n = int(eval(input()))
s = {}
for i in range(n):
    s[i] = int(eval(input()))

max_v = max(s.values())
max_k = max(s,key=s.get)
s.pop(max_k)
max_v2 = max(s.values())
max_k2 = max(s,key=s.get)

for i in range(n):
    if(i==max_k):
        print(max_v2)
    else:
        print(max_v)

"""
for i in range(n):
    temp = s[i]
    s.pop(i)
    max_v = max(s.values())
    print(max_v)
    s[i]=temp
"""
# Original solution
n=int(eval(input()))
a=[]
for i in range(n):
    a.append(int(eval(input())))
for i in range(n):
    b=a[i]
    a.pop(i)
    print((max(a)))
    a.insert(i,b)

# Optimized solution
n=int(eval(input()))
a=[]
for i in range(n):
    a.append(int(eval(input())))
m=max(a)
midx=a.index(max(a))
l=sorted(a)[-2]
for i in range(n):
    if i==midx:
        print(l)
    else:
        print(m)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

for i in range(N) :
    a = A[i]
    A[i] = 0
    print((max(A)))
    A[i] = a




# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
Max = max(A)
x = A.count(Max)

for i in range(0 ,N) :
    if x >= 2 :
        print(Max)
    elif A[i] == Max :
        A[i] = 0
        print((max(A)))
    else : print(Max)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
result = []
for i in range(N):
    C = A[i]
    A[i] = 0
    result.append(max(A))
    A[i] = C

for a in result:
    print(a)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = max(A)
C = [B]*N
D = sorted(A)[-2]
i = A.index(B)
if A.count(B) == 1:
    C[i] = D

for a in C:
    print(a)
# Original solution
def main():

    A = [int(i) for i in open(0).read().split()[1:]]
    tmp = A[:]
    tmp.sort()
    first = tmp[-1]
    second = tmp[-2]
    print(("\n".join(str(first) if a != first else str(second) for a in A)))
    return


main()


# Optimized solution
def main():

    *A, = list(map(int, open(0).read().split()[1:]))
    first, second = sorted(A)[:-3:-1]
    print(("\n".join(str(first) if a != first else str(second) for a in A)))
    return


main()
# Original solution
def main():

    *A, = list(map(int, open(0).read().split()[1:]))
    first, second = sorted(A, reverse=True)[:2]
    print(("\n".join(map(str, [first if a != first else second for a in A]))))
    return


main()


# Optimized solution
def main():

    N, *A = list(map(int, open(0).read().split()))
    first, second = sorted(A, reverse=True)[:2]
    print(("\n".join(map(str, [first if a != first else second for a in A]))))
    return


main()
# Original solution
N = int(eval(input()))
A = [eval(input()) for i in range(N)]
ans = 0
for i in range(N):
    wk = A[:]
    wk.pop(i)
    wk.sort()
    ans = wk[-1]
    print(ans)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
ans = 0
Max1 = max(A)
indexes = [i for i, x in enumerate(A) if x == Max1]
if len(A) == len(indexes):
    for i in A:
        print(i)
else:
    Max2 = sorted(set(A))[-2]
    if len(indexes) >= 2:
        for i in range(N):
            print(Max1)
    else:
        for i in range(N):
            ans = Max2 if A[i] == Max1 else Max1
            print(ans)
# Original solution
n=int(eval(input()))
a=[]
for i in range(n):
  ainput=int(eval(input()))
  a.append(ainput)

anext=a[:]
for i in range(n):
  anext.remove(anext[i])
  b=max(anext)
  print(b)
  anext.insert(i,a[i])

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

l1=sorted(a)[-1]
l2=sorted(a)[-2]

for i in a:
  if i==l1:
    print(l2)
  if i!=l1:
    print(l1)
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
b=a[:]
p=max(a)
b.remove(p)
q=max(b)

c=[i for i, x in enumerate(a) if x==p]

for i in range(n):
    if i not in c:
        print(p)
    else:
        print(q)

# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
b=a[:]
p=max(a)
b.remove(p)
q=max(b)

for i in a:
    if i!=p:
        print(p)
    else:
        print(q)
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for _ in [0]*n]
for i in range(n):
    print((max(a[:i]+a[i+1:])))

# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for _ in [0]*n]
M=max(a)
k=a.index(M)
m=max(a[:k]+a[k+1:])
for i in range(n):
    if i!=k:print(M)
    else:print(m)
# Original solution
n = int(eval(input()))

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

for i in range(n):
    t = a.pop(i)
    print((max(a)))
    a.insert(i, t)
    



# Optimized solution
n = int(eval(input()))

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

max_value = max(a)
max_value_index = a.index(max(a))

a.pop(max_value_index)
second_max_value = max(a)
a.insert(max_value_index,max_value)

#print("======")
#print(max_value)
#print(max_value_index)
#print(second_max_value)
#print("======")

for i in a:
    if i != max_value:
        print(max_value)
    else:
        print(second_max_value)
# Original solution
N = int(eval(input()))
a = list()
tmp = [0, 0]

for _ in range(N):
    ai = int(eval(input()))
    a.append(ai)
    if ai > tmp[1]:
        tmp[1] = ai
    elif ai > tmp[0]:
        tmp[0] = ai

m = tmp[1]

for ai in a:
    ans = m
    if ai == m:
        ans = tmp[0]
    print(ans)

# Optimized solution
n = int(eval(input()))
maximums = [0, 0]
nums = [int(eval(input())) for _ in range(n)]
maximums = sorted(nums, reverse=True)[:2]
for num in nums:
    if num == maximums[0]:
        print((maximums[1]))
    else:
        print((maximums[0]))
# Original solution
n = int(eval(input()))
a = list(map(int, [eval(input()) for i in range(n)]))

sum = max(a)
for i in range(n):
    if a[i] == max(a):
        b = a[:]
        b.remove(a[i])
        print((max(b)))
    else:
        print(sum)

# Optimized solution
n = int(eval(input()))
a = list(map(int, [eval(input()) for i in range(n)]))

m1 = max(a)
b = sorted(a, reverse = True)
m2 = max(b[1:])

for i in range(n):
    if a[i] == m1:
        print(m2)
    else:
        print(m1)
# Original solution
n = int(eval(input()))

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

for i in (a):
	b = max(a)
	if i ==b:
		print((sorted(a)[-2]))
	else:
		print(b)

# Optimized solution
n = int(eval(input()))

a = [int(eval(input())) for l in range(n)]
b = max(a)
c = sorted(a)[-2]
for i in (a):
	if not i==b:
		print(b)
	else:
		print(c)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]

for i in range(n):
    temp = a[i]
    a[i] = 0
    print((max(a)))
    a[i] = temp


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

aa = sorted(a)
first = aa[-1]
second = aa[-2]

for i in range(n):
    if a[i] != first:
        print(first)
    else:
        print(second)
# Original solution
n = int(eval(input()))

a_list = []
for _ in range(n):
    a = int(eval(input()))
    a_list.append(a)
b_list = sorted(a_list, reverse=True)

for a in a_list:
    ans = b_list[0] if a != b_list[0] else b_list[1]
    print(ans)

# Optimized solution
n = int(eval(input()))
a_list = [int(eval(input())) for _ in range(n)]
b_list = sorted(a_list, reverse=True)
for a in a_list:
    print((b_list[0] if a != b_list[0] else b_list[1]))
# Original solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
maxa=max(A)
for i in range(N):
  if A[i]==maxa:
    tmp=max(A[:i]+A[i+1:])
    print(tmp)
  else:
    print(maxa)

# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
maxa=max(A)
id=A.index(maxa)
for i in range(N):
  if i==id:
    tmp=max(A[:i]+A[i+1:])
    print(tmp)
  else:
    print(maxa)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]

max_number = max(a)

for i in range(n):
    if a[i] == max_number:
        print((max(a[0:i]+a[i+1:])))
    else:
        print(max_number)

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

max_number = max(a)
max_number2 = sorted(a)[-2]

for i in range(n):
    if a[i] == max_number:
        print(max_number2)
    else:
        print(max_number)
# Original solution
N,*A =list(map(int,open(0).read().split()))

for i in range(1,N+1):
  print((max(A[:i-1]+A[i:])))

# Optimized solution
N,*A =list(map(int,open(0).read().split()))
B =sorted(A)
biggest = B[-1]
for i in A:
  if i==biggest:
    print((B[-2]))
  else:
    print(biggest)
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
amax=max(a)
for i in range(n):
  if max(a)==a[i]:
    b=a[i]
    a[i]=0
    print((max(a)))
    a[i]=b
  else:
    print(amax)
  


# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]

amax,b=max(a),a.index(max(a))
a.remove(amax)
bmax=max(a)
for i in range(n):
  if i==b:
    print(bmax)
  else:
    print(amax)
# Original solution
N = int(eval(input()))

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

for i in range(N):
  print((max([elem for idx,elem in enumerate(A) if idx != i]))) 

# Optimized solution
N = int(eval(input()))

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

A.sort(key=lambda x :x[1],reverse=True)

for i in range(N):
  if A[0][0] != i:
    print((A[0][1]))
  else:
    print((A[1][1]))
# Original solution
N = int(eval(input()))
a_list = [None] * N
for i in range(N):
    a_list[i] = int(eval(input()))

#remove duplicate
sorted_a = sorted(a_list, reverse = True)
max_a = sorted_a[0]

result = []
for a in a_list:
    if a == max_a:
        print((max(sorted_a[1:])))
    else:
        print(max_a)


# Optimized solution
N = int(eval(input()))
a_list = [None] * N
for i in range(N):
    a_list[i] = int(eval(input()))

#remove duplicate
sorted_a = sorted(a_list, reverse = True)
max_a = sorted_a[0]

result = []
for a in a_list:
    if a == max_a:
        print((sorted_a[1]))
    else:
        print(max_a)
# Original solution
n = int(eval(input()))
lis = [int(eval(input())) for _ in range(n)]

M = max(lis)

for i in range(n):
    if lis[i] == M:
        lis2 = lis[:i] + lis[(i+1):]
        print((max(lis2)))
    else:
        print(M)


# Optimized solution
n = int(eval(input()))
lis = [int(eval(input())) for _ in range(n)]
lis2 = sorted(lis)
m1 = lis2[-1]
m2 = lis2[-2]

for a in lis:
    if a == m1:
        print(m2)
    else:
        print(m1)
# Original solution
N=int(eval(input()))
l=list()
for i in range(N):
    l.append(int(eval(input())))

num=list()
M=max(l)
for k in range(N):
    if(l[k]==M):
        num=l[:k]+l[k+1:]
        print((max(num)))
    else:
        print(M)


# Optimized solution
N=int(eval(input()))
l=list()
for i in range(N):
    l.append(int(eval(input())))
a=sorted(l)
m1=a[-1]
m2=a[-2]
for k in range(N):
    if(m1==l[k]):
        print(m2)
    else:
        print(m1)
# Original solution
a = eval(input())
a = int(a)

suuretu_list = []
kari_list = []

for i in range(a):
    b = int(eval(input()))
    suuretu_list.append(b)
    kari_list.append(b)

c = max(suuretu_list)

d = suuretu_list.index(c)

for u in suuretu_list:
    if u != c:
        print(c)
    else:
        e = max(kari_list)
        f = kari_list.index(e)
        kari_list.pop(f)
        g = max(kari_list)
        print(g)
        kari_list.append(g)

# Optimized solution
a = eval(input())
a = int(a)

suuretu_list = []
kari_list = []

for i in range(a):
    b = int(eval(input()))
    suuretu_list.append(b)
    kari_list.append(b)

kari_list = sorted(kari_list)

c = max(suuretu_list)

d = suuretu_list.index(c)

for u in suuretu_list:
    if u != c:
        print(c)
    else:
        print((kari_list[-2]))
# Original solution
N=int(eval(input()))
A=[int(eval(input())) for _ in range(N)]
B=sorted(A)[:N-1]
m=max(A)
for i in range(N):
    if  A[i]==m:
        print((max(B)))
    else:
        print(m)

# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for _ in range(N)]
B=sorted(A)[:N-1]
m=max(A)
n=A.index(max(A))
for i in range(N):
    if  i!=n:
        print(m)
    else:
        print((max(B)))
# Original solution
import copy
n = int(eval(input()))
a = [list(map(int, input().split())) for i in range(n)]

for i in range(n):
    al = copy.copy(a)
    del al[i]
    print((max(al)[0]))

# Optimized solution
import copy
n = int(eval(input()))
a = [list(map(int, input().split())) for i in range(n)]

a_l = []
for i in range(n):
    a_l.append(a[i][0])
a1 = sorted(a_l)
m1 = a1[-1]
m2 = a1[-2] 

for i in a_l:
    if i == m1:
        print(m2)
    else:
        print(m1)
# Original solution
N=int(eval(input()))
A=[]
for _ in range(N):
  A.append(int(eval(input())))

index = A.index(max(A))
for i in range(N):
  if i==index:
    b=A.pop(i)
    print((max(A)))
    A.insert(i,b)
  else:
      print((max(A)))

# Optimized solution
N=int(eval(input()))
A=[]
for _ in range(N):
  A.append(int(eval(input())))

value=max(A)
index = A.index(max(A))
for i in range(N):
  if i==index:
    b=A.pop(i)
    print((max(A)))
  else:
      print(value)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]

for i in range(n):
    print((max(a[:i] + a[i+1:])))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
m1 = max(a)
mi = a.index(m1)
m2 = max(a[:mi] + a[mi+1:])

for i in range(n):
    if i == mi:
        print(m2)
    else:
        print(m1)
# Original solution
import copy
def main():
    N = int(eval(input()))
    A = [int(eval(input())) for a in range(N) ]
    for i in range(N):
        tmp = copy.copy(A[i])
        A[i] = 0
        print((max(A)))
        A[i] = copy.copy(tmp)
if __name__ == "__main__":
    main()

# Optimized solution
import copy
def main():
    N = int(eval(input()))
    A = [int(eval(input())) for a in range(N) ]
    C = sorted(A)
    Af = C[-1]
    As = C[-2]

    for i in range(N):
        if A[i] != Af:
            print(Af)
        else:
            print(As)
if __name__ == "__main__":
    main()
# Original solution
N = int(eval(input()))

A = [0] * N
for i in range(N):
    a = int(eval(input()))
    A[i] = a

ans = 0
for i in range(N):
    tmp = A[:]
    tmp.sort(reverse=True)
    
    if tmp[0] == A[i]:
      print((tmp[1]))
    else:
      print((tmp[0]))   

# Optimized solution
N = int(eval(input()))

A = [0] * N
for i in range(N):
    a = int(eval(input()))
    A[i] = a

tmp = A[:]
tmp.sort(reverse=True)
for i in range(N):
    
    if tmp[0] == A[i]:
        print((tmp[1]))
    else:
        print((tmp[0]))
# Original solution
n = int(eval(input()))
nums = [int(eval(input())) for _ in range(n)]
for i in range(n):
  print((max(nums[:i]+nums[i+1:])))

# Optimized solution
n = int(eval(input()))
num = [int(eval(input())) for _ in range(n)]
m = max(num)
sec = sorted(num)[-2]
for x in num:
    if x != m:
        print(m)
    else:
        print(sec)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

max1 = [A.index(max(A)), max(A)]
p = A.pop(A.index(max(A)))
max2 = max(A)
ans = [max2 if j == max1[0] else max1[1] for j in range(N)]
for k in range(N):
    print((ans[k]))


# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

max1 = [A.index(max(A)), max(A)]
p = A.pop(A.index(max(A)))
max2 = max(A)
for k in range(N):
    if k == max1[0]:
        print(max2)
    else:
        print((max1[1]))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]

for i in range(n):
    print((max(a[:i] + a[i+1:])))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]

a_r = sorted(a, reverse=True)
for i in range(n):
    if a[i] == a_r[0]:
        print((a_r[1]))
    else:
        print((a_r[0]))
# Original solution
n = int(eval(input()))
a = [ int(eval(input())) for x in range(n) ] 

maximum = max(a)

for i in a:
    if i == maximum:
        b = a.copy()
        b.remove(i)
        print(( max(b) ))
    else:
        print(maximum)

# Optimized solution
n = int(eval(input()))
a = [ int(eval(input())) for x in range(n) ] 

b = sorted(a, reverse = True)
maximum = b[0]

for i in a:
    if i == maximum:
        print((b[1]))
    else:
        print(maximum)
# Original solution
n = int(eval(input()))
a = [ int(eval(input())) for x in range(n) ] 

b = sorted(a, reverse = True)
maximum = b[0]

for i in a:
    if i == maximum:
        print((b[1]))
    else:
        print(maximum)

# Optimized solution
n = int(eval(input()))
a = [ int(eval(input())) for x in range(n) ] 

b = sorted(a, reverse = True)
maximum = b[0]

for i in a: 
	print(( b[1] if i == maximum else maximum ))
# Original solution
a = int(eval(input()))
ar = [int(eval(input())) for i in range(a)]
br = sorted(ar)
for r in ar:
    if r == max(ar):
        print((br[-2]))
    else:
        print((max(ar)))

# Optimized solution
a = int(eval(input()))
ar = [int(eval(input())) for i in range(a)]
br = sorted(ar)
am = max(ar)
bm = br[-2]
for r in ar:
    if r == am:
        print(bm)
    else:
        print(am)
# Original solution
import copy

n = int(eval(input()))
l = [int(eval(input())) for i in range(n)]
for i in range(n):
    s = l[:i]+l[i+1:]
    print((sorted(s)[-1]))

# Optimized solution
import copy

n = int(eval(input()))
l = [int(eval(input())) for i in range(n)]
Max1 = sorted(l)[-1]
Max2 = sorted(l)[-2]
for i in range(n):
    if l[i] == Max1:
        print(Max2)
    else:
        print(Max1)
# Original solution
N = int(eval(input()))
A_list = [int(eval(input())) for i in range(N)]

for i in range(N):
    compare_list = A_list[0:i] + A_list[i+1:]
    print((max(compare_list)))


# Optimized solution
N = int(eval(input()))
A_list = [int(eval(input())) for i in range(N)]

sorted_A_list = sorted(A_list)
n1 = sorted_A_list[-1]
n2 = sorted_A_list[-2]

for i in range(N):
    if A_list[i] == n1:
        print(n2)
    else:
        print(n1)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

for i in range(N):
  target = A[0:i] + A[i+1:N]
  print((max(target)))

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

max_num = max(A)
max_ind = A.index(max(A))
for i in range(N):
  if max_ind == i:
    print((max(A[0:i]+A[i+1:N])))
  else:
    print(max_num)
# Original solution
n = int(eval(input()))

arr = []
max_num = 0
label = 1
for i in range(n):
    inp = int(eval(input()))
    if inp >= max_num:
       max_num = inp
       label = i
    arr.append(inp)


arr_sub = arr[:]
arr_sub.pop(label)
#print(arr)
#print(max(arr))
#print(max(arr_sub))



for i in range(n):
    if i != label:
        print((max(arr)))
    else:
        print((max(arr_sub)))




# Optimized solution
n = int(eval(input()))

arr = []
max_num = 0
label = 1
for i in range(n):
    inp = int(eval(input()))
    if inp >= max_num:
       max_num = inp
       label = i
    arr.append(inp)



arr_sub = arr[:]
arr_sub.pop(label)
second_max = max(arr_sub)


for i in range(n):
    if i != label:
        print(max_num)
    else:
        print(second_max)
# Original solution
N = int(input())
A = [int(input()) for i in range(N)]
ans = [0]*N

ans[0] = max(A[1:])
ans[N-1] = max(A[:-1])

for i in range(1, N-1):
    ans[i] = max(max(A[:i]), max(A[i+1:]))

print(*ans, sep="\n")


# Optimized solution
N = int(input())
A = [int(input()) for i in range(N)]
ans = [0]*N

first = sorted(A)[-1]
second = sorted(A)[-2]

for i in range(N):
    if A[i]==first:
        ans[i] = second
    else:
        ans[i] = first

print(*ans, sep="\n")
# Original solution
N = int(eval(input()))

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

for i in range(N):
    new_A = A.copy()
    del new_A[i]
    print((sorted(new_A)[-1]))

# Optimized solution
N = int(eval(input()))

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

max = sorted(A)[-1]
semi_max = sorted(A)[-2]

if max != semi_max:
    ex = A.index(max)
    
    for i in range(0,ex):
        print(max)
    
    print(semi_max)
    
    for i in range(ex+1,N):
        print(max)

else:
    for i in range(N):
        print(max)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
for i in range(N):
    Ai = A[i]
    A[i] = 0
    print((max(A)))
    A[i] = Ai

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
max_num0 = max(A)
temp = A.index(max_num0)
A[temp] = 0
max_num1 = max(A)
A[temp] = max_num0

for i in range(N):
    if A[i] != max_num0:
        print(max_num0)
    else:
        print(max_num1)
# Original solution
N=int(eval(input()))
A=[]
for i in range(N):
  a=int(eval(input()))
  A.append(a)
  
ans=max(A)
for i in range(N):
  if A[i]==ans:
    b=A[:i]
    c=A[i+1:]
    aa=b+c
    print((max(aa)))
  else:
    print(ans)

# Optimized solution
N=int(eval(input()))
A=[]
for i in range(N):
  a=int(eval(input()))
  A.append(a)
  
ans=max(A)
for i in range(N):
  if A[i]==ans:
    b=A[:i]
    c=A[i+1:]
    aa=b+c
    an=max(aa)
    if an==ans:
      for j in range(N-i):
        print(ans)
      break
    else:
      print(an)
  else:
    print(ans)
# Original solution
N = int(eval(input()))

nums = [int(eval(input())) for i in range(N)]
maxNum = max(nums)
for i in range(N):
    if nums[i] == maxNum:
        print((max(nums[:i] + nums[i+1:])))
    else:
        print(maxNum)

# Optimized solution
N = int(eval(input()))

nums = [int(eval(input())) for i in range(N)]
first = sorted(nums)[-1]
second = sorted(nums)[-2]

for i in range(N):
    if nums[i] == first:
        print(second)
    else:
        print(first)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
for i in range(n):
    t = a[:]
    t.pop(i)
    print((max(t)))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
b = sorted(a,reverse=True)

for i in range(n):
    if a[i]==b[0]:
        print((b[1]))
    else:
        print((b[0]))
# Original solution
N = int(eval(input()))
A_LIST = []

for _ in range(N):
    A = int(eval(input()))
    A_LIST.append(A)

for i in range(N):
    temp = A_LIST[i]
    A_LIST[i] = 0
    print((max(A_LIST)))
    A_LIST[i] = temp


# Optimized solution
N = int(eval(input()))
A_LIST = []

for _ in range(N):
    A = int(eval(input()))
    A_LIST.append(A)

sorted_A_LIST = sorted(A_LIST)
largest = sorted_A_LIST[-1]
second_largest = sorted_A_LIST[-2]

for i in range(N):
    if A_LIST[i] < largest:
        print(largest)
    else:
        print(second_largest)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

for i in range(N):
    X = A[0:i] + A[i+1:]
    Y = set(X)
    print((max(Y)))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

B = A[:]

a1 = max(A)
A.remove(a1)
a2 = max(A)

for i in range(N):
    if B[i] != a1:
        print(a1)
    else:
        print(a2)