CodeEff/ECCO huggingface dataset:
# Original solution
import copy
N = int(eval(input()))
As = []
for i in range(N):
    As.append(int(eval(input())))
for j in range(N):
    instAs = copy.copy(As)
    instAs.pop(j)
    print((max(instAs)))

# Optimized solution
import copy
N = int(eval(input()))
As = []
for i in range(N):
    As.append(int(eval(input())))
maxA = max(As)
instA = As.copy()
instA.remove(maxA)
secA = max(instA)
for i in range(N):
    if As[i] == maxA:
        print(secA)
    else:
        print(maxA)
# Original solution
n = int(eval(input()))
ls = [int(eval(input())) for _ in range(n)]
l = ls.copy()

for i in range(n):
    ls = l.copy()
    ls.pop(i)
    print((max(ls)))


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

for i in range(n):
    if sls[-1] == ls[i]:
        print((sls[-2]))
    else:
        print((sls[-1]))
# Original solution

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

# S = sorted(A)
# MAXS = max(S[1:3])
# two = S[-2]
# print("MAX {} two {}".format(MAXS,two))
# count = S.count(max(S))
#
# for i in range(N):
#     if A[i] == MAXS:
#         if count > 1:
#             print(MAXS)
#         else:
#             print(two)
#     else:
#         print(MAXS)
#
for i in range(N):

    if i == 0:
        print((max(A[1:])))

    elif i == N-1:
        print((max(A[:i])))

    else:
        low = max(A[0:i])
        high = max(A[i+1:])

        if high > low:
            print(high)
        else:
            print(low)


# Optimized solution
# N = int(input())
# A = list(map(int, input().split()))
# 
# S = sorted(A)
# MAXS = max(A)
# 
# for i in range(N):
#     if A[i] == MAXS:
#         print(S[-2])
#     else:
#         print(S[-1])
# 


n = int(eval(input()))
a = list()
for i in range(n):
    a.append(int(eval(input())))
c = a.index(max(a))
m = max(a)
a.sort()
d = a[-2]
for i in range(n):
    if i == c:
        print(d)
    else:
        print(m)
# Original solution
def second(s):
    s.sort()
    s.reverse()
    return s[1]

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
B=A
for i in range(0,N):
    if A[i]==max(A):
        ans=second(B)
        print(ans)
    else:
        print((max(A)))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
a1=max(A)
a2=0
j=0
for i in range(N):
    if A[i]==a1:
        j=j+1
    else:
        j=j
if j!=1:
    for i in range(N):
        print(a1)
else:
    for i in range(N):
        if A[i]>a2 and A[i]!=a1:
            a2=A[i]
    for i in range(N):
        if A[i]==a1:
            print(a2)
        else:
            print(a1)
# Original solution
import sys
input = sys.stdin.readline

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

for i in range(n):
    c = sorted(a,reverse = True)
    if c[0] == a[i]:
        b = c[1]
    else:
        b = c[0]
    print(b)

# Optimized solution
import sys
input = sys.stdin.readline

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

c = sorted(a,reverse = True)

for i in range(n):
    if c[0] == a[i]:
        b = c[1]
    else:
        b = c[0]
    print(b)
# Original solution
n = int(eval(input()))
l = ([int(eval(input())) for j in range(n)])
a = max(l)
for i in range(n):
  if l[i]==a:
    print((max(l[:i]+l[i+1:])))
  else:
    print(a)

# Optimized solution
n = int(eval(input()))
l = ([int(eval(input())) for j in range(n)])
a = sorted(l)[-1]
b = sorted(l)[-2]

for i in range(n):
  if l[i]==a:
    print(b)
  else:
    print(a)
# Original solution
n = int(eval(input()))
a = []
for i in range(n):
	a.append(int(eval(input())))
maxs = []
for i in range(n):
	a2 = a[i]
	a[i] = 0
	maxs.append(max(a))
	a[i] = a2

