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=[]
for i in range(n):
    a.append(int(input()))
b=max(a)
c=a.index(b)
a.pop(c)
d=max(a)
for i in range(n):
    if (i==c):
        print('{0}'.format(d))
    else:    
        print('{0}'.format(b))

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

max_l, max_r = [A[0]], [A[-1]]
for i in range(N-1):
    max_l.append(max(A[i+1],   max_l[i]))
    max_r.append(max(A[N-2-i], max_r[i]))

print(max_r[-2])
for i in range(1,N-1):
    print(max(max_r[-2-i], max_l[i-1]))
print(max_l[N-2])

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
m1 = max(a)
c = a.count(m1)
if len(set(a)) == 1:
	for i in range(n):
		print(m1)
else:
	m2 = sorted(set(a))[-2]
	for i in range(n):
		if a[i] < m1:
			print(m1)
		elif a[i] == m1:
			if c > 1:
				print(m1)
			else:
				print(m2)
		else:
			print(m2)

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

maxA=max(A)
countNumber=A.count(maxA)

for i in range(N):
  if A[i]<maxA:
    print(maxA)
  elif countNumber>1:
    print(maxA)
  else:
    B=A[:]
    del B[i]
    print(max(B))

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

m0 = 1
m1 = 1
max_i = []
for i in range(N):
    a = int(input())
    if a > m0:
        m1 = m0
        m0 = a
        max_i = []
        max_i.append(i)
    elif a == m0:
        m1 = a
    elif a > m1:
        m1 = a
for i in range(N):
    if i in max_i:
        print(m1)
    else:
        print(m0)

Solution (Python):
n = int(input())
array = []

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

m = max(array)
c = array.count(m)
sa = array[:]
sa.remove(m)
m2 = max(sa)

for e in array:

    if e != m:
        print(m)
    else:
        if 1 < c:
            print(m)
        else:
            print(m2)

Solution (Python):
import copy
n = int(input())
string_list = [int(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])

Solution (Python):
n = int(input())
A = []
for i in range(n):
  a = int(input())
  A.append(a)
m = max(A)
c = A.count(m)

if len(set(A)) > 1:
	m2 = sorted(set(A))[-2]

bool = False
if c == 1:
  bool = True

for i in A:
  if bool and i==m:
    print(m2)
  else:
    print(m)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
A_m = str(max(A))
a = A.index(int(A_m))
A = sorted(A)
if A.count(int(A_m)) >= 2:
    print((A_m + '\n')*(N-1) + A_m)
else:
    print((A_m + '\n')*a + str(A[-2]))
    if N-(a+1) == 1:
        print(A_m)
    elif N-(a+1) < 1:
        pass
    else:
        print((A_m + '\n')*(N-(a+2)) + A_m)

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

import numpy as np
an = np.array(an)
_an = an.argsort()[::-1]
_max = np.max(an[_an[0]])
_max_next = np.max(an[_an[1]])
an[an < _max] = _max
an[_an[0]] = _max_next
an = an.astype("str")
print("\n".join(list(an)))

Solution (Python):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
b = list(a)
a.sort(reverse=True)

max_num = max(a)
count = a.count(max_num)

for i in a:
    if i < max_num:
        max_num2 = i
        break

for i in range(n):
    if b[i] == max_num and count == 1:
        print(max_num2)
    else:
        print(max_num)

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

c = sorted(a)
a1 = c[-1] 
a2 = c[-2]

for j in range(N):
    if a[j]==a1:
        print(a2)
    else:
        print(a1)

Solution (Python):
import numpy as np

N = int(input())

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

if(N==1):
    print(a[0])
else:
    a_max = 0
    n_a_max = 0
    all_max = max(a)
    max_arg = np.argmax(a)

    if(max_arg!=0):
        a_max = max(a[:max_arg])
    if(max_arg!=N-1):
        n_a_max = max(a[max_arg+1:])

    if(a_max>=n_a_max):
        next_max = a_max
    else:
        next_max = n_a_max

    for i in range(N):
        if a[i]==all_max:
            print(next_max)
        else:
            print(all_max)

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
m_num = max(a)
m_index = [i for i, x in enumerate(a) if x == m_num]

