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

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

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

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

SA = sorted(A)
mx = max(A)

for i in range(N):
    if A[i] == mx:
        print((SA[-2]))
    else:
        print(mx)
# Original solution
n = int(eval(input()))
A = list([int(eval(input())) for _ in range(n)])

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

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

B = sorted(A)
max = B[-1]
for i in range(n):
    if A[i] != max:
        print(max)
    else:
        print((B[-2]))
# Original solution
n,*a=list(map(int,open(0)))
b=sorted(a)
for i in range(n):
    if a[i]==b[-1]:
        print((b[-2]))
    else:
        print((b[-1]))

# Optimized solution
n,*a=list(map(int,open(0)))
b=sorted(a)
for i in range(n):
    print(([b[-1],b[-2]][a[i]==b[-1]]))
# Original solution
N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)]
for i in range(len(a)):
  num = a[:]
  num.pop(i)
  print((max(num)))

# Optimized solution
N = int(input())
a = [int(input()) for _ in range(N)]
max_num = sorted(a, reverse=True)[0]
max_num2 = sorted(a, reverse=True)[1]
[print(max_num) if i!=max_num else print(max_num2) for i in a]
# Original solution
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]
for i in range(n):
  Ai = A[:]
  Ai.pop(i)
  print((max(Ai)))


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

sort = sorted(A)

max = sort[-1]
maxx = sort[-2]

for i in range(n):
  if max == A[i]:
    print(maxx)
  else:
    print(max)
# Original solution
n=int(eval(input()))
d=[]
for i in range(n):
  d.append(int(eval(input())))
x=sorted(d)
for j in range(n):
  if d[j]==max(d):
    print((x[n-2]))
  else:
    print((max(d)))

# Optimized solution
n=int(eval(input()))
d=[]
for i in range(n):
  d.append(int(eval(input())))
x=sorted(d)
for j in range(n):
  if d[j]==x[-1]:
    print((x[-2]))
  else:
    print((x[-1]))
# Original solution
n=int(eval(input()))
d=[]
for i in range(n):
  d.append(int(eval(input())))
x=sorted(d)
for j in range(n):
  if d[j]==x[-1]:
    print((x[-2]))
  else:
    print((x[-1]))



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

for i in range(n):
  if s[-1]==d[i]:
    print((s[-2]))
  else:
    print((s[-1]))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]

sortA = sorted(a, reverse=True)
maxA = sortA[0]
semiMaxA = sortA[1]

for i in range(n):
  if a[i] == maxA:
    print(semiMaxA)
  else:
    print(maxA)

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


def solve(N: int, A: "List[int]"):
    B = sorted(A)
    max_A = B[-1]
    submax_A = B[-2]
    for i in range(N):
        if A[i] == max_A:
            print(submax_A)
        else:
            print(max_A)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
B = A[:]
max_A = max(A)
for i in range(n):
    if A[i] == max_A:
        B[i] = 0
        print((max(B)))
        B[i] = max_A
    else:
        print(max_A)

# Optimized solution
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
B = A[:]
B.sort(reverse = True)
max_A = max(A)
for i in range(n):
    if A[i] == max_A:
        print((B[1]))
    else:
        print(max_A)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b, c = sorted(a)[-2:]
for i in range(n):
    print((b if a.index(c) == i else c))


# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b, c = sorted(a)[-2:]
j = a.index(c)
for i in range(n):
    print(((c, b)[i == j]))
# Original solution
def main():
    N = int(eval(input()))
    A = []
    for i in range(N):
        A.append(int(eval(input())))
    for j in range(N):
        a = A[j]
        A[j] = -1
        print((max(A)))
        A[j] = a


if __name__ == '__main__':
    main()

# Optimized solution
def main():
    N = int(eval(input()))
    maximum = 0
    next_maximum = 0
    A = []
    for _ in range(N):
        a = int(eval(input()))
        A.append(a)
        if a > maximum:
            maximum = a
        elif a > next_maximum:
            next_maximum = a
    for b in A:
        if b == maximum:
            print(next_maximum)
        else:
            print(maximum)


if __name__ == '__main__':
    main()
# Original solution
import sys
import math
import copy
a = int(eval(input()));
b = [int(eval(input())) for i in range(a)];
c = 0;
first = max(b);
g = b.copy();
h = g.index(first);
del g[h];
second = max(g);

for i in range(a):
    if max(b) > b[i]:
        print(first);
    elif first == b[i]:
        print(second);