for i in range(n):
	print((maxs[i]))

# Optimized solution
n = int(eval(input()))
a = []
for i in range(n):
	a.append(int(eval(input())))
max1 = max(a)
idx = a.index(max1)
a[idx] = 0
max2 = max(a)

for i in range(n):
	if i != idx:
		print(max1)
	else:
		print(max2)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

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

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A)
for a in A:
  if a == B[-1]:
    print((B[-2]))
  else:
    print((B[-1]))
# Original solution
n = int(eval(input()))

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

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



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

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

saidai1=max(a_list)
saidai1_index=a_list.index(saidai1)
saidai2=max(a_list[:saidai1_index]+a_list[saidai1_index+1:])

for i in range(n):
  if a_list[i]==saidai1:
    print(saidai2)
  else:
    print(saidai1)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
sorted_A = sorted(A)

for i in A:
  array = sorted_A.copy()
  array.remove(i)
  print((array[-1]))

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

for i in A:
  if i == sorted_A[-1]:
    print((sorted_A[-2]))
  else: 
    print((sorted_A[-1]))
# Original solution
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for i in range(n)]
for j in range(n):
    B = A.copy()
    B.remove(B[j])
    print((max(B)))

# Optimized solution
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for i in range(n)]
B = sorted(A)
m1 = B[-1]
m2 = B[-2]

for a in A:
    if a == m1:
        print(m2)
    else:
        print(m1)
# 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[i+1:]
  print((max(b)))

# Optimized solution
n = int(eval(input()))
a = []
for i in range(n):
  a.append(int(eval(input())))
b = sorted(a)
m = b[n-2]
M = b[n-1]
if M == m:
  for i in range(n):
    print(M)
else:
  for i in range(n):
    if a[i] == M:
      print(m)
    else:
      print(M)
# Original solution
n = eval(input())
A=[]
for i in range(0,int(n)):
  a=eval(input())
  A.append(int(a))

for i in range(0,int(n)):
  if ( sorted(A)[-1] == A[i]):
  	print((sorted(A)[-2]))
  else:
    print((sorted(A)[-1]))

# Optimized solution
n = eval(input())
A=[]
for i in range(0,int(n)):
  a=eval(input())
  A.append(int(a))
B=[]
B =sorted(A)
  
for i in range(0,int(n)):
  if ( B[-1] == A[i]):
  	print((B[-2]))
  else:
    print((B[-1]))
# Original solution
n = int(eval(input()))
a = [eval(input()) for _ in range(n)]

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


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

max_1st = max(a)
max_2nd = sorted(a)[-2]
for i in range(n):
    if a[i] == max_1st:
        print(max_2nd)
    else:
        print(max_1st)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

m2,m1 = sorted(A)[N-2:]

ans = [m1 if a!=m1 else m2 for a in A]
for a in ans:
  print(a)


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

m1=0
m2=0
for a in A:
  if a>=m1:
    m1,m2 = a,m1
  elif m1>a>=m2:
    m1,m2 = m1,a

ans = [m1 if a!=m1 else m2 for a in A]
for a in ans:
  print(a)
# Original solution
n = int(eval(input()))
a = list(int(eval(input())) for _ in range(n))

num = max(a)
for i in range(n):
    if a[i] < num:
        print(num)
    else:
        b = a.copy()
        int(b.pop(i))
        print((max(b)))

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

max_list = sorted(a,reverse=True)[:2]
num = max_list[0]
num2 = max_list[1]

for i in range(n):
    if a[i] < num:
        print(num)
    else:
        print(num2)
# Original solution
n = int(eval(input()))
a = []
for i in range(0, n):
    a.append(int(eval(input())))
for i in a:
    b = a.copy()
    b.remove(i)
    print((max(b)))

# Optimized solution
n = int(eval(input()))
a = []
for i in range(0, n):
    a.append(int(eval(input())))
b = a.copy()
f = max(b)
b.remove(f)
s = max(b)

