Problem:
 Score : 300 points    Problem Statement You are given a sequence of length N : A_1, A_2, ..., A_N .
For each integer i between 1 and N (inclusive), answer the following question:   Find the maximum value among the N-1 elements other than A_i in the sequence.       Constraints  2 \leq N \leq 200000  1 \leq A_i \leq 200000  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  A_1  :  A_N       Output Print N lines. The i -th line ( 1 \leq i \leq N ) should contain the maximum value among the N-1 elements other than A_i in the sequence.        Sample Input 1 3
1
4
3      Sample Output 1 4
3
4   The maximum value among the two elements other than A_1 , that is, A_2 = 4 and A_3 = 3 , is 4 .  The maximum value among the two elements other than A_2 , that is, A_1 = 1 and A_3 = 3 , is 3 .  The maximum value among the two elements other than A_3 , that is, A_1 = 1 and A_2 = 4 , is 4 .        Sample Input 2 2
5
5      Sample Output 2 5
5

Solution (Python):
N =int(input())
A = [0]*N
a = 0
b = 0
for i in range(N):
    x = int(input())
    if x > a:
        b = a
        a = x
    elif x > b:
        b = x
    A[i] = x

for c in A:
    if c == a:
        print(b)
    else:
        print(a)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
s, f = sorted(a)[-2:]

for ai in a:
    print(f if ai != f else s)

Solution (Python):
n=int(input())
m1=0
s1=0
m2=0
l=[]
for i in range(n):
  n1=int(input())
  l.append(n1)
  if n1>m1:
    m2=m1
    m1=n1    
    s1=0
  elif n1==m1:
    s1+=1
  elif n1>m2:
    m2=n1
if s1>0:
  for i in range(n):
    print(m1)
else:
  for i in range(n):
    if m1==l[i]:
      print(m2)
    else:
      print(m1)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
x,y = sorted(A)[-2:]
for a in A :
    print(y if a != y else x)

Solution (Python):
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
b = sorted(a)
max1 = b[-1]
max2 = b[-2]
for i in range(n):
    if a[i] == max1:
      print(max2)
    else:
      print(max1)

Solution (Python):
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
sorted_A = list(set(A))
max_A = sorted_A[-1]
max_nums = set(i for i, v in enumerate(A) if v == max_A)
if len(max_nums) > 1:
    for i in range(N):
        print(max_A)
else:
    max2_A = sorted_A[-2]
    for i in range(N):
        if i in max_nums:
            print(max2_A)
        else:
            print(max_A)

Solution (Python):
N = int(input())

A = []

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

max_value = max(A)           

max_index = A.index(max_value)

B = A[:]

del B[max_index]

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

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]

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

Solution (Python):
n = int(input())
a = [0 for n in range(n)]
for i in range(n):
  a[i] = int(input())
a_max = max(a)
b = sorted(a)
a_second = b[n-2]
for j in range(n):
  if a[j] != a_max:
    print(a_max)
  else:
    print(a_second)

Solution (Python):
N=int(input())
A=[[i,int(input())] for i in range(N)]
A.sort(key=lambda x:x[1],reverse=True)
j=A[0][0]
b1=A[0][1]
b2=A[1][1]
for i in range(N):
  print(b2 if i==j else b1)

Solution (Python):
n,*a=map(int,open(0))
b=sorted(a)
for i in a:
  if(b[-1]!=i):
    print(b[-1])
  else:
    print(b[-2])

Solution (Python):
def main12():
    n = int(input())
    nlist = []
    for i in range(n):
        nlist.append(int(input()))
    maxnum = max(nlist)
    c = nlist.count(maxnum)
    if c > 1:
        for i in range(n):
            print(maxnum)
    else:
        l = nlist.index(maxnum)
        nlist[l] = 0
        maxnum2 = max(nlist)
        for i in range(n):
            if i != l:
                print(maxnum)
            else:
                print(maxnum2)

