CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A)

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

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A)
c = A.index(max(A))
for i in range(N):
    if i == c:
        print((B[-2]))
    else:
        print((B[-1]))
# Original solution
n = int(eval(input()))
i = 0
A = []
while i < n:
	A.append(int(eval(input())))
	i += 1
	
for i in range(len(A)):
	m = max(A)
	if A[i] == m:
		A1 = A.copy()
		del A1[i]
		print((max(A1)))
	else:
		print((max(A)))

# Optimized solution
n = int(eval(input()))
A = []
for i in range(n):
	A.append(int(eval(input())))
	
B = A.copy()
B.remove(max(B))

A_max = max(A)
B_max = max(B)

for i in range(n):
	if A[i] == A_max:
		print(B_max)
	else:
		print(A_max)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
max_a = max(a)
tmp_a = a.copy()
count = 0
for i in range(n):
    if tmp_a[i] == max_a:
        count += 1

if count == 1:
    for i in range(len(a)):
        tmp_a = a.copy()
        if tmp_a[i] == max_a:
            del tmp_a[i]
            print((max(tmp_a)))
        else:
            print(max_a)
else:
    for i in range(len(a)):
        print(max_a)



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

sorted_a = sorted(a)
first_a = sorted_a[-1]
second_a = sorted_a[-2]

for i in range(len(a)):
    if a[i] == first_a:
        print(second_a)
    else:
        print(first_a)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
for i in range(n-1):
    if i==0:
        print((max(a[1:])))
    else:
        max1 = max(a[:i])
        max2 = max(a[i+1:])
        print((max(max1, max2)))
print((max(a[:n])))


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

ma = max(A)
for i in range(N):
    if A[i] == ma:
        A[i] = 0
        print((max(A)))
        A[i] = ma
    else:
        print(ma)

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

newA = sorted(A)
ma = newA[N-1]
for i in range(N):
    if A[i] == ma:
        print((newA[N-2]))
    else:
        print(ma)
# Original solution
n=int(eval(input()))
a=[]
for _ in range(n):
    a.append(int(eval(input())))
for i in range(n):
    tem=a[i]
    del a[i]
    print((max(a)))
    a.insert(i,tem)

# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
b=sorted(a)
mx=b[-1]
mx2=b[-2]
for i in a:
    if i==mx:
        print(mx2)
    else:
        print(mx)
# Original solution
n = int(eval(input()))
li_a = list()
d_a = dict()

for _ in range(n):
    wk = int(eval(input()))
    li_a.append(wk)

    get = d_a.get(wk, 0)
    d_a[wk] = get + 1

for i in range(n):
    d_a_copy = d_a.copy()
    if d_a_copy.get(li_a[i], 0) == 1:
        d_a_copy.pop(li_a[i])
    print((max(d_a_copy.keys())))




# Optimized solution
n = int(eval(input()))
li_a = list()
d_a = dict()

for _ in range(n):
    wk = int(eval(input()))
    li_a.append(wk)

    get = d_a.get(wk, 0)
    d_a[wk] = get + 1

li_top2 = sorted(list(d_a.keys()), reverse=True)[:2]