# Optimized solution
import sys
import math
import copy
a = int(eval(input()));
b = [int(eval(input())) for i in range(a)];
c = 0;
first = max(b);
g = b.copy();
h = g.index(first);
del g[h];
second = max(g);

for i in range(a):
    if first > b[i]:
        print(first);
    elif first == b[i]:
        print(second);
# Original solution
n=int(eval(input()))
A=[int(eval(input())) for i in range(n)]
if n==2:
  print((A[1]))
  print((A[0]))
  exit()

for i in range(n):
  if i==0:
    q=max(A[1:])
    print(q)
    continue
  if A[i]!=q:
    print(q)
  else:
    print((max(A[:i]+A[i+1:])))


# Optimized solution
n=int(eval(input()))
A=[int(eval(input())) for i in range(n)]
B=sorted(A)
f=B[-1]
s=B[-2]
q=A.index(f)

for i in range(q):
  print(f)
print(s)
for i in range(n-q-1):
  print(f)
# Original solution
import copy
s=[]
i=0
n=int(eval(input()))
while i!=n:
    s.append(int(eval(input())))
    i+=1
maxx=max(s)
g=s.count(maxx)
i=0

#print(g)
while i!=n:

    a=s[0]
    del s[0]
    if maxx==a and g<2:
        print((max(s)))
    else:
        print(maxx)


    s.append(a)
    i+=1

# Optimized solution
import copy
s=[]
i=0
n=int(eval(input()))
while i!=n:
    s.append(int(eval(input())))
    i+=1
maxx=max(s)
g=s.count(maxx)
i=0
j=0

#print(g)
while i!=n:
    a = s[j]
    if maxx == a and g < 2:
        a=s[j]
        del s[j]
        print((max(s)))
        s.append(a)
    else:
        print(maxx)
        j+=1

    i+=1
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
m=max(a)
for i in range(n):
  if a[i]>=m:
    print((max(a[:i]+a[i+1:])))
  else:
    print(m)


# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
s=sorted(a, reverse=True)
m=s[0]
for i in range(n):
  if a[i]>=m:
    print((s[1]))
  else:
    print(m)
# Original solution
import sys

def solve(n, d):
    d_sorted = sorted(d, reverse=True)
    for i in range(n):
        print(d_sorted[0] if d[i] != d_sorted[0] else d_sorted[1])


if __name__ == '__main__':

    n = int(sys.stdin.readline().strip())
    d = []
    for i in range(n):
        d.append(int(sys.stdin.readline().strip()))
    solve(n, d)

# Optimized solution
import sys

input = sys.stdin.readline
N = int(eval(input()))

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

for i, a in enumerate(sorted(A, reverse=True)):
    if i == 0:
        first = a
    elif i == 1:
        second = a
    else:
        break
# print(first, second)

for a in A:
    if a == first:
        print(second)
    else:
        print(first)
# Original solution
import copy
from sys import stdin
n=int(eval(input()))
A=[int(stdin.readline().rstrip()) for _ in range(n)]
for j in range(0,n):
    B=copy.copy(A)
    s=A[j]
    A.pop(j)
    print((max(A)))
    A = copy.copy(B)

# Optimized solution
import copy
from sys import stdin
n=int(eval(input()))
A=[int(stdin.readline().rstrip()) for _ in range(n)]
z=max(A)
B=sorted(A)
o=B[n-2]
for j in range(0,n):
    if A[j]<z:
       print(z)
    else:
        if B[n-2]==B[n-1]:
           print(z)
        else:
           print(o)
# Original solution
N = int(eval(input()))
List = []

for i in range(1,N+1):
  List.append(int(eval(input())))
list1 = List.copy()
List.sort(reverse=True)
MAX = List[0]
SEC_MAX = List[1]
for i in list1:
  if i != MAX:
    print(MAX)
  else:
    print(SEC_MAX)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
B = sorted(A,reverse=True)
MAX1 = B[0]
MAX2 = B[1]

for x in A:
  if x == MAX1:
    print(MAX2)
  else:
    print(MAX1)
# Original solution
n = int(eval(input()))
a = ["" for i in range(n)]
for i in range(n):
	a[i] = int(eval(input()))

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


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

a_sort = sorted(a)
max = a_sort[-1]
second = a_sort[-2]

for i in range(n):
	if a[i] == max:
		print(second)
	else:
		print(max)
# Original solution
if __name__ == '__main__':
    n = int(eval(input()))
    a_list = []
    for i in range(n):
        a = int(eval(input()))
        a_list.append(a)

    for i in range(n):
        cp = a_list.copy()
        del cp[i]
        print((max(cp)))

