CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]

m = max(a)

for i in range(n):
  if a[i]!=m:
    print(m)
  else:
    ans = max([x for j, x in enumerate(a) if j!=i])
    print(ans)

# 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 = []
for i in range(n):
    a.append(int(eval(input())))

a_copy = a[::]
a_copy.sort(reverse=True)

for i in range(n):
    if a[i] != a_copy[0]:
        print((a_copy[0]))
    else:
        print((a_copy[1]))

# Optimized solution
n = int(eval(input()))
a = []
top = 1
two = 1
for i in range(n):
    line = int(eval(input()))
    a.append(line)
    if line >= top:
        top, two = line, top
    elif line >= two:
        two = line

for i in range(n):
    if a[i] != top:
        print(top)
    else:
        print(two)
# Original solution
n = int(eval(input()))
a = [0] * n
for i in range(n):
    a[i] = int(eval(input()))

for i in range(0, n):
    if a[i] == max(a):
        print((sorted(a)[-2]))
    else:
        print((max(a)))

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

maxa = max(a)
index_max = a.index(maxa)

for i in range(0, n):
    if i == index_max:
        print((sorted(a)[-2]))
    else:
        print(maxa)
# Original solution
n = int(eval(input()))
ls = []
for i in range(n):
    ls.append(int(eval(input())))
maxnum = max(ls)
for i in range(n):
    if maxnum > ls[i]:
        print(maxnum)
    else:
        lstmp = ls[0:i] + ls[i+1:]
        print((max(lstmp)))


# Optimized solution
n = int(eval(input()))
ls = []
for i in range(n):
    ls.append(int(eval(input())))
maxnum = max(ls)
ind = ls.index(maxnum)
ls.remove(maxnum)
secondnum = max(ls)
ls = ls[0:ind] + [maxnum] + ls[ind:]
#print(ls)
if maxnum == secondnum:
    for i in range(n):
        print(maxnum)
    quit()
for i in range(n):
    if ls[i] == maxnum:
        print(secondnum)
    else:
        print(maxnum)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a_ = sorted(a)
a_max = a_[-1]
a_second = a_[-2]
 
if a.count(max(a)) >= 2:
    for _ in range(n):
        print(a_max)
else:
    for _ in range(n):
        if a[_] == max(a):
            print(a_second)
        else:
            print(a_max)

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a_ = sorted(a)
a_max = a_[-1]
a_second = a_[-2]
 
if a.count(a_max) >= 2:
    for _ in range(n):
        print(a_max)
else:
    for _ in range(n):
        if a[_] == a_max:
            print(a_second)
        else:
            print(a_max)
# Original solution
n = int(eval(input()))
a = []
for _ in range(n):
    A = int(eval(input()))
    a.append(A)
    
s = sorted(a)
for i in range(n):
    if a[i] == s[-1]:
        print((s[-2]))
    else:
        print((s[-1]))

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

one = (0, 0)
two = (0, 0)
for i in range(N):
    A = int(eval(input()))
    if A > one[0]:
        two = one
        one = (A, i)
    elif A > two[0]:
        two = (A, i)

for i in range(N):
    if i == one[1]:
        print((two[0]))
    else:
        print((one[0]))


# Optimized solution
import sys

N = int(eval(input()))

one = (0, 0)
two = (0, 0)
for i, A in enumerate(map(int, sys.stdin.readlines())):
    if A > one[0]:
        two = one
        one = (A, i)
    elif A > two[0]:
        two = (A, i)

for i in range(N):
    if i == one[1]:
        print((two[0]))
    else:
        print((one[0]))
# Original solution
n = int(eval(input()))
a = []
for i in range(n):
  a.append(int(eval(input())))
for i in range(n):
  tmp = a[:i]+a[i+1:]
  print((max(tmp)))

# Optimized solution
n = int(eval(input()))
a = []
for i in range(n):
  a.append(int(eval(input())))
max_a = max(a)
if a.count(max(a)) == 1:
  sec_max = sorted(a)[-2]
else:
  sec_max = max_a

for i in range(n):
  if a[i] == max_a:
    print(sec_max)
  else:
    print(max_a)
# Original solution
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
if n == 2:
    print((A[1]))
    print((A[0]))    
else:
    for i in range(n):
        if i == 0:
            print((max(A[1 : ])))
        elif i == n - 1:
            print((max(A[ : n])))
        else:
            a = max(A[ : i])
            b = max(A[i + 1 : ])
            print((max(a, b)))