for i in range(n):
    val = li_a[i]

    if val not in li_top2:
        print((li_top2[0]))
    else:
        if val == li_top2[0] and d_a.get(val, 0) == 1:
            print((li_top2[1]))
        else:
            print((li_top2[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] = 0
    print((max(a)))
    a[i] = tmp

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

max_ = -1
max_2 = -1
for i in range(n):
    if i == 0:
        tmp = a[i]
        a[i] = 0
        max_ = max(a)
        print(max_)
        a[i] = tmp
        if a[0]>=max_:
            max_ = a[0]
        continue
    else:
        if max_<=a[i]:
            if max_2 == -1:
                tmp = a[i]
                a[i] = 0
                max_2 = max(a)
                print(max_2)
                a[i] = tmp
            else:
                print(max_2)
        else:
            print(max_)
# Original solution
N = int(eval(input()))
A = []
for _ in range(N):
  A.append(int(eval(input())))

for i in range(N):
  A_ = A.copy()
  A_[i] = 0
  print((max(A_)))

# Optimized solution
N = int(eval(input()))
max = 0
max2 = 0
n_max = 0
A = []
for _ in range(N):
  a = int(eval(input()))
  A.append(a)
  if a > max:
    max2 = max
    max = a
    n_max = 1
  elif a == max:
    n_max += 1
  elif a > max2:
    max2 = a

for a in A:
  if a == max:
    if n_max == 1:
      print(max2)
    else:
      print(max)
  else:
    print(max)
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
for _ in range(n):
  b=a[0:_]+a[_+1:n]
  print((max(b)))


# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
b=sorted(a)
f=b[-1]
s=b[-2]
for ans in a:
  if ans < f:
    print(f)
  else:
    print(s)
# Original solution
n=int(eval(input()))
s=[int(eval(input())) for i in range(n)]
for j in range(n):
    print((max(s[:j]+s[j+1:])))

# Optimized solution
#134c tle
n=int(eval(input()))
s=[int(eval(input())) for i in range(n)]
a=sorted(s)
max_=a[-1]
max_2=a[-2]
#print(s)
for i in range(n):
    if s[i]==max_:
        print(max_2)
    else:
        print(max_)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A_max = 0
for i in range(N):
  A_max = max(A_max,A[i])
cnt = 0
for j in range(N):
  if A_max == A[j]:
    cnt += 1
  if cnt == 2:
    for _ in range(N):
      print(A_max)
    exit()
A[A.index(A_max)] = 0
A_second = 0
for l in range(N):
  A_second = max(A_second,A[l])
for m in range(N):
  print((A_second if A[m] == 0 else A_max))

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

for i in range(n):
    m=0
    for j in range(n):
        if i == j:
            continue
        m=max(m,a[j])
    print(m)



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

m=max(a)
c=a.count(m)

if c > 1:
    for i in range(n):
        print(m)
else:
    s=sorted(a)[-2]
    for i in range(n):
        if a[i] != m:
            print(m)
        else:
            print(s)
# Original solution
n=int(eval(input()))
a=list(int(eval(input()))for _ in range(n))
b=sorted(a,reverse=True)
for i in range(n):
    if max(a)!=a[i]:
        print((max(a)))
    else:
     print((b[1]))

# Optimized solution
n=int(eval(input()))
a=list(int(eval(input()))for _ in range(n))
b=sorted(a,reverse=True)
for i in range(n):
    if b[0]!=a[i]:
        print((b[0]))
    else:
     print((b[1]))
# Original solution
n = int(eval(input()))
l = [int(eval(input())) for _ in range(n)]

for i in range(n):
  li = l[:i] + l[i+1:]
  print((max(li)))

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

for i in range(n):
  print((ls[-1] if l[i] != ls[-1] else ls[-2]))
# Original solution
N = int(eval(input()))
A = [0] * N
m = 0
for i in range(N):
    A[i] = int(eval(input()))
    if A[i] > m:
        m = A[i]
for i in range(N):
    if A[i] != m:
        print(m)
    else:
        A[i] = 0
        print((max(A)))
        A[i] = m

# Optimized solution
N = int(eval(input()))
A = [0] * N
for i in range(N):
    A[i] = int(eval(input()))
tmp = sorted(A)
m1 = tmp[-1]
m2 = tmp[-2]
for i in range(N):
    if A[i] != m1:
        print(m1)
    else:
        print(m2)
# Original solution
n=int(eval(input()))
l=[]
for i in range(n):
    x=int(eval(input()))
    l.append(x)
for i in range(n):
    x=l[i]
    l.pop(i)
    y=max(l)
    l.insert(i,x)
    print(y)

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

main()

# Optimized solution
def main():
    n = int(eval(input()))
    a = [int(eval(input())) for _ in range(n)]
    a_copy = sorted(a)
    a_max = a_copy[-1]
    a_second = a_copy[-2]
    for i in range(n):
        if a[i] == a_max:
            print(a_second)
        else:
            print(a_max)


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

max_val = max(a)

for i in range(n):
    if max_val > a[i]:
        print(max_val)

    elif max_val == a[i]:
        temp = a[i]
        a[i] = 0
        print((max(a)))
        a[i] = temp

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

max_val = max(a)
max_total = a.count(max_val) - 1

for i in range(n):
    if max_val > a[i]:
        print(max_val)

    elif max_val == a[i] and max_total != 0:
        print(max_val)
        max_total -= 1
    else:
        temp = a[i]
        a[i] = 0
        print((max(a)))
        a[i] = temp
# Original solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from copy import copy


def main():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]
    for i in range(N):
        tmp = copy(A)
        tmp[i] = 0
        print((max(tmp)))


if __name__ == "__main__":
    main()


# Optimized solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from copy import copy


def main():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]
    A_max = copy(A)
    A_max.sort(reverse=True)

    for a in A:
        if a == A_max[0]:
            print((A_max[1]))
        else:
            print((A_max[0]))