# Optimized solution
if __name__ == '__main__':
    n = int(eval(input()))
    a_list = []
    max_num = 0
    second_max = 0
    max_count = 0
    for i in range(n):
        a = int(eval(input()))
        a_list.append(a)
        if a > max_num:
            max_num = a
            max_count = 1
        elif a > second_max:
            second_max = a

    for i in range(n):
        if a_list[i] != max_num:
            print(max_num)
        else:
            print(second_max)
# Original solution
# -*- coding: UTF-8 -*-

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

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

print((max(a[:n])))


# Optimized solution
# -*- coding: UTF-8 -*-

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

p = a.index(max(a))

for i in range(n):
    if i == p:
        print((b[1]))
    else:
        print((b[0]))
# Original solution
N, *d = list(map(int, open(0).read().split()))
m=d.index(max(d))
c=[max(d)] *N
  
for j in range(N):
    d[m]=0
    y=max(d)

c[m]=y
for i in range(len(c)):
    print((c[i]))
 

# Optimized solution
N, *d = list(map(int, open(0).read().split()))
m=d.index(max(d))
c=[max(d)] *N
d[m]=0
y=max(d)
c[m]=y
for i in range(len(c)):
    print((c[i]))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
B = sorted(A)
for i in range(N):
    print((B[-2] if A[i] == B[-1] else B[-1]))


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

a = []

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

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

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

a = []

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

a_max = max(a)
a_max_index = a.index(a_max)

a.sort(reverse=True)
a_second_max = a[1]

for i in range(n):
    if i == a_max_index:
        print(a_second_max)
    else:
        print(a_max)
# Original solution
n = int(eval(input()))
lis = []

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

for i in range(n):
	x = lis.pop(i)
	print((max(lis)))
	lis.insert(i,x)

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

for i in range(n):
	a = int(eval(input()))
	lis.append(a)
kou = sorted(lis, reverse=True)

for i in range(n):
	if lis[i] < kou[0]:
		print((kou[0]))
	else:
		print((kou[1]))
# Original solution
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(eval(input()))
    l=[int(eval(input())) for i in range(n)]
    if len(set(l))==1:
        for i in range(n):
            print((max(l)))
    else:
        biggest = max(l)
        lsort=sorted(l)
        niban=lsort[-2]
        for j in range(n):
            if l[j]!=biggest:
                print(biggest)
            else:
                print(niban)
resolve()

# Optimized solution
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(eval(input()))
    l=[int(eval(input())) for i in range(n)]
    biggest = max(l)
    lsort=sorted(l)
    niban=lsort[-2]
    for j in range(n):
        if l[j]!=biggest:
            print(biggest)
        else:
            print(niban)
resolve()
# Original solution
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(eval(input()))
    l=[int(eval(input())) for i in range(n)]
    biggest = max(l)
    lsort=sorted(l)
    niban=lsort[-2]
    for j in range(n):
        if l[j]!=biggest:
            print(biggest)
        else:
            print(niban)
resolve()

# Optimized solution
import sys
def input(): return sys.stdin.readline().strip()
def resolve():
    n=int(eval(input()))
    l=[int(eval(input())) for i in range(n)]
    l1=sorted(l,reverse=True)
    for j in range(n):
        if l[j]!=l1[0]:
            print((l1[0]))
        else:
            print((l1[1]))
resolve()
# Original solution
N = int(eval(input()))
a = []
for i in range(N):
  a.append(int(eval(input())))

for i in range(N):
  b = a[:]
  b.pop(i)
  print((max(b)))


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

sort = sorted(a)
m1 = sort[-1]
m2 = sort[-2]
if m1 == m2:
  for i in range(N):
    print(m1)
else:
  j = a.index(m1)
  for i in range(N):
    if i == j:
      print(m2)
    else:
      print(m1)
# Original solution
N = int(eval(input()))
lst_A = [int(eval(input())) for _ in range(N)]
srt_A = sorted(lst_A, reverse=True)
m1 = srt_A[0]
m2 = srt_A[1]


for v in lst_A:
    print((m2 if v == m1 else m1))

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


N = int(eval(input()))
lst_A = [int(eval(input())) for _ in range(N)]
srt_A = sorted(lst_A, reverse=True)
m1 = srt_A[0]
m2 = srt_A[1]


for v in lst_A:
    print((m2 if v == m1 else m1))
# Original solution
import sys
#import numpy as np
import math
from fractions import Fraction
import itertools