if __name__ == "__main__":
    main12()

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
m = max(a)
mi = a.index(m)
for i in range(n):
    if i == mi:
        ma = max(a[: i] + a[i + 1: ])
        print(ma)
    else:
        print(m)

Solution (Python):
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
b=sorted(a)
m,M=b[-2:]
for i in range(n): print(m if a[i]==M else M)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
m = max(a)

if a.count(m) > 1:
    for _ in range(n):
        print(m)
else:
    mi = a.index(m)
    for i in range(n):
        if i == mi:
            ma = max(a[: i] + a[i + 1: ])
            print(ma)
        else:
            print(m)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
m = max(a)

if a.count(m) > 1:
    for _ in range(n):
        print(m)
else:
    for i in range(n):
        if a[i] == m:
            a[i] = 0
            ma = max(a)
            print(ma)
        else:
            print(m)

Solution (Python):
N = int(input())
ai = []
for i in range(N):
    ai.append(int(input()))

first = -1
second = -1
for i in ai:
    if first < i:
        second = first
        first = i
    elif second < i:
        second = i

for x in ai:
    if x == first:
        print(second)
    else:
        print(first)

Solution (Python):
N = int(input())
ai = []
for i in range(N):
    ai.append(int(input()))
first = max(ai)
ai_ = ai[:]
ai_.remove(first)
second = max(ai_)

for x in ai:
    if x == first:
        print(second)
    else:
        print(first)

Solution (Python):
n = int(input())
arr = []
fst = 0
scd = 0
for i in range(n):
  t = int(input())
  fst, scd = sorted([fst, scd, t], reverse=True)[:2]
  arr.append(t)

for i in range(n):
  print(fst if arr[i]!=fst else scd)

Solution (Python):
while True:
    n=int(input())
    if(2<=n<=200000):
        break
a=[]
for i in range(n):
        a.append(int(input()))
ma=a[0]
b=0
for j in range(1,n):
    if(ma==a[j]):
        b=a[j]
    if(ma<a[j]):
        ma=a[j]
        continue
    if(b<a[j]):
        b=a[j]
for l in range(n):
    if(a[l]!=ma):
        print(str(ma))
    else:
        print(str(b))

Solution (Python):
l=[]
a=int(input())
for i in range(a):
  b=int(input())
  l.append(b)
c=l.copy()
c.sort()
max1=c[-1]
max2=c[-2]

for i in l:
  if i==max1:
    print(max2)
  else:
    print(max1)

Solution (Python):
N = int(input())
A = []
 
for _ in range(N):
    A.append(int(input()))
    
a = b = 0
    
for i in range(N):
    if A[i] >= a:
        b = a
        a = A[i]
    elif A[i] > b:
        b = A[i]
 
for i in range(N):
    if A[i] < a:
        print(a)
    else:
        print(b)

Solution (Python):
n=int(input())
ls=[]
for i in range(n):
    a=int(input())
    ls.append(a)
ls_sort=sorted(ls)
for s in ls:
    if s==ls_sort[-1]:
        print(ls_sort[-2])
    else:
        print(ls_sort[-1])

Solution (Python):
import sys
input = sys.stdin.readline
  
def solve():
  n = int(input())
  maxi = -10
  maxi2 = -10
  place = -1
  for i in range(n):
    a = int(input())
    if a>maxi:
      maxi2 = maxi
      maxi = a
      place = i
    else:
      maxi2 = max(maxi2,a)
  for j in range(n):
    if place == j:
      print(maxi2)
    else:
      print(maxi)
  
solve()

Solution (Python):

def solve():
  n = int(input())
  maxi = -10
  maxi2 = -10
  place = -1
  for i in range(n):
    a = int(input())
    if a>maxi:
      maxi2 = maxi
      maxi = a
      place = i
    else:
      maxi2 = max(maxi2,a)
  for j in range(n):
    if place == j:
      print(maxi2)
    else:
      print(maxi)
  
solve()

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
m = max(A)
x = A.index(m)
m2 = max(A[:x] + A[x + 1:])
ans = [m for _ in range(N)]
ans[x] = m2
for i in range(N):
    print(ans[i])