if __name__ == "__main__":
    main()
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
m=max(a)
for i in range(n):
  print((max([a[j] for j in range(n) if i!=j])))

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

max_indexs =  [i for i, x in enumerate(li) if x == max(li)]
li.sort()
max_val = li[-1]

if len(max_indexs) == 1:
    for i in range(N):
        if i == max_indexs[0]:
            print((li[-2]))
        else:
            print(max_val)
else:
    for i in range(N):
        print(max_val)

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

li2 = sorted(li)
max1 = li2[-1]
max2 = li2[-2]
max_index = li.index(max1)

if max1 != max2:
    for i in range(N):
        if i == max_index:
            print(max2)
        else:
            print(max1)
else:
    for i in range(N):
        print(max1)
# Original solution
def maxprint(A,i):
    a = list(A)
    a.pop(i)
    print((max(a)))

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


for i in range(N):
    maxprint(A,i)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
m1,m2,*_ = sorted(A)[::-1]

for i in A:
    if m1 == i:
        print(m2)
    else:
        print(m1)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
m1,m2,*_ = sorted(A)[::-1]

for i in A:
    if m1 == i:
        print(m2)
    else:
        print(m1)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
m1,m2 = sorted(A)[-2:]

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

max_num = max(string_list)

for j in string_list:
    if j != max_num:
        print(max_num)
    else:
        templist = copy.deepcopy(string_list)
        templist.remove(j)
        print((max(templist)))

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

sorted_list = sorted(string_list)
max_num = max(string_list)

for j in string_list:
    if j != max_num:
        print(max_num)
    else:
        print((sorted_list[-2]))
# Original solution
N=eval(input())
N=int(N)
A=[]
for i in range(N):
    b=eval(input())
    b=int(b)
    A.append(b)

max_value=max(A)
for i in range(N):
    if A[i]<max_value:
        print(max_value)
    else:
        data=A.pop(i)
    #    print(lst,i)
        print((max(A)))
        A.insert(i,data)


# Optimized solution
N=eval(input())
N=int(N)
A=[]
for i in range(N):
    b=eval(input())
    b=int(b)
    A.append(b)
flag=0
max_value=max(A)
for i in range(N):
    if flag==1:
        print(max_value)
    elif A[i]<max_value:
        print(max_value)
    else:
        data=A.pop(i)
        print((max(A)))
        A.insert(i,data)
        if max(A)==max_value:
            flag=1
# Original solution
N = int(eval(input()))
A = []

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

for i in range(N):
    tA = A.copy()
    # print(tA)
    tA.pop(i)
    print((max(tA)))

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

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

As = ld = sorted(A, reverse=True)
# print(As)
m = As[0:2]
# print(m)
for i in range(N):
    if A[i] == m[0]:
        print((m[1]))
    else:
        print((m[0]))
# Original solution
N = int(eval(input()))
A = []
import sys
input = sys.stdin.readline
for i in range(N):
  A.append(int(input().rstrip()))
from collections import Counter
counter = Counter(A)
B = sorted(set(A), key = A.index)
B = sorted(B, reverse = True)
max_A = B[0]
try:
  second_max = B[1]
except:
  second_max = B[0]
j = False
if counter[max_A] >= 2:
  j = True
for i in range(N):
  if A[i] == max_A and j == False:
    print(second_max)
  else:
    print(max_A)

# Optimized solution
N = int(eval(input()))
A = []
import sys
input = sys.stdin.readline
for i in range(N):
  A.append(int(input().rstrip()))
from collections import Counter
counter = Counter(A)
max_A = max(A)
#B = sorted(set(A), key = A.index)
#B = sorted(B, reverse = True)
#max_A = B[0]
try:
  second_max = sorted(set(A))[-2]