# Optimized solution
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
semi_max_num, max_num = sorted(A)[-2:]
for a in A:
    if a != max_num:
        print(max_num)
    else:
        print(semi_max_num)
# Original solution
n = int(eval(input()))
a = []

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

for j in range(n):
  tmp = a[j]
  a[j] = 0
  print((max(a)))
  a[j] = tmp

# Optimized solution
n = int(eval(input()))
a = []
a_sort = []

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

m1 = max(a)
m2 = sorted(a)[-2]
  
for j in range(n):
  if a[j] == m1:
    print(m2)
  else:
    print(m1)
# Original solution
def resolve():
    a = [int(eval(input())) for _ in range(int(eval(input())))]
    st = sorted(a)
    count = len(st)
    for i in a:
        index = st.index(i)
        if index == (count - 1):
            print((st[-2]))
        else:
            print((st[-1]))


resolve()

# Optimized solution
def resolve():
    a = [int(eval(input())) for _ in range(int(eval(input())))]
    st = sorted(a)
    first = st[-1]
    second = st[-2]
    for i in a:
        if i == first:
            print(second)
        else:
            print(first)


resolve()
# 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)]

high = sorted(A, reverse=True)[: 2]

for i in range(n):
    if A[i] == high[0]:
        ans = high[1]
    else:
        ans = high[0]
    print(ans)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

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

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
 
A2 = sorted(A)[::-1]
for a in A:
  if a == A2[0]:
    print((A2[1]))
  else:
    print((A2[0]))
# Original solution
n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
a_max = max(a)
print((max(a[1:])))
for i in range(1, n-1):
    if a[i] != a_max:
        print(a_max)
    else:
        print((max(max(a[:i]), max(a[i+1:]))))
print((max(a[:n-1])))
        

# Optimized solution
n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
a_max = max(a)
ind_M = a.index(a_max)
tmpl = a
tmpl.pop(ind_M)
for i in range(n):
    if i != ind_M:
        print(a_max)
    else:
        print((max(tmpl)))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
print((max(a[1:])))
for i in range(1,n-1):
    print((max(*a[:i],*a[i+1:])))
print((max(a[:n-1])))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
temp = sorted(a)
m1 = temp[-1]
m2 = temp[-2]
for i in range(n):
    if a[i] == m1:
        print(m2)
    else:
        print(m1)
# Original solution
from math import sqrt

def solve(N, A):
    D = int(sqrt(N))
    M = []
    for i in range(0, N, D):
        M.append(max(A[i:i+D]))
    M.append(0)
    for i in range(0, N):
        d = i // D
        l = d*D
        m = 0
        for j in range(l, min(l+D, N)):
            if i != j and A[j] > m:
                m = A[j]
        m0 = m
        if d == 0:
            m = max(m, max(M[d+1:]))
        elif d >= len(M) - 1:
            m = max(m, max(M[:d]))
            pass
        else:
            #print(d, len(M))
            #print("M[:d]", M[:d])
            #print("M[d+1:]", M[d+1:])
            m = max(m, max(M[:d]), max(M[d+1:]))
        print(m)
        #print("d=%d,"%d, m, max(A[:i]+A[i+1:]))
        #assert m == max(A[:i]+A[i+1:])


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

#l = list(range(1, 200))
#solve(len(l), l)
main()


# Optimized solution
from math import sqrt

def solve0(N, A):
    S = sorted(A)
    S0 = S[-1]
    S1 = S[-2]

    for a in A:
        if a == S0:
            print(S1)
        else:
            print(S0)

def solve(N, A):
    D = int(sqrt(N))
    M = []
    for i in range(0, N, D):
        M.append(max(A[i:i+D]))
    M.append(0)
    for i in range(0, N):
        d = i // D
        l = d*D
        m = 0
        for j in range(l, min(l+D, N)):
            if i != j and A[j] > m:
                m = A[j]
        m0 = m
        if d == 0:
            m = max(m, max(M[d+1:]))
        elif d >= len(M) - 1:
            m = max(m, max(M[:d]))
            pass
        else:
            #print(d, len(M))
            #print("M[:d]", M[:d])
            #print("M[d+1:]", M[d+1:])
            m = max(m, max(M[:d]), max(M[d+1:]))
        print(m)
        #print("d=%d,"%d, m, max(A[:i]+A[i+1:]))
        #assert m == max(A[:i]+A[i+1:])


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