Solution (Python):
import sys
input = sys.stdin.readline
  
def solve():
  n = int(input())
  maxi = -10
  maxi2 = -10
  place = -1
  for i in range(n):
    a = int(input())
    if a>maxi:
      maxi2 = maxi
      maxi = a
      place = i
    else:
      maxi2 = max(maxi2,a)
  for j in range(n):
    if place == j:
      print(maxi2)
    else:
      print(maxi)
  
solve()

Solution (Python):
from sys import stdin
import numpy as np
from operator import itemgetter

N = int(stdin.readline().rstrip().split()[0])
A = []
for i in range(N):
    A.append(int(stdin.readline().rstrip().split()[0]))

L_max = [0]
R_max = [0]

for i in range(N-1):
    L_max.append(max(L_max[-1], A[i]))

for i in range(N-1,0,-1):
    R_max.append(max(R_max[-1], A[i]))

R_max=R_max[::-1]
noi_max = []
for i in range(N):
    noi_max.append(max(L_max[i], R_max[i]))

for i in range(N):
    print(noi_max[i])

Solution (Python):
n=int(input())
A=[int(input()) for i in range(n)]
b=list(set(A))
if A.count(max(A))>1:
    ans=max(b)
    for i in range(n):
        print(ans)
    exit()

mi,maxi=b[-2:]
for a in A:
    if a==maxi:
        print(mi)
    else:
        print(maxi)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
B = sorted(A)

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

Solution (Python):
N = int(input())

biggest = 0
secandBiggest = 0
A = [0 for i in range(N)]
for i in range(N):
  A[i] = int(input())
  if(biggest <= A[i]):
    secandBiggest = biggest
    biggest = A[i]
  elif(secandBiggest <= A[i]):
    secandBiggest = A[i]
    
for i in range(N):
  if(A[i] == biggest):
    print(secandBiggest)
  else:
    print(biggest)

Solution (Python):
import math
import fractions
import copy
import numpy as np

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
n = ip()
a = []
ma = 1
mnum = -1
for i in range(n):
  a.append(ip())
  if mnum < a[i]:
    ma = 1
    mnum = a[i]
  elif mnum == a[i]:
    ma+=1
for i in range(n):
  if a[i] != mnum or ma>1:
    print(mnum)
  elif a[i] == mnum:
    b = copy.copy(a)
    b.pop(i)
    print(max(b))