for i in a:
    r = f if i != f else s
    print(r)
# Original solution
from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    xs = [int(stdin.readline().rstrip()) for _ in range(n)]

    for i in range(n):
        if i == 0:
            print((max(xs[i+1:])))
        elif i == n-1:
            print((max(xs[0:i])))
        else:
            print((max(max(xs[0:i]),max(xs[i+1:]))))

if __name__ == '__main__':
    main()


# Optimized solution
from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    xs = [int(stdin.readline().rstrip()) for _ in range(n)]

    max_1 = max(xs)
    key_max = xs.index(max_1)

    for i in range(n):
        if key_max != i:
            print(max_1)
        elif i == 0:
            print((max(xs[i+1:])))
        elif i == n-1:
            print((max(xs[0:i])))
        else:
            print((max(max(xs[0:i]),max(xs[i+1:]))))

if __name__ == '__main__':
    main()
# Original solution
import copy
N=int(eval(input()))
A=[]
for i in range(N):
  A.append(int(eval(input())))

x=max(A)
for i in range(N):
    if A[i]==x:
        B=copy.copy(A)
        B.pop(i)
        print((max(B)))
    else:
        print(x)

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

x=max(A)
count=(A.count(x))
index=[]
if count!=1:
    for i in range(N):
        print(x)
else:
    B=copy.copy(A)
    B.remove(x)
    y=max(B)
    for i in range(N):
        if A[i]==x:
            print(y)
        else:
            print(x)
# Original solution
#!/usr/bin/env python3


def main():
    N = int(eval(input()))
    As = [int(eval(input())) for _ in range(N)]
    for i in range(N):
        tmp = As[:]
        tmp.pop(i)
        print((max(tmp)))


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3


def main():
    N = int(eval(input()))
    As = [int(eval(input())) for _ in range(N)]
    max1 = max(As)
    max_idx = As.index(max1)
    As.remove(max1)
    max2 = max(As)
    max_list = [max1] * N
    max_list[max_idx] = max2
    for m in max_list:
        print(m)


if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for x in range(N)]
As = sorted(A)

for i in range(N):
    As.remove(A[i])
    print((As[-1]))
    As.insert(i, A[i])
    


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

for i in range(N):
    if As[-1] > A[i]:
        print((As[-1]))
        
    elif As[-1] == A[i]:
        print((As[-2]))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
s = A.index(max(A))
x = max(A)
A.sort()
y = A[-2]
ans = []
for i in range(N):
  ans.append(x)
  
ans[s] = y

for i in ans:
  print(i)

# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
a_max=max(a)
x=a.index(a_max)
a_sort=sorted(a)
y=a_sort[-2]
for i in range(n):
  if i==x:
    print(y)
  else:
    print(a_max)
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
a_max=max(a)
x=a.index(a_max)
a_sort=sorted(a)
y=a_sort[-2]
for i in range(n):
  if i==x:
    print(y)
  else:
    print(a_max)

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

s=max(a)
t=a.index(s)

for i in range(n):
  if i==t:
    del a[t]
    print((max(a)))
  else:
    print(s)
# Original solution
n = int(eval(input()))
l = [int(eval(input())) for _ in range(n)]
l = [0] + l + [0,0]
for i in range(1,n+1):
    print((max(max(l[:i]), max(l[i+1:]))))

# Optimized solution
n = int(eval(input()))
l = [int(eval(input())) for _ in range(n)]
_l = l.copy()
_l.sort(reverse=True)
lmax = _l[0]
lsec = _l[1]

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

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


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

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

for i in range(n):
    if not i == max_index:
        print(max_value)
    else:
        newlist = a[:i] + a[i+1:]
        print((max(newlist)))
# Original solution
import copy
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
A = copy.deepcopy(a)
#print(A)
for i in range(n):
    A.pop(i)
    print((max(A)))
    A.insert(i,a[i])