#l = list(range(1, 200))
#solve(len(l), l)
main()
# Original solution
n = int(eval(input()))
num = [ int(eval(input())) for _ in range(n) ]
maxnum = max(num)
for i in range(n):
    if num[i] != maxnum:
        print(maxnum)
    else:
        print((max(num[0:i]+num[i+1:])))

# Optimized solution
n = int(eval(input()))
num = [ int(eval(input())) for _ in range(n) ]
B = sorted(num,reverse=True)
maxnum = B[0]
maxnum2 = B[1]

for i in range(n):
    if num[i] != maxnum:
        print(maxnum)
    else:
        print(maxnum2)
# Original solution
N = int(eval(input()))
A = [0]*N

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

  M = max(A)
for i in range(N):
  if M == A[i]:
    Atmp = A[0:i]
    Atmp.extend(A[i+1:N])
    ans = max(Atmp)
    print(ans)
  else:
    print(M)


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

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

As = sorted(A, reverse=True)
M = As[0]
Ms = As[1]

for i in range(N):
  if M == A[i]:
    print(Ms)
  else:
    print(M)
# Original solution
n = int(eval(input()))
d = []
for i in range(n):
    tmp = int(eval(input()))
    d.append(tmp)

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


# Optimized solution
n = int(eval(input()))
mv = 0
mi = 0
d = []
for i in range(n):
    tmp = int(eval(input()))
    if tmp > mv:
        mv = tmp
        mi = i
    else:
        d.append(tmp)

for i in range(n):
    if i == mi:
        print((max(d)))
    else:
        print(mv)
# Original solution
n = int(eval(input()))
mv = 0
mi = 0
d = []
for i in range(n):
    tmp = int(eval(input()))
    if tmp > mv:
        mv = tmp
        mi = i
    else:
        d.append(tmp)

for i in range(n):
    if i == mi:
        print((max(d)))
    else:
        print(mv)

# Optimized solution
n = int(eval(input()))
mv1 = 0
mi1 = 0
mv2 = 0
for i in range(n):
    tmp = int(eval(input()))
    if tmp > mv1:
        mv1 = tmp
        mi1 = i
    elif tmp > mv2:
        mv2 = tmp

for i in range(n):
    if i != mi1:
        print(mv1)
    else:
        print(mv2)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
 
 
left_max = [-1] * N
right_max = [0]
all = sum(A)
left_max[0] = A[0]
right_max[0] = A[-1]
for i in range(1, N):
        left_max[i] = max(left_max[i-1], A[i])
for i in reversed(list(range(0, N-1))):
        right_max.insert(0, max(right_max[0], A[i]))
 
 
print((right_max[1]))
for i in range(1,N-1):
        print((max(left_max[i-1], right_max[i+1])))
print((left_max[-2]))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
 
 
left_max = [-1] * N
right_max = [-1] * N
all = sum(A)
left_max[0] = A[0]
right_max[-1] = A[-1]
for i in range(1, N):
        left_max[i] = max(left_max[i-1], A[i])
for i in reversed(list(range(0, N-1))):
        right_max[i] = max(right_max[i+1], A[i])
 

print((right_max[1]))
for i in range(1,N-1):
        print((max(left_max[i-1], right_max[i+1])))
print((left_max[-2]))
# 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)]

maximum = max(a)
ans = [maximum]*n
if a.count(maximum) ==1:
    maximum_index = a.index(maximum)
    ans[maximum_index] = max(
        a[:maximum_index]+a[maximum_index+1:]
    )
for i in range(n):
    print((ans[i]))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
s = max(a)
if a.count(s) >= 2:
  for i in range(n):  
    print(s)
else:
  for i in range(n):
    l = a.copy()
    l[i] = 0
    print((max(l)))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
s = max(a)
if a.count(s) >= 2:
  for i in range(n):  
    print(s)
else:
  for i in range(n):
    if a[i] == s:
      l = a.copy()
      l.sort()
      print((l[-2]))
    else:
      print(s)
# Original solution
N = int(eval(input()))
list1 = [int(eval(input())) for i in range(N)]

for i in range(N):
  list2 = list1[:i]+list1[i+1:]
  print((max(list2)))



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

max1 = list1.index(max(list1))
max2 = max(list1)
list2 = list1[:max1]+list1[max1+1:]
max3 = max(list2)

for i in range(N):
  if i != max1:
    print(max2)
  else:
    print(max3)