except:
  second_max = max_A
j = False
if counter[max_A] >= 2:
  j = True
for i in range(N):
  if A[i] == max_A and j == False:
    print(second_max)
  else:
    print(max_A)
# Original solution
N = int(eval(input()))
nums = [int(eval(input())) for _ in range(N)]

all_max = max(nums)
for num in range(N):
    if nums[num] == all_max:
        new_nums = list(nums)
        new_nums.pop(num)
        print((max(new_nums)))
    else:
        print(all_max)


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

all_max = max(nums)

new_nums = list(nums)
new_nums.remove(all_max)

second_max = max(new_nums)  # max関数はfor文の中にいれずに、先に2番目の最大値をもとめておく

for num in range(N):
    if nums[num] == all_max:
        print(second_max)
    else:
        print(all_max)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
for i in range(0, n-1):
    a_i = a[0:i] + a[i+1:n]
    print((max(a_i)))
print((max(a[0:n])))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a_sorted = sorted(a, reverse=True)
for i in range(0, n):
    if a[i]==a_sorted[0]:
        print((a_sorted[1]))
    else:
        print((a_sorted[0]))
# Original solution
def main():
    n = int(eval(input()))
    a = [int(eval(input())) for _ in range(n)]
    for _ in range(n):
        tmp = a.pop(0)
        print((max(a)))
        a.append(tmp)
   
    
if __name__ == '__main__':
    main()

# Optimized solution
def main():
    n = int(eval(input()))
    a = [int(eval(input())) for _ in range(n)]
    b = sorted(a, reverse=True)
    for i in range(n):
        if b[0] !=  a[i]:
            print((b[0]))
        else:
            print((b[1]))
   
    
if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))

A = []

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

for i in A:
    copy = A[:]
    copy.remove(i)
    print((max(copy)))

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

A = []

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

maxa = max(A)

copy = A[:]

copy.remove(maxa)

maxa2 = max(copy)

for i in A:
    if i == maxa:
        print(maxa2)
    else:
        print(maxa)
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
b=sorted(a,reverse=True)
x,y=b[0],b[1]
for i in range(n):
	if i==a.index(x):
		print(y)
	else:
		print(x)

# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
b=sorted(a,reverse=True)
x,y=b[0],b[1]
z=a.index(x)
for i in range(n):
	if i==z:
		print(y)
	else:
		print(x)
# Original solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
M=max(A)

for i in range(N):
    if M>A[i]:
        print(M)
    elif M==A[i]:
        A[i]=0
        print((max(A)))
        A[i]=M

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

for i in range(N):
    if M[N-1]>A[i]:
        print((M[N-1]))
    elif M[N-1]==A[i]:
        print((M[N-2]))
# Original solution
import copy

N = int(eval(input()))
l = []
for i in range(N):
  l.append(int(eval(input())))

mv = max(l)
for i in range(N):
  if l[i] < mv:
    print(mv)
  if l[i] == mv:
    a = copy.copy(l)
    del a[i]
    print((max(a)))


# Optimized solution
import copy

N = int(eval(input()))
l = []
for i in range(N):
  l.append(int(eval(input())))

mcnt = 0
mv = max(l)
for i in range(N):
  if l[i] == mv and mcnt == 0:
    a = copy.copy(l)
    del a[i]
    print((max(a)))
    mcnt = mcnt + 1
  else:
    print(mv)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
for i in A:
  AA = A.copy()
  AA.remove(i)
  print((max(AA)))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A)
MAX1, MAX2 = B[-1], B[-2]

for i in A:
  if i == MAX1:
    print(MAX2)
  else:
    print(MAX1)
# Original solution
N = int(eval(input()))
num_dict = {}

num_list = [int(eval(input())) for i in range(N)]
max_num = max(num_list)

for cnt in range(N):
  if num_list[cnt] == max_num:
    print((max(num_list[0:cnt] + num_list[cnt+1:])))
  else:
    print(max_num)

# Optimized solution
N = int(eval(input()))
num_list = [int(eval(input())) for i in range(N)]
max_num = max(num_list)
max_num_num = num_list.count(max_num)