Solution (Python):
n=int(input())
a=[int(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)

Solution (Python):
num = int(input())
box = [int(input()) for _ in range(num)]
box_dash = sorted(box, reverse=True)
for b in box:
  if b == box_dash[0]:
    print(box_dash[1])
  else:
    print(box_dash[0])

Solution (Python):
N = int(input())
A = [ int(input()) for _ in range(N) ]
B = A[:]
B.sort()
for a in A:
  if a == B[N-1]:
    print(B[N-2])
  else:
    print(B[N-1])

Solution (Python):
n=int(input())
a=[int(input()) for i in range(n)]

maxa = max(a[0],a[1])
mina = min(a[0],a[1])

for i in range(2,n):
    if a[i] >= maxa:
        mina = maxa
        maxa = a[i]
    elif a[i] >mina:
        mina = a[i]

for i in range(n):
    if a[i] == maxa:
        print(mina)
    else:
        print(maxa)

Solution (Python):
n=int(input())
a=[int(input())for _ in range(n)]
left=[0]
for i in a:
  left.append(max(left[-1],i))
right=[0]
for i in reversed(a):
  right.append(max(right[-1],i))
right.reverse()
for i in range(n):
  print(max(left[i],right[i+1]))

Solution (Python):
N, *l = map(int, open(0).read().split())

l_b = sorted(l)
max_a = l_b[-1]
max_b = l_b[-2]

for j in range(N):
    if max_a == l[j]:
        print(max_b)
    else:
        print(max_a)

Solution (Python):
import numpy as np

N = int(input())
A = []

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

B = np.array(A)
C = B.argsort()[::-1]

fuji_i = C[0]
kita_i = C[1]
fuji = A[C[0]]
kita = A[C[1]]

for i in range(N):
    if i != fuji_i:
        print(fuji)
    else:
        print(kita)

Solution (Python):
import sys
input = sys.stdin.readline

import numpy as np

N = int(input())
A = np.array([int(input()) for _ in range(N)])

from_left = np.maximum.accumulate(A)
from_right = np.maximum.accumulate(A[::-1])[::-1]

from_left, from_right

from_left = [0] + from_left.tolist()[:-1]
from_right = from_right[1:].tolist() + [0]

for x,y in zip(from_left, from_right):
    print(x if x > y else y)

Solution (Python):
n = int(input())
l = []
for i in range(n):
    l.append(int(input()))

l_b = sorted(l)
max_a = l_b[-1]
max_b = l_b[-2]

for j in range(len(l)):
    if max_a == l[j]:
        print(max_b)
    else:
        print(max_a)

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

max1 = max(A[0], A[1])
max2 = min(A[1], A[0])
if A[0] > A[1]:
    maxi1 = 0
    maxi2 = 1
else:
    maxi1 = 1
    maxi2 = 0


for i, a in enumerate(A[2:], 2):
    if max1 < a:
        max2 = max1
        maxi2 = maxi1
        max1 = a
        maxi1 = i
    elif max2 < a:
        max2 = a
        maxi2 = i

for i in range(N):
    if i != maxi1:
        print(max1)
    else:
        print(max2)

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

max1 = max(A[0], A[1])
max2 = min(A[1], A[0])
if A[0] > A[1]:
    maxi1 = 0
    maxi2 = 1
else:
    maxi1 = 1
    maxi2 = 0


for i, a in enumerate(A[2:], 2):
    if max1 < a:
        max2 = max1
        maxi2 = maxi1
        max1 = a
        maxi1 = i
    elif max2 < a:
        max2 = a
        maxi2 = i

for i in range(N):
    if i != maxi1:
        print(max1)
    else:
        print(max2)

Solution (Python):
N =int(input())
n=[]
for i in range(N):
	n.append(int(input()))

mx = max(n)
m = n.index(mx)
b = sorted(n)
my = b[N-2]

for i in range(N):
	if i == m:
		print(my)
	else:
		print(mx)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
B = []
for i, a in enumerate(A):
    B.append((i, a))
B.sort(key=lambda x: x[1], reverse=True)
for i in range(N):
    if i==B[0][0]:
        print(B[1][1])
    else:
        print(B[0][1])

Solution (Python):
n = int(input())
a = []
prem = 0
m = 0
j = 0
for i in range(n):
    a.append(int(input()))
for i in range(n):
    if a[i] > m:
        prem = m
        m = a[i]
    elif a[i] > prem:
        prem = a[i]
for i in range(n):
    if a[i] == m:
        print(prem)
    else:
        print(m)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
first = max(A)
second = sorted(A)[:: -1][1]
for ai in A:
	if ai == first:
		print(second)
	else:
		print(first)

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

a = max(A)
A_max = []
A_ = A[:]

for i in range(N):
  if A[i] == a:
    A_[i] = 0
    break
    
a_ = max(A_)    
    
for i in range(N):
  if A[i] != a:
    A_max.append(a)
  else:
    A_max.append(a_)
    
for i in A_max:
  print(i)

Solution (Python):
N = int(input())

A = []

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

max1 = sorted(A)[-1]
max2 = sorted(A)[-2]


for i in A:
    if i == max1:
        print(max2)
    else:
        print(max1)

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
m = max(a)
x = a.index(m)
m2 = max(a[:x]+a[x+1:])
if m-m2:
    for i in range(n):
        if i-x: print(m)
        else: print(m2)
else:
    for i in range(n): print(m)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
aa = sorted(a,reverse=True)
a1 = aa[0]
a2 = aa[1]
for i in a:
    if i == a1:
        print(a2)
    else:
        print(a1)

Solution (Python):
n = int(input())
a = []
for _ in range(0, n):
    a.append(int(input()))
first = max(a)
second_1 = sorted(a)
second = second_1[-2]
for i in range(0, n):
    if a[i] == first:
        print(second)
    else:
        print(first)

Solution (Python):
n = int(input())
l = [int(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)

Solution (Python):
N = int(input())
a_list = [int(input()) for i in range(N)]
_a_list = a_list[::]
_a_list.sort(reverse=True)
first =  _a_list[0]
second = _a_list[1]

for i in range(N):
    if a_list[i] == first:
        print(second)
    else:
        print(first)

Solution (Python):
n = int(input())
lst = []
for i in range(0,n):
  lst.append(int(input()))
  
sort_lst = lst[:]
sort_lst.sort(reverse=True)
m = sort_lst[0]
m_s = max = sort_lst[1]
for i in range(0,len(lst)):
  if not lst[i] == m:
    print(m)
  else:
    print(m_s)

Solution (Python):
N = int(input())
A = []
Copy = []
for i in range(N):
    tmp = int(input())
    A.append(tmp)
    Copy.append(tmp)
Copy.sort()

Max_1 = Copy[-1]
Max_2 = Copy[-2]
for i in range(N):
    if A[i] == Max_1:
        print(Max_2)
    else:
        print(Max_1)

Solution (Python):


N = int(input())

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

max1 = 0
max2 = 0

for j in range(N):
    
    if A[j] > max2:
        if A[j] > max1:
            max2 = max1
            max1 = A[j]
        else:
            max2 = A[j]
            
for j in range(N):
    if A[j] != max1:
        print(max1)
    else:
        print(max2)

Solution (Python):
n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a) 

for a in a:print(b[(a<b[-1])-2])

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
sA = sorted(A)

for a in A:
    if a != sA[-1]:
        print(sA[-1])
    else:
        print(sA[-2])

Solution (Python):



def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    sorted_a = sorted(a)
    a_max = max(a)
    a_second = sorted_a[-2]

    for ai in a:
        if ai == a_max:
            print(a_second)
        else:
            print(a_max)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    sorted_a = sorted(a)
    a_max = max(a)
    a_second = sorted_a[-2]

    for ai in a:
        if ai == a_max:
            print(a_second)
        else:
            print(a_max)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    sorted_a = sorted(a)
    a_max = max(a)

    for ai in a:
        if ai == a_max:
            print(sorted_a[-2])
        else:
            print(sorted_a[-1])


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
list=[]
for i in range(N):
  list.append(int(input()))
M=max(list)
L=[i for i, v in enumerate(list) if v == M]
n=len(L)
if n>1:
  for i in range(N):
    print(M)
else:
  del list[L[0]]
  M2=max(list)
  for i in range(N):
    if i == L[0]:
      print(M2)
    else:
      print(M)

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
L = [None] * N

for i in range(N):
    L[i] = (int(input()), i)
    
L.sort(key = lambda x:-x[0])

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

Solution (Python):
n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a)
for a in a:print(b[(a<b[-1])-2])

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
tmpa = a[:] 
tmpa.sort()