# Optimized solution
import copy
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
b =sorted(a, reverse = True)
#print(b)
#print(a)
for i in range(n):
    if a[i]==b[0]:
        print((b[1]))
    else:
        print((b[0]))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
first = sorted(A)[-1]
second = sorted(A)[-2]
if first == second:
    for i in range(N):
        print(first)
else:
    for i in range(N):
        if i == A.index(first):
            print(second)
        else:
            print(first)


# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
first = sorted(A)[-1]
second = sorted(A)[-2]
if first == second:
    for i in range(N):
        print(first)
else:
    idx = A.index(first)
    for i in range(N):
        if i == idx:
            print(second)
        else:
            print(first)
# Original solution
N = int(eval(input()))
data = []
for x in range(N):
    data.append(int(eval(input())))
for x in range(N):
    print((max(data[0:x] + data[x+1:N])))


# Optimized solution
N = int(eval(input()))
data = []
max1 = 0
max2 = 0
for i in range(N):
    x = int(eval(input()))
    if x > max1:
        max1 = x
        max_i = i
    elif x > max2:
        max2 = x
for i in range(N):
    if max_i == i:
        print(max2)
    else:
        print(max1)
# Original solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
A.insert(0,0)
A.insert(N+1,0)
ans=max(A)
for i in range(1,N+1):
  if A[i]!=ans:
    print(ans)
  else:
    m1=max(A[:i])
    m2=max(A[i+1:])
    m=max(m1,m2)
    print(m)

# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for _ 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
import copy
N = int(eval(input()))
A = []
for i in range(N):
    A.append(int(eval(input())))
B = sorted(A,reverse=True)
for a in A:
    C = copy.copy(B)
    C.remove(a)
    print((C[0]))    

# Optimized solution
import copy
N = int(eval(input()))
A = []
for i in range(N):
    A.append(int(eval(input())))
B = sorted(A,reverse=True)
for a in A:
    if a < B[0]:
        print((B[0]))    
    else:
        print((B[1]))
# Original solution
n=int(eval(input()))
a=[]
b=[]
for i in range(n):
    num=int(eval(input()))
    a.append(num)
    b.append(num)
for i in range(n):
    tmp=a[i]
    a[i]=0
    print((max(a)))
    a[i]=tmp

# Optimized solution
n=int(eval(input()))
a=[]
b=[]
for i in range(n):
    num=int(eval(input()))
    a.append(num)
    b.append(num)
b.sort(reverse=True)
x=a.count(b[0])
for i in range(n):
    if(a[i]==b[0]):
        if(x==1):
            print((b[1]))
        else:
            print((b[0]))
    else:
        print((b[0]))
# Original solution
n=int(eval(input()))
l=[]
for i in range(n):
    l.append(int(eval(input())))
for i in range(n):
    tmp=0
    b=[False for x in range(n)]
    b[i]=True
    for j in range(n):
        if(b[j]==False and l[j]>tmp):
            tmp=l[j]
    print(tmp)



# Optimized solution
n=int(eval(input()))
l=[]
for i in range(n):
    l.append(int(eval(input())))
# print(l)
x=[]
for i in range(n):
    x.append(l[i])
x.sort()
for i in range(n):
    if(l[i]!=x[n-1]):
     
        print((x[n-1]))
    else:

        print((x[n-2]))
# Original solution
import copy
N=int(eval(input()))
A=[int(eval(input())) for _ in range(N)]

def delete(n):
  B=copy.deepcopy(A)
  del B[n]
  return(max(B))

for i in range(N):
  print((delete(i)))

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

a=max(A)
k=A.count(a)#リストの最大数の個数をカウント
if k>=2:
  for i in range(N):
    print(a)
else:
  b=A.index(a)
  for i in range(N):
    if i != b:
      print(a)
    else:
      s=sorted(A)
      print((s[N-2]))
# Original solution
import copy
N=int(eval(input()))
A=[int(eval(input())) for _ in range(N)]