input=sys.stdin.readline
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(max(a[:i]),max(a[i+1:]))))
    
print((max(a[:n-1])))

# Optimized solution
import sys
#import numpy as np
import math
from fractions import Fraction
import itertools

input=sys.stdin.readline
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
l=[0]*n
r=[0]*n
l[0]=a[0]
r[0]=a[-1]
for i in range(1,n):
    if a[i]>l[i-1]:
        l[i]=a[i]
    else:
        l[i]=l[i-1]
    if a[n-1-i]>r[i-1]:
        r[i]=a[n-1-i]
    else:
        r[i]=r[i-1]
print((r[n-2]))
for i in range(1,n-1):
    print((max(l[i-1],r[n-i-2])))
print((l[n-2]))
# Original solution
N = int(eval(input()))
A = [0]*N
for i in range(N):
    A[i] = int(eval(input()))

for j in range(N):
    B = A[0:j]
    C = A[j+1:N]
    D = B+C
    print((max(D)))

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

mx = max(A)
mxidx = A.index(mx)

for i in range(N):
    if i == mxidx:
        B = A[0:i] + A[i+1:N]
        print((max(B)))
    else:
        print(mx)
# 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.pop(i)
    print((max(_a)))


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

m = max(a)
idxs = [i for i, v in enumerate(a) if v == m]

if len(idxs) > 1:
    for i in range(n):
        print(m)

if len(idxs) == 1:
    idx = idxs[0]
    for i in range(n):
        if idx == i:
            _a = a.copy()
            _a.pop(i)
            print((max(_a)))
        else:
            print(m)
# Original solution
# -*- coding: utf-8 -*-

N = int(eval(input()))

values = [0]*N
value_count_map = {}
for i in range(N):
    in_value = int(eval(input()))
    values[i] = in_value
    value_count = 0
    if in_value in value_count_map:
        value_count = value_count_map[in_value]
    value_count_map[in_value] = value_count + 1

for row in range(N):
    row_value = values[row]
    max_value = max(value_count_map.keys())
    if row_value != max_value:
        print(max_value)
    elif value_count_map[row_value] != 1:
        print(max_value)
    else:
        # if row value is a unique max value
        value_count = value_count_map.pop(row_value)
        max_value = max(value_count_map.keys())
        print(max_value)
        value_count_map[row_value] = value_count




# Optimized solution
# -*- coding: utf-8 -*-

N = int(eval(input()))

values = [0]*N
value_count_map = {}
for i in range(N):
    in_value = int(eval(input()))
    values[i] = in_value
    value_count = 0
    if in_value in value_count_map:
        value_count = value_count_map[in_value]
    value_count_map[in_value] = value_count + 1

max_value = max(value_count_map.keys())
value_count = value_count_map.pop(max_value)
if value_count == 1:
    next_max_value = max(value_count_map.keys())
for row in range(N):
    if value_count > 1:
        print(max_value)
    elif values[row] == max_value:
        print(next_max_value)
    else:
        print(max_value)
# Original solution
# ABC134C - Exception Handling
def main():
    N, *A = list(map(int, open(0)))
    sorted_A = sorted(A)
    m1, m2 = sorted_A[-1], sorted_A[-2]
    ans = [m1 if i != m1 else m2 for i in A]
    print(("\n".join(map(str, ans))))


if __name__ == "__main__":
    main()

# Optimized solution
# ABC134C - Exception Handling
def main():
    N, *A = list(map(int, open(0)))
    m1, m2 = sorted(A, reverse=1)[:2]
    ans = [m1 if i != m1 else m2 for i in A]
    print(("\n".join(map(str, ans))))


if __name__ == "__main__":
    main()
# Original solution
#coding : utf-8

import os
import sys

def except_i(a, i):
	return a[0:i] + a[i+1:len(a)]

N = int(eval(input()))

A = []

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


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



# Optimized solution
#coding : utf-8

import os
import sys

N = int(eval(input()))

A = []

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

X = [[A[i], i] for i in range(N)]


X.sort(key = lambda x: x[0], reverse=True)


for i in range(N):
	if i != X[0][1]:
		print((X[0][0]))
	else:
		print((X[1][0]))
# Original solution
#coding : utf-8

import os
import sys

N = int(eval(input()))

A = []

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

X = [[A[i], i] for i in range(N)]


X.sort(key = lambda x: x[0], reverse=True)


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



# Optimized solution
#coding : utf-8

import os
import sys

N = int(eval(input()))

A = []

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


Amax = max(A)