if len(m_index) > 1:
  for i in range(n):
    print(m_num)
else:
  if len(a) == 1:
    print(a[0])
  else:
    m2_num = sorted(a)[-2]
    for i in range(n):
      if (i in m_index):
        print(m2_num)
      else:
        print(m_num)

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

li = [int(input()) for i in range(n)]
ls = sorted(li, reverse = True)

m1 = ls[0]
m2 = ls[1]
"""
for i in range(0,n):
    if(ls[i] != m1):
        m2 = ls[i]
        break
"""

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

Solution (Python):
import copy
import numpy as np
N = int(input())
sequences = [int(input()) for _ in range(N)]
np_sequences = np.array(sequences)
max_index = np_sequences.argmax()
for i in range(N):
        if i != max_index:
            print(sequences[max_index])
        else:
            tmp = copy.copy(sequences)
            tmp.pop(i)
            tmp_set = set(tmp)
            print(max(tmp_set))

Solution (Python):
import sys
N=input()
A=[ int(sys.stdin.readline().strip())  for _ in range(N) ]

L=[]
for i,a in enumerate(A):
	if i==0:
		L.append(a)
	else:
		L.append( max(L[-1], a) )

R=[]
for i,a in enumerate(A[::-1]):
	if i==0:
		R.append(a)
	else:
		R.append( max(R[-1], a) )

R=R[::-1]


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

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

b=sorted(a,reverse=True)

for a_el in a:
  if b[0] == a_el:
    result=b[1]
  else:
    result=b[0]
  print(result)

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

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

Solution (Python):


import math

if __name__ == '__main__':
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))

    value = sorted(A)
    first = value[N-1]
    second = value[N-2]


    

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

Solution (Python):
import copy
from sys import stdin
n=int(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)

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

li = [int(input()) for i in range(n)]
m = max(li)
m2 = sorted(li)[-2]

for j in range(n):
  if m == li[j]:
    print(m2)
  else:
    print(m)

Solution (Python):
n = int(input())
a = []
first = 0
second = 0
for num in range(n):
	hoge = int(input())
	a.append(hoge)
	if hoge >= first:
		second = first
		first = hoge
	elif second <= hoge and hoge <= first:
		second = hoge


for num in range(n):
	if(first <= a[num]):
		print(second)
	else:
		print(first)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
maxA = max(A)
secA = sorted(A)[-2]
num=A.count(maxA)

 
for i in range(N):
  if num>1:print(maxA)
  elif A[i]==maxA:print(secA)
  else:print(maxA)

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
max_a = max(a)
second_a = sorted(a)[-2]
max_count = a.count(max_a) - 1
if max_count:
    [print(max_a) for _ in range(len(a))]
else:
    [print(max_a) if a[i] != max_a else print(second_a) for i in range(len(a))]

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

a_sorted = sorted(a_li, reverse=True)
max_a = a_sorted[0]
second = a_sorted[1]
for i in range(n):
    if a_li[i] == max_a:
        print(second)
    else :
        print(max_a)

Solution (Python):
n = int(input())
LA = [int(input()) for i in range(n)]
LB = []
LB.extend(LA)
LA.sort()
z = LA[-1]
y = LA[-2]
for i in range(n):
    if LB[i] == z:
        print(y)
    else:
        print(z)

Solution (Python):
N = int(input())
A = [0] * N
for n in range(N):
    A[n] = int(input())

maximum = max(A)
second_maximum = sorted(A, reverse=True)[1]
for n in range(N):
    if A[n] == maximum:
        print(second_maximum)
    else:
        print(maximum)

Solution (Python):
import copy
n = int(input())
all_list = [int(input()) for _ in range(n)]
max_value = max(all_list)
max_value_count = all_list.count(max_value)
for i in range(n):
    if all_list[i] == max_value:
        if max_value_count > 2:
            print(max_value)
        else:
            tmp = copy.copy(all_list)
            tmp.pop(i)
            print(max(tmp))
    else:
        print(max_value)