a=max(A)
k=A.count(a)#リストの最大数の個数をカウント
if k>=2:
  for i in range(N):
    print(a)
else:
  b=A.index(a)
  for i in range(N):
    if i != b:
      print(a)
    else:
      s=sorted(A)
      print((s[N-2]))

# Optimized solution
import copy

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

  a=max(A)
  k=A.count(a)#リストの最大数の個数をカウント
  if k>=2:
    for i in range(N):
      print(a)
  else:
    b=A.index(a)
    for i in range(N):
      if i != b:
        print(a)
      else:
        s=sorted(A)
        print((s[N-2]))

if __name__ == "__main__":
    main()
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]


for i in range(n):
    ret = a[:]
    ret.pop(i)
    print((max(ret)))


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

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

# Optimized solution
n=int(eval(input()))
A=[int(eval(input())) for i in range(n)]
ma=max(A)
flag=False
if A.count(ma)>=2:
  flag=True
for i in range(n):
  if A[i] != ma:
    print(ma)
  else:
    if flag:
      print(ma)
    else:
      A[i]=0
      print((max(A)))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
sa = sorted(a)
am, asl = sa[-1], sa[-2]
for i in range(n):
    print((asl if a[i] == am else am))

# Optimized solution
n = int(input())
a = [int(input()) for i in range(n)]
sa = sorted(a)
am, asl = sa[-1], sa[-2]
print(*[asl if ai == am else am for ai in a], sep='\n')
# Original solution
N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)]
lam = [0] * N
ram = [0] * N
lam[0] = a[0]
ram[N - 1] = a[N - 1]
for i in range(1, N):
  lam[i] = max(lam[i - 1], a[i])
  ram[N - 1 - i] = max(ram[N - 1 - i + 1], a[N - 1 - i])
print((ram[1]))
for i in range(1, N - 1):
  print((max(lam[i - 1], ram[i + 1])))
print((lam[N - 2]))


# Optimized solution
# 累積和(max)
N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)]
lam = a[:]
ram = a[:]
for i in range(1, N):
  lam[i] = max(lam[i], lam[i - 1])
for i in range(N - 2, -1, -1):
  ram[i] = max(ram[i], ram[i + 1])
print((ram[1]))
for i in range(1, N - 1):
  print((max(lam[i - 1], ram[i + 1])))
print((lam[N - 2]))
# Original solution
# 累積和(max)
N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)]
lcm = a[:]
rcm = a[:]
for i in range(1, N):
  lcm[i] = max(lcm[i], lcm[i - 1])
for i in range(N - 2, -1, -1):
  rcm[i] = max(rcm[i], rcm[i + 1])
print((rcm[1]))
for i in range(1, N - 1):
  print((max(lcm[i - 1], rcm[i + 1])))
print((lcm[N - 2]))


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

b = A[:]
b.sort(reverse=True)
for i in range(N):
    if A[i] != b[0]:
        print((b[0]))
    else:
        print((b[1]))
# Original solution
N = int(eval(input()))
A = []
mx=0
for i in range(N):
    A.append(int(eval(input())))


if A.count(max(A)) > 1:
    for i in range(N):
        print((max(A)))
else:
    for i in range(N):
        if A[i] != max(A):
            print((max(A)))
        else:
            print((sorted(A)[-2]))

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

mx=0
for i in range(N):
    A.append(int(eval(input())))

M = max(A)
    
if A.count(max(A)) > 1:
    for i in range(N):
        print(M)
else:
    for i in range(N):
        if A[i] != M:
            print(M)
        else:
            print((sorted(A)[-2]))
# Original solution
N = int(eval(input()))
list = [int(eval(input())) for i in range(N)]
list_max = sorted(list)
for i in range(N):
	if(list[i] == max(list)):
		print((list_max[-2]))
	else:
		print((max(list)))

# Optimized solution
N = int(eval(input()))
list = [int(eval(input())) for i in range(N)]
list_max = sorted(list)
max = max(list)
for i in range(N):
	if(list[i] == max):
		print((list_max[-2]))
	else:
		print(max)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