i = A.index(Amax)
t = A[i]
A[i] = 0
A2nd = max(A)
A[i] = t

for i in range(N):
	if A[i] == Amax:
		print(A2nd)
	else:
		print(Amax)
# Original solution
N = int(eval(input()))

nums = [int(eval(input())) for x in range(N)]

copys = nums.copy()

for ind in range(N):
    copys.pop(ind)
    print((max(copys)))
    copys = nums.copy()

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

nums = [int(eval(input())) for x in range(N)]

a = sorted(nums)[-1]#max(nums)
b = sorted(nums)[-2]#max(nums.remove(max_num))



if a == b:
    for _ in nums:
        print(a)
else:
    for x in [b if x == a else a for x in nums]:
        print(x)
# Original solution

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

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

# 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):
    ans = a_s[0]
    if a[i]==a_s[0]:
        ans = a_s[1]
    
    print(ans)
# Original solution
N=int(eval(input()))
a_list=[]
for i in range(N):
    a_list.append(int(eval(input())))
 
for i in range(len(a_list)):
    tmp=[x for j,x in enumerate(a_list) if i!=j]
    print((max(tmp)))

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

tmp=sorted(a_list)[::-1]
one=tmp[0]
two=tmp[1]
for i in range(len(a_list)):
    if a_list[i]==one:
        print(two)
    else:
        print(one)
# Original solution
N = int(eval(input()))
a_list = []
max_v = -1
max_ind = []
for i in range(N):
    a_list.append(int(eval(input())))
    if a_list[-1]>max_v:
        max_v = a_list[-1]
        max_ind = [i]
    elif a_list[-1]==max_v:
        max_ind.append(i)
del a_list[max_ind[-1]]
sec = max(a_list)
for i in range(N):
    if i in max_ind:
        print(sec)
    else:
        print(max_v)
        

# Optimized solution
N = int(eval(input()))
a_list = []
max_v = -1
sec = -1
tmp = 0
drop = False
max_ind = []
for i in range(N):
    a_list.append(int(eval(input())))
    if a_list[-1]>max_v:
        tmp = max_v
        max_v = a_list[-1]
        max_ind = [i]
    elif a_list[-1]<max_v:
        if a_list[-1]>sec:
            drop = True
            sec = a_list[-1]
    else:
        max_ind.append(i)
if len(max_ind)>1:
    for i in range(N):
        print(max_v)
elif drop:
    for i in range(N):
        if i in max_ind:
            print(sec)
        else:
            print(max_v)
else:
    for i in range(N):
        if i in max_ind:
            print(tmp)
        else:
            print(max_v)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
max_A = max(A)
for i in range(N):
    if A[i] == max_A:
        print((max(A[:i]+A[i+1:])))
    else:
        print(max_A)
    

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

inx=a.index(max(a))
a_s=sorted(a)

for i in range(n):
 print((a_s[-1] if inx!=i else a_s[-2]))

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

for i in a:
  if i==a2[0]:
    print((a2[1]))
  else:
    print((a2[0]))
# Original solution
N = int(eval(input()))
numbers_full = [int(eval(input())) for _ in range(N)]

numbers_minus1 = numbers_full
for i, tmp in enumerate(numbers_full):
  numbers_minus1[i] = 0
  print((str(max(numbers_minus1))))
  numbers_minus1[i] = tmp

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

sorted_num = sorted(number_list)
number_max = sorted_num[-1]
number_second_max = sorted_num[-2]

if number_max == number_second_max:
  output_always_max = True
else:
  output_always_max = False

for number in number_list:
  if output_always_max:
    print((str(number_max)))
  else:
    if number == number_max:
      print((str(number_second_max)))
    else:
      print((str(number_max)))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]

for i in range(n):
  ans = max(a)
  if a[i] == ans:
    temp = ans
    a.remove(ans)
    ans = max(a)
    a.insert(i, temp)
  print(ans)



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

sorted_a = sorted(a)
max_a = sorted_a[-1]
max_a_r = sorted_a[-2]

for i in range(n):
  if a[i] == max_a:
    print(max_a_r)
  else:
    print(max_a)
# Original solution
n = int(eval(input()))
li = list(int(eval(input())) for i in range(n))

for i in range(n):
  li_copy = li.copy()
  del li_copy[i]
  print((max(li_copy)))

# Optimized solution
n = int(eval(input()))
li = list(int(eval(input())) for i in range(n))

sorted_li = sorted(li)
a, b = sorted_li[-1], sorted_li[-2]

for i in li:
  if i == a:
    print(b)
  else:
    print(a)