Solution (Python):
N=int(input())
L=[int(input()) for i in range(N)]
tl=sorted(L)
index1=L.index(tl[-1])
index2=L.index(tl[-2])
for i in range(N):
	if i==index1:
		print(L[index2])
	else:
		print(L[index1])

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

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

Solution (Python):
n = int(input())
aMax=0
multi=0
a = [0 for i in range(n)]
for i in range(n):
  a[i] = int(input())
  if aMax == a[i]:
    multi = 1
  elif aMax < a[i]:
    aMax = a[i]
    multi = 0

if multi == 1:
  for i in range(n):
    print(aMax)
else:
  for i in range(n):
    if aMax != a[i]:
      print(aMax)
    else:
      if i == 0:
        print(max(a[1:]))
      elif i == n - 1:
        print(max(a[0:i]))  
      else:
        aMax2=max(max(a[:i]),max(a[i+1:]))
        print(aMax2)

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
max = 0
max2 = 0
tmp = 0
for i in range(n):
    if max<a[i]:
        max = a[i]
        tmp=i
for i in range(n):
    if tmp!=i and max2<a[i]:
        max2 = a[i]

for i in range(n):
    if i != tmp:
        print(max)
    else:
        print(max2)

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

m = max(a)
l = []
for i, k in enumerate(a):
    if k == m:
        l.append(i)

if len(l) == 1:
    for i in range(n):
        if i != l[0]:
            print(m)
        else:
            a[l[0]] = 0
            print(max(a))
else:
    for i in range(n):
        print(m)

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

first_max = max(a)

former_arr = [0] + a[0:a.index(first_max)]
latter_arr = [0] + a[a.index(first_max) + 1:]
second_max = (max(max(former_arr), max(latter_arr)))

ans = ""
ans += (str(first_max) + '\n') * (a.index(first_max))
ans += (str(second_max) + '\n')
ans += (str(first_max) + '\n') * (N - a.index(first_max) - 1)
print(ans.rstrip('\n'))

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
a1=max(A)
a2=0
j=0
for i in range(N):
    if A[i]==a1:
        j=j+1
    else:
        j=j
if j!=1:
    for i in range(N):
        print(a1)
else:
    for i in range(N):
        if A[i]>a2 and A[i]!=a1:
            a2=A[i]
    for i in range(N):
        if A[i]==a1:
            print(a2)
        else:
            print(a1)

Solution (Python):
N=int(input())
A=[int(input()) for i in range(N)]
A_sub = A.copy()
MAX = max(A)
A_sub.remove(MAX)
MAX2 = max(A_sub)

for i in range(N):
    if A[i] < MAX:
        print(MAX)
    elif A[i] == MAX:
        print(MAX2)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
n = A.index(max(A))
m = max(A)
A.remove(max(A))

for i in range(n):    
    print(m)
print(max(A))
for i in range(N-n-1):
    print(m)

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

def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

N = SORO_INT()
A = list([int(input()) for i in range(N)])
t = sorted(A)[-2]

B = max(A)
B_in = A.index(B)


for i in range(N):
    A[i] = B
A[B_in] = t
for i in range(N):
    print(A[i])

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

B.sort()

max_a = B[N-1]
max_dup = False
if B[N-2] == max_a:
    max_dup = True
second_max_a = -1
for i in range(N-1,-1,-1):
    if B[i] < max_a:
        second_max_a = B[i]
        break

for a in A:
    if a < max_a:
        print(max_a)
    elif max_dup:
        print(max_a)
    else:
        print(second_max_a)

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
d = []
h = []
for i in range(n):
    k = readi()
    d.append(k)
    heapq.heappush(h,-k)
t1 = -heapq.heappop(h)
t2 = -1
if h:
    t2 = -heapq.heappop(h)
if n == 1:
    print(d[0])
else:
    for i in range(n):
        if d[i] == t1:
            print(t2)
        else:
            print(t1)