Amax = max(a)
Amax2 = sorted(a)[-2]
for i in range(n):
    if Amax > a[i]:
        print(Amax)
    else:
        print(Amax2)

# Optimized solution
n =  int(eval(input()))
A = []
for i in range(n):
    A.append(int(eval(input())))
ma = max(A)
ma2 = sorted(A)[-2]
for a in A:
    if a == ma:
        print(ma2)
    else:
        print(ma)
# Original solution
def main():
    n = int(eval(input()))
    a_lst = [(int(eval(input())), i + 1) for i in range(n)]
    a_lst_descend = sorted(a_lst, reverse=True)

    max_value = a_lst_descend[0][0]
    max_index = a_lst_descend[0][1]
    second_value = a_lst_descend[1][0]

    for i in range(1, n + 1):
        if i == max_index:
            print(second_value)
        else:
            print(max_value)


if __name__ == "__main__":
    main()


# Optimized solution
def main():
    n = int(eval(input()))
    a_lst = [int(eval(input())) for i in range(n)]
    a_lst_descend = sorted(a_lst, reverse=True)

    max_value = a_lst_descend[0]
    second_value = a_lst_descend[1]

    for a in a_lst:
        if a == max_value:
            print(second_value)
        else:
            print(max_value)


if __name__ == "__main__":
    main()
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
print((max(A[1:])))
for i in range(1,N-1):
    A1 = max(A[:i])
    A2 = max(A[i+1:])
    print((max(A1,A2)))
print((max(A[:N-1])))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
f = max(A)
if A.count(f) >=2:
    for i in range(N):
        print(f)
else:
    M = A.index(f)
    del A[M]
    for i in range(M):
        print(f)
    print((max(A)))
    for i in range(M+1,N):
        print(f)
# Original solution
from heapq import heappush, heappop

N = int(input())
A = [int(input()) for i in range(N)]
hq = []
for i in range(N):
    if A[i] not in hq:
        heappush(hq, -A[i])
max1 = -heappop(hq)
max2 = -heappop(hq)
ans = [0] * N
for i in range(N):
    if A[i] == max1:
        ans[i] = max2
    else:
        ans[i] = max1
print(*ans, sep="\n")


# Optimized solution
from heapq import heappush, heappop

N = int(input())
A = [int(input()) for i in range(N)]
hq = []
for i in range(N):
    heappush(hq, -A[i])
max1 = -heappop(hq)
max2 = -heappop(hq)
ans = [0] * N
for i in range(N):
    if A[i] == max1:
        ans[i] = max2
    else:
        ans[i] = max1
print(*ans, sep="\n")
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a_sorted = sorted(a)[::-1][:2]
for an in a:
    print((a_sorted[an == a_sorted[0]]))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a_sorted = sorted(a, reverse=True)[:2]
print(('\n'.join(map(str, [a_sorted[an == a_sorted[0]] for an in a]))))
# Original solution
n = int(eval(input()))
a = []
for _ in range(n):
    a.append(int(eval(input())))

for _ in range(n):
    val = a.pop(0)
    print((max(a)))
    a.append(val)


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

desc = sorted(list(set(a)), reverse=True)
max = desc[0]
large_2 = desc[1] if len(desc) > 1 else 0

if a.count(max) == 1:
    for val in a:
        if val == max:
            print(large_2)
        else:
            print(max)
else:
    for _ in range(n):
        print(max)
# Original solution
N = int(eval(input()))
A = [0] * (N)
for i in range(N):
	A[i] = int(eval(input()))

D=max(A)
for j in range(N):
	if A[j] != D:
		print(D)
	else:
		B = A[:]
		B.pop(j)
		print((max(B)))

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

D=max(A)
C=sorted(A)[-2]
for j in range(N):
	if A[j] != D:
		print(D)
	else:
		print(C)