# Original solution
n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))

for i in range(len(a)):
    tmp = a.pop(i)
    print((max(a)))
    a.insert(i, tmp)



# Optimized solution
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)
# Original solution
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)

# Optimized solution
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)
# Original solution
N = int(eval(input()))
A =[int(eval(input())) for _ in range(N)]

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

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

B = sorted(A)
M, m = B[N-1], B[N-2]

for i in A:
    if i == M:
        print(m)
    else:
        print(M)
# Original solution
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]
X = list(set(A))
X.sort()
X.reverse()
if len(X) == 1 or A.count(max(A)) >= 2:
  for i in range(n):
    print((max(A)))
else:
  for i in range(n):
    if A[i] == X[0]:
      print((X[1]))
    else:
      print((X[0]))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
B = list(set(A))
B.sort()
B.reverse()
if len(B) == 1 or A.count(B[0])>= 2:
  for i in range(N):
    print((B[0]))
else:
  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 = [int(eval(input())) for _ in range(N)]

first = 0
second = 0

aa = copy.deepcopy(A)
aa.sort()

for a in aa:
    if a >= first:
        second = first
        first = a

for a in A:
    if a == first:
        print(second)
    else:
        print(first)


# Optimized solution
import copy

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

aa = copy.deepcopy(A)
aa.sort()

first = aa[-1]
second = aa[-2]

for a in A:
    if a == first:
        print(second)
    else:
        print(first)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for n in range(N)]
B = sorted(A)[::-1]
a1 = B[0]
a2 = B[1]

if a1==a2:
  for n in range(N):
    print(a1)
else:
  for n in range(N):
    if A[n]==a1:
      print(a2)
    else:
      print(a1)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for n in range(N)]
B = sorted(A)[::-1]
a1 = B[0]
a2 = B[1]

for n in range(N):
  if A[n]==a1:
    print(a2)
  else:
    print(a1)
# Original solution
n=int(eval(input()))
A = []
for _ in range(n):
  x = int(eval(input()))
  A.append(x)
standard = max(A)
for i in range(n):
  if A[i] != standard:
    print(standard)
  else:
    temp = 0
    for t in range(n):
      if t != i:
        if A[t] >= temp:
          temp = A[t]
    print(temp)

# Optimized solution
n=int(eval(input()))
A = []
for _ in range(n):
  x = int(eval(input()))
  A.append(x)
standard = max(A)
counter = A.count(max(A))
for i in range(n):
  if A[i] != standard:
    print(standard)
  elif counter >=2:
    print(standard)
  else:
    temp = 0
    for t in range(n):
      if t != i:
        if A[t] >= temp:
          temp = A[t]
    print(temp)
# Original solution
n = int(eval(input()))
an = [int(eval(input())) for _ in range(n)]

for i in range(n):
  if i != n-1 :
    a = an[:i] + an[i+1:]
  else :
    a = an[:i]
  print((max(a)))

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

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

for i in range(n):
    tmp = A[:]
    del tmp[i]
    print((max(tmp)))


# Optimized solution
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]
tmp = sorted(A,reverse=True)
Max = tmp[0]
Second = tmp[1]
for i in range(n):
    if A[i] != Max:
        print(Max)
    else:
        print(Second)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A,reverse=True)

for i in range(N):
  if i == A.index(max(A)):
    print((B[1]))
  else:
    print((B[0]))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A,reverse=True)
x = B[1]
y = B[0]
m = A.index(max(A))

for i in range(N):
  if i == m:
    print(x)
  else:
    print(y)
# Original solution
a=[]
b=int(eval(input()))
c=[]
i=0
while i<b:
    a.append(int(eval(input())))
    i+=1

i=1
while i<=b:
    for x in a:
        c.append(x)
    c[i-1]=0
    c.sort()
    print((c[-1]))
    i+=1
    c=[]

# Optimized solution
a=[]
b=int(eval(input()))
c=[]
i=0
while i<b:
    a.append(int(eval(input())))
    i+=1
for x in a:
    c.append(x)
c.sort()

i=1

if c[-1]!=c[-2]:
    while i<=b:
        if a[i-1]!=c[-1]:
            print((c[-1]))
        else:
            print((c[-2]))
        i+=1
else:
    while i<=b:
        print((c[-1]))
        i+=1
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
max_list = max(a)
for i in range(n):
    if a[i] == max_list:
        ans = sorted(list(a))[-2]
        print(ans)
    else :
        print(max_list)

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
max_list = max(a)
ans = sorted(list(a))[-2]
for i in range(n):
    if a[i] == max_list:
        print(ans)
    else :
        print(max_list)