Solution (Python):
def main():
    n = int(input())
    a_list = []
    for i in range(n):
        a = int(input())
        
        a_list.append([i,a])

    ans = sorted(a_list, key=lambda x:x[1])
    

    
    for i in range(n):
        
        if a_list[i][1] == ans[-1][1]:
            
            print(ans[-2][1])
        else:
            print(ans[-1][1])

main()

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

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

max_value = max(a_list)

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

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

a_max = max(a)
idx = [i for i, x in enumerate(a) if x==a_max]

if len(idx) > 1:
    for i in range(n):
        print(a_max)
else:
    for i in range(n):
        if a[i] == a_max:
            print(max(a[0:i]+a[i+1:]))
        else:
            print(a_max)

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

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

Solution (Python):
from bisect import bisect
n = int(input())

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

max_val = max( vals )
vals_not_max = [a for a in vals if a != max_val]
if len(vals_not_max) < n -1:
	max_val_exclude  = max_val
else:
	max_val_exclude = max(vals_not_max)
	
for a in vals:
	if a == max_val:
		print(max_val_exclude)
	else:
		print(max_val)

Solution (Python):
import numpy as np

n = int(input())

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

a = np.array(a)

max_a = a.max()
ans = np.array([max_a for i in range(n)])

max_ind = np.where(a == max_a)[0]

if len(max_ind) == 1:
    b = np.sort(a)
    ans[max_ind] = b[-2]

for i in ans:
    print(i)

Solution (Python):
def main():
	import sys
	import numpy as np
	input = sys.stdin.readline
	N = int(input())
	A = [int(input()) for _ in range(N)]
	A = np.array(A)
	maxNum = np.max(A)
	maxIndex = np.where(A == A.max())[0]
	if len(maxIndex) > 1:
		for _ in range(N):
			print(maxNum)
	elif maxIndex[0] == 0:
		print(np.max(A[1:]))
		for i in range(1, N):
			print(maxNum)
	elif maxIndex[0] == N-1:
		for i in range(N-1):
			print(maxNum)
		print(np.max(A[:N-1]))
	else:
		for i in range(maxIndex[0]):
			print(maxNum)
		prev = max(np.max(A[:maxIndex[0]]), np.max(A[maxIndex[0]+1:]))
		print(prev)
		for i in range(maxIndex[0]+1, N):
			print(maxNum)



if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A=[]
for i in range(N):
    A.append(int(input()))
max_A=max(A)
ind_max = A.index(max_A)
A2=A
del A2[ind_max]
max2_A=max(A2)
for i in range(N):
    if i==ind_max:
        print(max2_A)
    else:
        print(max_A)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n = i()
a = hi(n)
maxa = max(a)
b = sorted(a, reverse=True)
snda = b[1]
if maxa == snda:
    for i in range(n):
        print(maxa)
else:
    for i in range(n):
        if maxa == a[i]:
            print(snda)
        else:
            print(maxa)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(list(set(A)))
max_v = B[-1]
max_c = A.count(max_v)
for i in range(N):
    tmp = A[i]
    if tmp != max_v:
        print(max_v)
    else:
        if max_c > 1:
            print(max_v)
        else:
            print(B[-2])

Solution (Python):
N=int(input())
L=[int(input()) for i in range(N)]
NL=sorted(L)
for i in range(N):
  if L[i]==NL[N-1]:
    print(NL[N-2])
  else:
    print(NL[N-1])

Solution (Python):


import sys
from collections import deque

def input():
    return sys.stdin.readline().rstrip()

N = int(input())
que = deque([int(input()) for i in range(N)])
tmp = 0
max_num1 = sorted(que)[-1]
max_num2 = sorted(que)[-2]

for i in range(N):
    tmp = que.popleft()
    if tmp != max_num1:
        print(max_num1)
    else:
        print(max_num2)
    que.append(tmp)