for cnt in range(N):
  if num_list[cnt] == max_num and max_num_num == 1:
    print((max(num_list[0:cnt] + num_list[cnt+1:])))
  else:
    print(max_num)
# Original solution
def test():
    n = int(eval(input()))
    a = [int(eval(input())) for i in range(n)]
    s = 0
    for i in range(n):
        s = a[i]
        a[i] = 0
        print((max(a)))
        a[i] = s


if __name__ == "__main__":
    test()


# Optimized solution
def test():
    n = int(eval(input()))
    s = 0; t = 0; index_ = 0
    for i in range(n):
        a = int(eval(input()))
        if s < a:
            index_ = i
            s = a
        elif t < a and a <= s:
            t = a
    for i in range(n):
        if index_ == i:
            print(t)
        else:
            print(s)


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

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

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

tNum = max(a)
sNum = sorted(a, reverse=True)[1]

if a.count(tNum) > 1:
  for _ in range(n):
    print(tNum)
  exit()

for i in a:
  if i == tNum:
    print(sNum)
    continue
  print(tNum)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]

tNum = max(a)
sNum = sorted(a, reverse=True)[1]

if a.count(tNum) > 1:
  for _ in range(n):
    print(tNum)
  exit()

for i in a:
  if i == tNum:
    print(sNum)
    continue
  print(tNum)

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

num = sorted(a, reverse=True)[:2]
for i in a:
  if i != num[0]:
    print((num[0]))
  else:
    print((num[1]))
# Original solution
N = int(eval(input()))

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

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

print(ma)


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

A = []
for i in range(N):
    a = int(eval(input()))
    A.append([a, i])
    
A_ = sorted(A, reverse=True)

#print(A_)

for i in range(N):
    if A_[0][1] == i:
        print((A_[1][0]))
    else:
        print((A_[0][0]))
# Original solution
N=int(eval(input()))
AList = [int(eval(input())) for i in range(N)]

if AList.count(max(AList)) > 1:
    for i in range(N):
        print((max(AList)))
else:
    SList=sorted(AList)
    SecMax=SList[-2]
    MaxIndex=AList.index(max(AList))
    
    for i in range(N):
        if i==MaxIndex:
            print(SecMax)
        else:
            print((max(AList)))
    
    
    


# Optimized solution
N = int(eval(input()))
A = []
for i in range(N):
    A.append(int(eval(input())))
B = sorted(A)
for n in A:
    if B[-1] != n:
        print((B[-1]))
    else:
        print((B[-2]))
# Original solution
def main():
    N = int(eval(input()))
    A = []
    for n in range(N):
        A.append(int(eval(input())))

    max1_A = max(A)
    A_cp = sorted(A)
    A_cp.pop(-1)
    max2_A = max(A_cp)
    argmax_A = [i for i, x in enumerate(A) if x == max(A)]

    for a in A:
        if a == max1_A:
            print(max2_A)
        else:
            print(max1_A)
            
        
if __name__ == '__main__':
    main()


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

    A_cp = sorted(A)
    max1_A = A_cp.pop(-1)
    max2_A = max(A_cp)
    for a in A:
        if a == max1_A:
            print(max2_A)
        else:
            print(max1_A)
            
        
if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
 
for i in range(n):
    print((max(max(a[0:i], a[i+1:n]))))


# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
b = sorted(a)
b_max = b[-1]
b.pop(-1)
b_2max = b[-1]

for i in a:
    if i == b_max:
        print(b_2max)
    else:
        print(b_max)
# Original solution
N = int(eval(input()))
A = [eval(input()) for _ in range(N)]
tmp = 0
for i in range(N):
    if max(A) == A[i]:
        tmp = A.pop(i)
        print((max(A)))
        A.insert(i,tmp)
    else:
        print((max(A)))

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

for i in range(n):
    max = 0
    for j in range(n):
        if i != j:
            if max < a[j]:
                max = a[j]
    print(max)
            

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

highmax = 0
maxs=0
for i in range(n):
    if highmax < a[i]:
        highmax = a[i]
        maxs = i

for i in range(n):
    max = 0
    if maxs != i:
        print((a[maxs]))
    else:
        for j in range(n):
            if i != j:
                if max < a[j]:
                    max = a[j]
        print(max)