# Original solution
import sys, re
input = sys.stdin.readline

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

# a[0]の場合
temp_list = a[1:]
temp_list.sort()
print((temp_list[-1]))

# それ以外の場合
for i in range(1, n):
  temp_list = a[:i] + a[i+1:]
  temp_list.sort()
  print((temp_list[-1]))


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

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

# a をソートして、一番大きい要素を取り出す
temp_list = sorted(a)
m = temp_list[::-1][0]


# 最も大きな数が複数あった場合
if temp_list[::-1][1] == m:
    m_dash = m
else:
    m_dash =temp_list[::-1][1]

for a_i in a:
  if a_i == m:
    print(m_dash)
  else:
    print(m)
# Original solution
def main():
    N = int(eval(input()))
    A = [int(eval(input())) for i in range(N)]
    A_sort = sorted(A)
    if (A_sort[-1] == A_sort[-2]):
        for i in range(N):
            print((A_sort[-1]))
    else:
        for i in range(N):
            if(A[i]==A_sort[-1]):
                print((A_sort[-2]))
            else:
                print((A_sort[-1]))

main()


# Optimized solution
N = int(eval(input()))
x = [int(eval(input())) for i in range(N)]
x_sort = sorted(x, reverse=True)
for i in range(N):
    if x[i] == x_sort[0]:
        print((x_sort[1]))
    else:
        print((x_sort[0]))
# Original solution
N = int(eval(input()))
li = []

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

li2 = sorted(li,reverse=True)

for i in range(N):
    ans = max(li)
    if(ans == li[i]):
        print((li2[1]))
    else:
        print(ans)
    
        

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

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

li2 = sorted(li,reverse=True)
ans = max(li)

for i in range(N):
    if(ans == li[i]):
        print((li2[1]))
    else:
        print(ans)
# Original solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
A0=max(A)
for i in range(N):
  if A[i]!=A0:
    print(A0)
  else:
    A.remove(A0)
    A1=max(A)
    print((max(A)))
    A.append(A1)

# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
B=sorted(A)
A0=B[N-1]
A1=B[N-2]
for i in range(N):
  if A[i]!=A0:
    print(A0)
  else:
    print(A1)
# Original solution
# -*- coding: utf-8 -*-
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a_unique = list(sorted(set(a), reverse=True))
max_value = max(a_unique)
for i in range(n):
    current_value = a.pop(i)
    if max_value in a:
        print(max_value)
    else:
        print((a_unique[1]))
    a.insert(i, current_value)


# Optimized solution
# -*- coding: utf-8 -*-
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a_unique = list(sorted(set(a), reverse=True))
max_value = a_unique[0]
max_value_count = a.count(max_value)

if max_value_count == 1:
    for i in range(n):
        if a[i] == max_value:
            print((a_unique[1]))
        else:
            print(max_value)
else:
    for i in range(n):
        print(max_value)
# Original solution
import sys


def main():
  n, *lst = map(int, sys.stdin.read().split())
  copy = sorted(lst)
  max1, max2 = copy[-1], copy[-2]
  if max2 < max1:
    print(*[max1 if j != max1 else max2 for j in lst], sep='\n')
  else:
    print(*[max1]*n, sep='\n')

    
if __name__ == '__main__':
  main()


# Optimized solution
import sys


def main():
  n, *lst = map(int, sys.stdin.read().split())
  max1 = max(lst)
  idx = lst.index(max1)
  max2 = max(lst[:idx] + lst[idx+1:])
  if max2 < max1:
    print(*[max1 if j != max1 else max2 for j in lst], sep='\n')
  else:
    print(*[max1]*n, sep='\n')

    
if __name__ == '__main__':
  main()
# Original solution
import heapq

num = int(eval(input()))
a = [int(eval(input())) for i in range(num)]
b = heapq.nlargest(2, a)
c = [b[0] for i in range(num)]
if b[0] == b[1]:
  for j in c:
    print(j)
else:
  for f in range(num):
    if f == a.index(b[0]):
      print((b[1]))
    else:
      print((b[0]))



# Optimized solution
from heapq import nlargest

n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
b = nlargest(2, a)
ma = max(a)
for j in a:
  if j == ma:
    print((b[1]))
  else:
    print(ma)