Solution (Python):
N = int(input())
A = MAX = [0]*N
max_1 = max_2 = index = 0
for i in range(N):
  A[i] = int(input())
  if A[i] >= max_1:
    max_2 = max_1
    max_1 = A[i]
  elif A[i] > max_2:
    max_2 = A[i]
for i in range(N):
  if A[i] == max_1:
    print(max_2)
  else:
    print(max_1)

Solution (Python):
a = []
c = []
n = int(input())
max_i = 0
max_s = 0
b = False
for i in range(n):
    aa = int(input())
    a.append(aa) 
    c.append(aa)   
    if max_i < aa : max_i = aa

c.remove(max_i)
max_s = max(c)

for i in range(n):
    if a[i] != max_i : print(max_i)
    else:print(max_s)

Solution (Python):

import copy


N = int(input())
A = list()
for _ in range(N):
    A.append(int(input()))


ans = copy.copy(A)
ans.sort()
m = ans[-1]
for i in range(N):
    if A[i] != m:
        print(m)
    else:
        print(ans[N - 2])

Solution (Python):
import copy

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

result = max(A)
ind = A.index(result)

for i in range(N):
    if i == ind:
        a = copy.deepcopy(A)
        a.remove(result)
        print(max(a))
    else:
        print(result)

Solution (Python):
N = int(input())
C = list(map(int,[input() for _ in range(N)]))

first = -1
second = -2
for i in range(N):
    if first <= C[i]:
        second = first
        first = C[i]
    elif second < C[i]:
        second = C[i]
    
for j in range(N):
    if C[j] == first:
        print(second)
    else:
        print(first)

Solution (Python):
import copy
n = int(input())
a = [int(input()) for i in range(n)]
sorted_a = sorted(a, reverse=True)
n1 = sorted_a[0]
n2 = sorted_a[1]
if(n1 == n2):
  for i in range(n):
    print(n1)
else:
  for i in range(n):
    if a[i] == n1:
      print(n2)
    else:
      print(n1)

Solution (Python):
import numpy as np

N = int(input())
A = [int(input()) for i in range(N)]
A = np.array(A)
first = max(A)
arg = A.argsort()
first_idx = arg[-1]
second_idx = arg[-2]
second = A[second_idx]
for i in range(len(A)):
  if i==first_idx:
    print(second)
  else:
    print(first)

Solution (Python):
n = input()
a = []
n = int(n)

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

if n == 1:
    print(a[0])
else:
    s = sorted(a, reverse=True)[0]
    t = sorted(a, reverse=True)[1]

    for i in a:
        if i == s:
            print(t)
        else:
            print(s)

Solution (Python):
n = int(input()) 
t = [int(input()) for i in range(n)]
m2 = sorted(t)[-2]
m = max(t)
for i in range(n):
	if t[i] != m:
		print(m)
	else:
		print(m2)

Solution (Python):
a = int(input())
b = [int(input()) for _ in range(a)]
c = [0] * a
c[0] = b[0]
c[1] = max(b[1], c[0])
d = [0] * a
d[0] = b[-1]
d[1] = max(b[-2], d[0])
for i in range(2, len(b)):
    c[i] = max(c[i-1], b[i])
    d[i] = max(d[i-1], b[-i-1])
c.insert(0, 0)
d.insert(0, 0)
for i in range(len(c)-1):
    print(max(c[i], d[-i-2]))

Solution (Python):
n=int(input())
a=list(int(input()) for i in range(n))
b=[0]
c=[0]
for i in range(n):
    b.append(max(b[i],a[i]))
    c.append(max(c[i],a[-i-1]))
del b[n]
del c[n]
 
for i in range(n):
    d=b[i]
    e=c[n-1-i]
    print(max(d,e))

Solution (Python):
N=int(input())
A = [int(input()) for i in range(N)]
maxval = max(A)
argmaxval = A.index(maxval)
for i,a in enumerate(A):
  if i==argmaxval:
    B = A[:]
    B[i]=0
    print(max(B))
  else:
    print(maxval)

Solution (Python):

import copy


N = int(input())
A = list()
for _ in range(N):
    A.append(int(input()))