for x in a:
  if x == tmpa[n-1]:
    print(tmpa[n-2])
  else:
    print(tmpa[n-1])
"""
if a[0] > a[1]:
  m,m2 = a[0],a[1]
else:
  m,m2 = a[1],a[0]

for x in a[2:]:
  if x > m2:
    if x>m:
      m2,m = 

"""
"""
for i in range(n):
  if i == 0:
    p
    rint(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)
  """

Solution (Python):
from collections import Counter
from collections import deque
from functools import reduce
from operator import mul
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def COMBINATION(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    o = reduce(mul, range(n, n - r, -1))
    u = reduce(mul, range(1, r + 1))
    return o // u
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n = II()
a = [[i+1, II()] for i in range(n)]
a = sorted(a, key=lambda x: x[1])
maxi = a[-1][1]
for i in range(1, n+1):
    print(maxi if i != a[-1][0] else a[-2][1])

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
L = sorted(A)

for i in range(N):
    if A[i] == L[-1]:
        print(L[-2])
    else:
        print(L[-1])

Solution (Python):
n = int(input())
lister = [int(input()) for i in range(n)]
ordered=sorted(lister,reverse=True)

for element in lister:
  if ordered[0]!=element:
    print(ordered[0])
  else:
    print(ordered[1])

Solution (Python):
import copy
n = int(input())
 
columns = [int(input()) for i in range(n)]

sorted_columns = sorted(columns, reverse = True)

for i in range(n):
    if sorted_columns[0] == columns[i]:
        print(sorted_columns[1])
    else:
        print(sorted_columns[0])

Solution (Python):
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
  
sorted_a = sorted(a, reverse=True)

for v in a:
  if v == sorted_a[0]:
    print(sorted_a[1])
  else:
    print(sorted_a[0])

Solution (Python):
import sys
input = sys.stdin.readline


N = int(input())
lst_A = [int(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)

Solution (Python):
import sys
input = sys.stdin.readline


N = int(input())
lst_A = [int(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)

Solution (Python):
N = int(input())
lst_A = [int(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)

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())

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

b = sorted(a)

m = b[-1]
for i in range(n):
    if m == a[i]:
        print(b[-2])
    else:
        print(m)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]

B = sorted(A, reverse=True)

for n in range(N):
    print(B[0] if B[0] != A[n] else B[1])

Solution (Python):
import heapq


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


hq = []
for val in lst_A:
    val *= -1
    heapq.heappush(hq, val)
m1 = -(heapq.heappop(hq))
m2 = -(heapq.heappop(hq))


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

Solution (Python):
n = int(input())
a = [int(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)

Solution (Python):
import sys
import heapq


input = sys.stdin.readline
N = int(input())
lst_A = [int(input()) for _ in range(N)]


hq = []
for val in lst_A:
    val *= -1
    heapq.heappush(hq, val)
m1 = -(heapq.heappop(hq))
m2 = -(heapq.heappop(hq))


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

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

Solution (Python):
import sys
input = sys.stdin.readline
n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a)
for a in a:print(b[(a<b[-1])-2])

Solution (Python):
n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a)
for a in a:print(b[(a<b[-1])-2])

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class SegmentTree():
    '''
    非再帰
    segment tree
    '''

    def __init__(self, _n, func, init=float('inf')):
        '''
        _n->配列の長さ
        func:func(a,b)->val,　func=minだとRMQになる
        木の高さhとすると,
        n:h-1までのノード数。h段目のノードにアクセスするために使う。
        data:ノード。
        parent:k->child k*2+1とk*2+2
        '''
        self.n = 2**(_n-1).bit_length()
        self.inf = init
        self.data = [init]*(2*self.n)
        self.func = func

    def set(self, k, v):
        '''
        あたいの初期化
        '''
        self.data[k+self.n-1] = v

    def build(self):
        '''
        setの後に一斉更新
        '''
        for k in reversed(range(self.n-1)):
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def update(self, k, a):
        '''
        list[k]=aに更新する。
        更新ぶんをrootまで更新
        '''
        k += self.n-1
        self.data[k] = a

        while k > 0:
            k = (k-1)//2
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def query(self, l, r):
        '''
        [l,r)のfuncを求める
        '''
        L = l+self.n
        R = r+self.n
        ret = self.inf
        while L < R:
            if R & 1:
                R -= 1
                ret = self.func(ret, self.data[R-1])
            if L & 1:
                ret = self.func(ret, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return ret


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

Seg = SegmentTree(N, max, init=0)
for i, a in enumerate(A):
    Seg.set(i, a)

Seg.build()

for i in range(N):
    print(max(Seg.query(0, i), Seg.query(i+1, N)))

Solution (Python):
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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

SortedA = sorted(A)
A_first = SortedA[N-1]
A_second = SortedA[N-2]

for i in range(N):
    if A[i] == A_first:
        print(A_second)
    else:
        print(A_first)

Solution (Python):
N = int(input())
L = []
L2 = []
for _ in range(N):
    x = int(input())
    L.append(x)
    L2.append(x)

L2 = sorted(L2)
m1 = L2[-1]
m2 = L2[-2]
for x in L:
    if x == m1:
        print(m2)
    else:
        print(m1)

Solution (Python):
N = int(input())
A = list(int(input()) for _ in range(N))
asc, des = [0], [0]
for i in range(N-1):
    asc.append(max(asc[-1], A[i]))
    des.append(max(des[-1], A[-1-i]))

for i in range(N):
    print(max(asc[i], des[-1-i]))

Solution (Python):
n = int(input())
l = [int(input()) for i in range(n)]
la = sorted(l, reverse=True)
m1 = la[0]
m2 = la[1]
for i in l:
    if i == m1:
        print(m2)
    else:
        print(m1)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]

A_ = sorted(A, reverse=True)
first, second = A_[0], A_[1]

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

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]