ans = copy.copy(A)
ans.sort()
m = ans[-1]
for i in range(N):
    if A[i] != m:
        print(m)
    else:
        print(ans[N - 2])

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    a_list = [int(input()) for _ in range(n)]
    maximum = max(a_list)
    count = a_list.count(maximum)
    if count == 1:
        second = max(set(a_list) - set([maximum]))
    for a in a_list:
        if count > 1:
            print(maximum)
            continue
        if maximum == a:
            print(second)
        else:
            print(maximum)


if __name__ == "__main__":
    main()

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

b = sorted(a)
maxnum = b[-1]
nextmaxnum = b[-2]

if maxnum == nextmaxnum:
  for i in range(n):
    print(maxnum)
else:
  for i in range(n):
    if a[i] == maxnum:
      print(nextmaxnum)
    else:
      print(maxnum)

Solution (Python):
n = int(input())
max1 = 0
max2 = 0
index = 0
for i in range(n):
    a = int(input())
    new_max = max(a, max1)
    if (a == new_max and max2 <= max1) or (a == new_max and max2 <= max1 and a == max1):
        max2 = max1
        index = i
    elif (a != new_max and max2 <= a) or (a != new_max and max2 <= a and a == max1):
        max2 = a
    max1 = new_max

for i in range(n):
    if i != index:
        print(max1)
    else:
        print(max2)

Solution (Python):
import numpy as np
n= int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
    
b = np.array(a)
b = np.sort(b)[::-1]

ans = [0]*n

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

Solution (Python):


n = int(input())

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

B = sorted(A)



m = B[len(B)-1]
m_ind = A.index(m)

m2 = B[len(B)-2]
for i in range(n):
    if m != m2:
        if i == m_ind:
            print(m2)
        else:
            print(m)
    else:
        print(m)

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

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

nums_sorted = sorted(nums,reverse=True)
max1 = nums_sorted[0]
max2 = nums_sorted[1]

for num in nums:
    if(num!=max1):
        print(max1)
    else:
        print(max2)

Solution (Python):
N, *d = map(int, open(0).read().split())
allmax = max(d)
allMaxCount = d.count(allmax)
for i in range(N):
    max = 0
    if(allMaxCount > 1 or d[i] != allmax):
        max = allmax
    else:
        for j in range(N):
            if(i == j):
                continue
            if d[j] > max:
                max = d[j]
                if max == allmax:
                    break
    print(max)

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

for i in range(n):
    if l[i] == m1:
        print(m2)
    else:
        print(m1)

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

sort = temp[:]

sort.sort()

maximum = sort[-1]


for i in temp:
	if i != maximum:
		print(maximum)

	else:
		print(sort[-2])

Solution (Python):
import heapq
n = int(input())
a_list = [int(input()) for _ in range(n)]
a_list_heap = list(map(lambda x:(-1)*x,a_list))
heapq.heapify(a_list_heap)
max_num = a_list_heap[0]*(-1)

for i in range(len(a_list)):
    if a_list[i] != max_num:
        print(max_num)
    else:
        tmp = heapq.heappop(a_list_heap)
        print(a_list_heap[0]*(-1))
        heapq.heappush(a_list_heap,tmp)

Solution (Python):


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

array_sorted = sorted(array, reverse=True)
max_index = array.index(array_sorted[0])
max_value = array_sorted[0]
second_value = array_sorted[1]

for i in range(N):
  if array[i] == max_value:
    print(second_value)
  else:
    print(max_value)

Solution (Python):
n=int(input())
x=list(int(input()) for _ in range(n))

import numpy as np

mi=np.argmax(x)

y=np.array(x)

for i in range(n):
	if i!=mi:
		print(x[mi])
	else:
		z=np.ones(n)
		z[i]=0
		print(int(max(y*z)))

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

A_max = max(A_copy)
A_copy.remove(A_max)
A_next = max(A_copy)
for i in A:
    if i == A_max:
        print(A_next)
    else:
        print(A_max)

Solution (Python):
n = int(input())
s = {}
for i in range(n):
    s[i] = int(input())

max_v = max(s.values())
max_k = max(s,key=s.get)
s.pop(max_k)
max_v2 = max(s.values())
max_k2 = max(s,key=s.get)

for i in range(n):
    if(i==max_k):
        print(max_v2)
    else:
        print(max_v)

"""
for i in range(n):
    temp = s[i]
    s.pop(i)
    max_v = max(s.values())
    print(max_v)
    s[i]=temp
"""

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

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

m_l = [0]
m_r = [0]

for i in range(n):
  m_l.append(max(m_l[i], l[i]))
  m_r.append(max(m_r[i], l[-(i+1)]))
m_r = m_r[::-1]



for i in range(n):
  print(max(m_l[i], m_r[i+1]))

Solution (Python):
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    
A_MAX = max(A)
B = len([k for k in A if k == A_MAX])


if len(A) != B:
    C = -B-1
    D = sorted(A)
    A_MAX2 = D[C]

for j in A:
    if j == A_MAX:
        if B > 1:
            print(A_MAX)
        else:
            print(A_MAX2)
    else:
        print(A_MAX)

Solution (Python):
import numpy as np
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
max_1_idx = np.argmax(a)
max_1_val = a[max_1_idx]
a[max_1_idx] = -1
max_2_val = np.max(a)
for i in range(n):
    if i == max_1_idx:
        print(max_2_val)
    else:
        print(max_1_val)

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

numset = set(arr)
maxval = max(numset)
count = 0

if len(numset) == 1:
    for i in range(n):
        print(maxval)
else:
    numset.remove(maxval)
    semimax = max(numset)
    for j in range(n):
        if arr[j] == maxval:
            count +=1
    for i in range(n):
        if arr[i] == maxval and count == 1:
            print(semimax)
        else:
            print(maxval)

Solution (Python):
import numpy as np
N = int(input())
nums = [int(input()) for _ in range(N)]
nums = np.array(nums)
max_num = max(nums)
max_index = np.where(nums == nums.max())[0]

if len(max_index) == 1:
  for i in range(len(nums)):
    if i == max_index[0]:
      print(sorted(nums)[-2])
    else:
      print(max_num)
else:
  for i in range(len(nums)):
    print(max_num)

Solution (Python):
n = int(input())
a = []

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

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

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

index = A.index(max(A))
A.sort()
max_ = A[-1]
second_max = A[-2]

if max_ == second_max:
    for _ in range(N):
        print(max_)
else:
    for i in range(N):
        if i == index:
            print(second_max)
        else:
            print(max_)

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

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

max_list = sorted(A, reverse=True)
max_index = A.index(max(A))

for i in range(0, len(A)):
    if i == max_index:
        print(max_list[1])
    else:
        print(max_list[0])

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

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

max_num = max(b)
c = b - {max_num}
if len(c) == 0 or a.count(max_num) >= 2:
    second_max_num = max_num
else:
    second_max_num = max(c)

for elem in a:
    if not elem == max_num:
        print(max_num)
    else:
        print(second_max_num)

Solution (Python):
import numpy as np

now_max = -1
prev_max = 100000000
left_max = -1
right_max = -1
right_max_index = 0

N = int(input())
A_list = [int(input()) for _ in range(N)]
np_A_list = np.array(A_list)
for i, A in enumerate(A_list):
    
    if i == len(A_list) - 1:
        print(left_max)
        break
    if right_max_index == i:
        slc = np_A_list[i + 1:]
        right_max = slc.max()
        right_max_index = len(np_A_list) - 1 - slc[::-1].argmax()

    if left_max > right_max:
        now_max = left_max
        print(left_max)
    else:
        now_max = right_max
        print(right_max)
    
    if prev_max < now_max:
        left_max = right_max = now_max
        right_max_index = 10000000
    
    prev_max = now_max
    if left_max < A:
        left_max = A

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

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

A.sort(key=lambda x :x[1],reverse=True)

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

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