A_ = sorted(A.copy(), reverse=True)
max_num = [A_[0], A_[1]]

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

Solution (Python):
N = int(input())
A = [int(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(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])

Solution (Python):
from sys import stdin
n = int(stdin.readline())
a = [int(stdin.readline()) for _ in range(n)]
b = a.copy()
m1 = max(b)
b.remove(m1)
m2 = max(b)
for i in range(n):
  if a[i] == m1:
    print(m2)
  else:
    print(m1)

Solution (Python):
N = int(input())
A = []

maxN = 0 
secmax = 0

for i in range(N):
  x = int(input())
  A.append(x)
  if maxN <= x:
    secmax = maxN
    maxN = x
  elif secmax <= x:
    secmax = x
  
for a in A:
  print(secmax if maxN == a else maxN)

Solution (Python):
N = int(input())
A = []

maxN = 0 
secmax = 0

for i in range(N):
  x = int(input())
  A.append(x)
  if maxN <= x:
    secmax = maxN
    maxN = x
  elif secmax <= x:
    secmax = x
  
for a in A:
  print(secmax if maxN == a else maxN)

Solution (Python):
import copy

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

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

for i in range(N):
    if A_original[i] == A[-1]:
        print(A[-2])
    else:
        print(A[-1])

Solution (Python):
n = int(input())
no1 = -1
no1_i = -1
no2 = -2
no2_i = -1
S = []
for _ in range(n):
    S.append(int(input()))
 
for i in range(n):
  if S[i] > no1:
    no1_i =i
    no1 = S[i]
  elif S[i] > no2:
    no2_i = i
    no2 = S[i]
      
for i in range(n):
  if no1_i == i:
    print(no2)
  else:
    print(no1)

Solution (Python):
n = int(input())
lis = []
for _ in range(n):
  lis.append(int(input()))
lis_up = [-1]*n
lis_down = [-1]*n

for i in range(n):
  if i == 0:
    lis_up[i] = lis[i]
  else:
    lis_up[i] = max(lis_up[i-1],lis[i])

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

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for _ in range(N)]

first = 0
second = -1

for k in range(N):
    if A[k] > first:
        second = first
        first = A[k]
    elif second < A[k] <= first:
        second = A[k]

for l in range(N):
    if A[l] == first:
        print(second)
    else:
        print(first)

Solution (Python):
n = int(input())
a = []
num = []
prem = 0
m = 0
j = 0
for i in range(n):
    a.append(int(input()))
for i in range(n):
    if a[i] > m:
        prem = m
        m = a[i]
        num = []
        num.append(i)
    elif a[i] == m:
        num.append(i)
    elif a[i] > prem:
        prem = a[i]
for i in range(n):
    if len(num) > 1:
        print(m)
    elif j < len(num) and i == num[j]:
        print(prem)
        j += 1
    else:
        print(m)