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 = input()
a = []
for i in range(N):
        a.append(input())
b = sorted(a)
b0,b1 = b[-1],b[-2]
for i in range(N):
        if a[i]!=b0 :
                print(b0)
        else:
                print(b1)

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

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

sort_num_list = sorted(num_list)
max_n = sort_num_list[-1]
smax_n = sort_num_list[-2]

for i in num_list:
  if i==max_n:
    print(smax_n)
  else:
    print(max_n)

Solution (Python):
a = int(input())
b = [int(input()) for _ in range(a)]
c = b.copy()
c = sorted(c, reverse=True)
for i in b:
    if i == c[0]:
        print(c[1])
    else:
        print(c[0])

Solution (Python):
import numpy as np
N = int(input())
A = np.array([int(input()) for i in range(N)])

max_index=np.argmax(A)
a_max=int(A[max_index])
a_second=int(np.amax(np.delete(A,max_index)))
A[:]=a_max
A[max_index]=a_second
for a in A:
    print(int(a))

Solution (Python):
n = int(input())
numList  = [int(input()) for _ in range(n)]
maxVal = max(numList)
workList = numList[:]
workList.remove(maxVal)
secondVal = max(workList)
for num in numList:
  if num != maxVal:
    print(maxVal)
  else:
    print(secondVal)

Solution (Python):
A = [int(input()) for i in range(int(input()))]
first = max(A)
second = sorted(A)[-2]
for i in A:
    if i == first:
        print(second)
    else:
        print(first)

Solution (Python):
n = int(input())
numList  = [int(input()) for i in range(n)]
maxVal = max(numList)
workList = numList[:]
workList.remove(maxVal)
secondVal = max(workList)
for num in numList:
  if num != maxVal:
    print(maxVal)
  else:
    print(secondVal)

Solution (Python):
n = int(input())
a = [int(input()) for x 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):
N = int(input())
A = [int(input()) for i in range(N)]

x = sorted(A)

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

Solution (Python):
N = int(input())
As = [int(input()) for _ in range(N)]
Bs = sorted(As,reverse=True)
for x in As:
  if x == Bs[0] and x != Bs[1]:
    print(Bs[1])
  else:
    print(Bs[0])

Solution (Python):
import copy
list = []
n = int(input())
for i in range(n):
    list.append(int(input()))
list2 = copy.deepcopy(list)
maxsize = max(list)
list2.sort(reverse=True)
max_second = list2[1]
maxsecond = list2[1]
for j in range(n):
    a = list[j]
    if a == maxsize:
        print(maxsecond)
    else:
        print(maxsize)

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

max_ = max(list)
for i in range(n):
    a = list[i]
    if a == max_:
        del list[i]
        ans = max(list)
        print(ans)
        list.insert(i,a)
        for j in range(n-i-1):
            print(max_)
        break
    else:
        print(max_)

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

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

A_i_sord = sorted(A_i)
A_i_max_first = A_i_sord[N - 1]
A_i_max_second = A_i_sord[N - 2]

for i in range(N):
    if A_i_max_first == A_i[i]:
        print(A_i_max_second)
    else:
        print(A_i_max_first)

Solution (Python):

n = int(input())
a = [int(input()) for _ in range(n)]
a_unique = list(sorted(set(a), reverse=True))
max_value = a_unique[0]
max_value_count = a.count(max_value)

if max_value_count == 1:
    for i in range(n):
        if a[i] == max_value:
            print(a_unique[1])
        else:
            print(max_value)
else:
    for i in range(n):
        print(max_value)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
m = max(A)
ans = list(map(str, [m for _ in range(N)]))
if A.count(m) > 1:
    print('\n'.join(ans))
    exit()
AA = A[:]
AA.remove(m)
mm = max(AA)
for n in range(N):
    if A[n] == m:
        ans[n] = str(mm)
        break
print('\n'.join(ans))

Solution (Python):


import os
import sys

N = int(input())

A = []

for i in range(N):
	A.append(int(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)

Solution (Python):

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
































S = sorted(A)
MAXS = max(A)

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

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

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

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

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

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

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

Solution (Python):

n = int(input())
a = []

for i in range(n):
    a.append(int(input()))
    
a_copy = list(a)
a.sort(reverse=True)

max_1 = a[0]
max_count = a.count(max_1)

for i in a:
    if i < max_1:
        max_2 = i
        break
        
for a in a_copy:
    if a == max_1 and max_count == 1:
        print(max_2)
    else:
        print(max_1)

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

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


A2 = sorted(A)

max1 = A2[len(A2)-1]
max2 = A2[len(A2)-2]

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

Solution (Python):
N=int(input())
A=[0 for i in range(N)]
for i in range(N):
  A[i]=int(input())
max1=max(A)
numbers_of_max1=0
for i in range(N):
  if A[i]==max1:
    numbers_of_max1+=1
    
if numbers_of_max1>1:
  for i in range(N):
    print(max1)
else:
  L=A.copy()
  L.pop(L.index(max1))
  max2 = max(L)
  for i in range(N):
    if A[i]==max1:
      print(max2)
    else:
      print(max1)

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

normal = max(A)
hoge=sorted(A)
exception = hoge[-2]

for i in range(N):
    if A[i] == normal:
        print(exception)
    else:
        print(normal)

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

Solution (Python):














n = int(input())
a = list()
for i in range(n):
    a.append(int(input()))
c = a.index(max(a))
m = max(a)
a.sort()
d = a[-2]
for i in range(n):
    if i == c:
        print(d)
    else:
        print(m)

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

maxNum = 0
maxcount = 0
tugi = 0
ls = [0]*n
for i in range(n):
    o = int(input())
    maxNum = max(maxNum,o)
    ls[i] = o
for i in range(n):
    if ls[i] == maxNum:
        maxcount+=1
    else:
        tugi = max(tugi,ls[i])
if maxcount > 1:
    for i in range(n):
        print(maxNum)
else:
    for i in range(n):
        if ls[i] == maxNum:
            print(tugi)
        else:
            print(maxNum)

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

B = A.copy()

B.sort()


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

Solution (Python):

n=int(input())
a=[int(input()) for i in range(n)]
a_=sorted(a)
m=a_[-1]
for i in range(n):
  if a[i]!=m:
    print(m)
  else:
    print(a_[-2])

Solution (Python):
import copy
def resolve():
    N = int(input())
    A = [int(input()) for i in range(N)]
    B = copy.copy(A)
    B.sort()
    A_max = B[-1]
    A_sec = B[-2]
    for i in range(N):
        if (A[i] == A_max):
            print(A_sec)
        else:
            print(A_max)
resolve()

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

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

A_i_sord = sorted(A_i)
A_i_max_first = A_i_sord[N - 1]
A_i_max_second = A_i_sord[N - 2]

for i in range(N):
    if A_i_max_first == A_i[i]:
        print(A_i_max_second)
    else:
        print(A_i_max_first)

Solution (Python):
N = int(input())
data = []
max1 = 0
max2 = 0
for i in range(N):
    x = int(input())
    if x > max1:
        max1 = x
        max_i = i
    elif x > max2:
        max2 = x
for i in range(N):
    if max_i == i:
        print(max2)
    else:
        print(max1)

Solution (Python):
import numpy as np
n=int(input())
a=[int(input()) for i in range(n)]
a_=sorted(a)
m=max(a)
for i in range(n):
  if a[i]!=m:
    print(m)
  else:
    print(a_[-2])

Solution (Python):


import copy

a = int(input())
nums = [0]*a

for i in range(a):
    nums[i] = int(input())
    
maxnum = max(nums)
maxenum = [i for i, x in enumerate(nums) if x == maxnum]
maxquant = len(maxenum)


if maxquant != 1:
    for j in range(a):
        print(maxnum)
else:
    for j in range(a):
        if nums[j] != maxnum:
            print(maxnum)
        else:
            copylist = copy.deepcopy(nums)
            copylist[maxenum[0]] = 0
            print(max(copylist))

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

mymax1 = -99
mymax2 = -9
mycnt = -1


for i in range(N):
  mynum = int(input())
  if mynum > mymax1:
    mymax1 = mynum
    mycnt = i
  else:
    if mynum > mymax2:
      mymax2 = mynum
for i in range(N):
  if i == mycnt:
    print(mymax2)
  else:
    print(mymax1)

Solution (Python):

import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    Am = max(A)
    if A.count(Am)>1:
        for j in range(N):
            print(Am)
        return
    Ap = copy.copy(A)
    set(Ap)
    Ap.sort(reverse=True)
    for i in range(N):
        if  A[i] != Am:
            print(Am)
        else:
            print(Ap[1])
if __name__ == '__main__':
    main()

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





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

Solution (Python):

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
B = A[:]
B.sort()
one = B[-1]
two = B[-2]
for i in range(N):
    if A[i] == one:
        print(two)
    else:
        print(one)

Solution (Python):
def main():
    n = input()
    aa = []
    for _ in xrange(n):
        aa.append(input())
    bb = sorted(aa)
    b0, b1 = bb[-1], bb[-2]
    for a in aa:
        if a < b0:
            print b0
        else:
            print b1
 
 
if __name__ == '__main__':
    main()

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

for i in range(0,N):
    if ans_tmp < A[i]:
        ans_tmp = A[i]

for i in range(0,N):
    if ans_tmp == A[i]:
        count += 1
    if ans_tmp2 < A[i] and ans_tmp > A[i]:
        ans_tmp2 = A[i]

if count > 1:
    for j in range(0,N):
        ans[j] = ans_tmp

else:
    for j in range(0,N):
        if A[j] != ans_tmp:
            ans[j] = ans_tmp
        else:
            ans[j] = ans_tmp2

for i in range(0,N):
    print(ans[i])

Solution (Python):

from itertools import accumulate,chain

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

r = list(accumulate(chain((0,),A), max))
l = list(accumulate(chain((0,),reversed(A)), max))

for i in range(N):
    print(max(r[i],l[-i-2]))

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
A=[I() for i in range(n)]
m=max(A)
B=sorted(A)
for i in range(n):
    if A[i]==m:
        print(B[-2])
    else:
        print(B[-1])

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 = [int(input()) for _ in range(N)]
max_A = max(A)


max_index = [i for i, v in enumerate(A) if v == max_A]


one_max = (len(max_index) == 1)
answer = [max_A] * N

if one_max:
    Second = A.copy()
    Second.remove(max_A)
    Second_A = max(Second)
    for i in max_index:
        answer[i] = Second_A
for i in range(N):
    print(answer[i])

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

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


temp_list = sorted(a)
m = temp_list[::-1][0]



if temp_list[::-1][1] == m:
    m_dash = m
else:
    m_dash =temp_list[::-1][1]

for a_i in a:
  if a_i == m:
    print(m_dash)
  else:
    print(m)

Solution (Python):
import math

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

B = sorted(A)

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

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

left_max=0
right_max=max(Arr)

for i in range(N):
    n = Arr[i]
    if left_max>=right_max:
        print(left_max)
    else:
        if n==right_max:
            if i ==N-1:
                right_max=left_max
                
            else:
                right_max = max(Arr[i+1:])

        print(right_max)

    if i == N-1:
        break
    left_max=max(n,left_max)

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

max_list = sorted(a,reverse=True)[:2]
num = max_list[0]
num2 = max_list[1]

for i in range(n):
    if a[i] < num:
        print(num)
    else:
        print(num2)

Solution (Python):
N = int(input())
mylist = []
first=0
second=0
for i in range (N):
  A = int(input())
  if first < A:
    first = A
  elif second < A:
    second = A
  mylist.append(A)
for i in range (N):
  if mylist[i] == first:
    print(second)
  else :
    print(first)

Solution (Python):
n = int(input())
a_list = [int(input()) for _ in range(n)]
m1 = max(a_list)
k = a_list.index(m1)
m2 = max(a_list[:k]+a_list[k+1:])
for i in range(n):
  if i == k:
    print(m2)
  else:
    print(m1)

Solution (Python):
def returnsecond(numbers, N):
    first = 0
    firc = 0;
    second = 0
    for j in range(N):
        if first < numbers[j]:
            first = numbers[j]
            firc = j
    for j in range(N):
        if(j != firc and second <= numbers[j]):
            second = numbers[j]

    return first, second;


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

for i in range(N):
    numbers.append(int(input()))
first, second = returnsecond(numbers, N)

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

Solution (Python):
import numpy as np
N=int(input())
A=[int(input()) for i in range(N)]
Amax=max(A)

Ai=np.argmax(A)
if Ai==0:
  A2max=max(A[1:])
elif Ai==N-1:
  A2max=max(A[:-1])
else:
  A2max=max(max(A[:Ai]),max(A[Ai+1:]))
for i in range(N):
  if i==Ai:
    print(A2max)
  else:
    print(Amax)

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

Solution (Python):
N = int(input()) 
s = [int(input()) for i in range(N)] 
num = len(s)
s1 = sorted(s,reverse=True)[:2]
for i in range(num):
    if s1[0] == s[i]:
        print(s1[1])
    else:
        print(s1[0])

Solution (Python):
import numpy as np
N = int(input())
num_list = [int(input()) for i in range(N)]
a = max(num_list)
if num_list.count(a) > 1:
  for j in range(N):
    print(a)
else:
  b = np.sort(num_list)
  c = b[-2]
  for k in range(int(num_list.index(a))):
    print(a)
  print(c)
  for l in range(N-int(num_list.index(a))-1):
    print(a)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
ans = 0
Max1 = max(A)
indexes = [i for i, x in enumerate(A) if x == Max1]
if len(A) == len(indexes):
    for i in A:
        print(i)
else:
    Max2 = sorted(set(A))[-2]
    if len(indexes) >= 2:
        for i in range(N):
            print(Max1)
    else:
        for i in range(N):
            ans = Max2 if A[i] == Max1 else Max1
            print(ans)

Solution (Python):
N, *d = 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])

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

b[0] = a[0]
c[n-1] = a[n-1]
for i in range(1,n):
    b[i] = max(b[i-1],a[i-1])
    
for i in range(n-2,-1,-1):
    c[i] = max(c[i+1],a[i+1])
    
for i in range(n):
    if i == 0:
        print(c[i])
    elif i == n-1:
        print(b[i])
    else:
        print(max(c[i],b[i]))

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

list=a[:]
list.sort(reverse=True)
max1 = list[0]
max2 = list[1]

for i in range(n):
    if a[i]==max1:
        print(max2)
    else:
        print(max1)

Solution (Python):
import copy
n=int(input())
l=[int(input()) for i in range(n)]
a=max(l)
ind=l.index(a)
del l[ind]
b=max(l)
for i in list(range(ind)):
  print(a)
print(b)
for s in list(range(n-ind-1)):
  print(a)

Solution (Python):
N = int(input())
a =int(input())
b=int(input())
if a>b:
    max1 = a
    max2 = b
else:
    max1 = b
    max2 = a

list = []
list.append(a)
list.append(b)

for _ in range(N-2):
    i = int(input())
    list.append(i)
    if i > max1:
        max2 = max1
        max1 = i
    elif i > max2:
        max2 = i
if max1==max2:
    for i in range(N):
        print(max1)

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

Solution (Python):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
bl = [0 for i in range(n)]
bl[0] = a[0]
br = [0 for i in range(n)]
br[0] = a[n - 1]
for i in range(1, n):
    bl[i] = max(bl[i - 1],a[i])
a.reverse()
for i in range(1, n):
    br[i] = max(br[i - 1],a[i])
br.reverse()
print(br[1])
for i in range(1, n - 1):
    print(max(bl[i - 1],br[i + 1]))
print(bl[n - 2])

Solution (Python):
from sys import stdin

readline = stdin.readline


def nf():
    """
    入力全て(EOFまで)を`int iter`に変換
    """
    return map(int, open(0).read().split())


def main():
    n, *al = nf()
    s, f = sorted(al)[-2:]
    if s == f:
        for _ in range(n):
            print(f)
        return
    for a in al:
        if a == f:
            print(s)
            continue
        print(f)


if __name__ == "__main__":
    main()

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

v = nums 
v_sort = sorted(v, reverse=True)
v_max=v_sort[0]
v_max2=v_sort[1]

for i in range(N):
    if(v[i]!=v_max):
        print(v_max)
    else:
        print(v_max2)

Solution (Python):
import heapq

n = int(input())
a = [int(input()) for _ in range(n)]
a1, a2 = heapq.nlargest(2, a)
[print(a1) if _ != a1 else print(a2) for _ in a]

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
amax = max(a)
b = a.copy()
b.remove(amax)
bmax = max(b)
for i in a :
    if i == amax :
        print(bmax)
    else :
        print(amax)

Solution (Python):
n=int(input())
a=[int(input()) for i in range(n)]
t=list(enumerate(a))
t.sort(key=lambda x:x[1])
mx=t[-1][1]
ans=[mx for i in a]
ans[t[-1][0]]=t[-2][1]
for k in ans:
    print(k)

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

maxinum = max(nums)
maxinum2 = -1
for i in range(N):
    if nums[i] == maxinum:
        if maxinum2 == -1:
            maxinum2 = max(nums[0:i] + nums[i+1:])
        print(maxinum2)
    else:
        print(maxinum)

Solution (Python):
N = int(input())
A_l = []
for i in range(N):
    A_l.append(int(input()))
    
A_max = max(A_l)
A_tmp = A_l.copy()
A_tmp.remove(A_max)
A_second = max(A_tmp)
for j in range(N):
    if A_l[j] != A_max:
        print(A_max)
    else:
        print(A_second)

Solution (Python):
N = int(input())
A = []
B = []
for i in range(N):
	A.append(int(input()))
	
max_1 = max(A)
B = A[:]
B.remove(max_1)
max_2 = max(B)

for i in A:
	if i == max_1:
		print(max_2)
	else:
		print(max_1)

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

for i in range(n):
  if a[i] == max_a:
    print(sec_max)
  else:
    print(max_a)

Solution (Python):
import numpy as np
n=int(input())
a=[]
m=[]
for i in range(n):
  a.append(int(input()))
m.append(a.index(max(a)))
m.append(a.pop(m[0]))
m.append(max(a))

for i in range(m[0]):
  print(m[1])
  
print(m[2])

for i in range(m[0]+1,n):
  print(m[1])

Solution (Python):
import numpy as np

i = input()
N = int(i)
A = np.array([0]*N)
i = input()
a = int(i)
A[0] = a
i = input()
b = int(i)
A[1] = b
snd = min(a, b)
fst = max(a, b)
for x in range(N - 2):
    j = input()
    y = int(j)
    A[x+2] = y
    if y <= fst:
        snd = max(snd, y)
    fst = max(fst, y)

for x in range(N):
    if A[x] < fst:
        print(fst)
    else:
        print(snd)

Solution (Python):
import heapq
N = int(input())
A = [None]*N
for i in range(N):
    A[i] = {
        "index": i,
        "value": int(input())
    }

B = heapq.nlargest(2, A, key=lambda e:e["value"])
for i in range(N):
    if i == B[0]["index"]:
        print(B[1]["value"])
    else:
        print(B[0]["value"])

Solution (Python):
n = int(input())
li = [int(input()) for i in range(n)]
a = sorted(li)
if a[-2] == a[-1]:
    for i in range(n) : print(a[-1])
else:
    for i in range(n) : print(a[-1] if li[i]!=a[-1] else a[-2])

Solution (Python):
n = int(input())
ls = [int(input()) for _ in range(n)]
ls_sort = sorted(ls,reverse=True)

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

Solution (Python):
n=int(input())
a=[]
b=[]
for i in range(n):
    num=int(input())
    a.append(num)
    b.append(num)
b.sort(reverse=True)
x=a.count(b[0])
for i in range(n):
    if(a[i]==b[0]):
        if(x==1):
            print(b[1])
        else:
            print(b[0])
    else:
        print(b[0])

Solution (Python):
N = int(input())
a_list = []
max_v = -1
sec = -1
tmp = 0
drop = False
max_ind = []
for i in range(N):
    a_list.append(int(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)

Solution (Python):
n = int(input())
list = []
max = 0
second = 0
max_index = []

for i in range(n):
    num = int(input())
    if (num > max):
        max = num
    elif (num > second):
        second = num
    list.append(num)

counter = list.count(max)

for i,x in enumerate(list):
    if (x == max) & (counter == 1):
        print(second)
    else:
        print(max)

Solution (Python):
import numpy as np

n = int(input())
arr = np.array([int(input()) for _ in range(n)])

a_max = arr.max()

idx = np.where(arr == a_max)[0]

if len(idx) > 1:
    for i in range(n):
        print(a_max)

    exit()

not_arr = arr[arr != a_max]

b_max = not_arr.max()

t = idx[0]
for i in range(n):
    if i == t:
        print(b_max)
    else:
        print(a_max)

Solution (Python):
import copy

N = int(input())
l = []
for i in range(N):
  l.append(int(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)

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

max_ = max(list)
for i in range(n):
    a = list[i]
    if a == max_:
        del list[i]
        ans = max(list)
        print(ans)
        list.insert(i,a)
        if ans == max_:
            for j in range(n-i-1):
                print(max_)
            break
    else:
        print(max_)

Solution (Python):
N = int(input())
s = [int(input()) for i in range(N)]
ld = sorted(s, reverse=True)
D = int(s.index(ld[0]))

if N == 1:
    print(s[0])
else:
    for i in range(D):
        print(ld[0])
    print(ld[1])
    for i in range(N-D-1):
        print(ld[0])

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

Solution (Python):
a = int(input()) 
b = [int(input()) for i in range(a)] 
 
m=max(b)
sorted(b)
s=sorted(b)[-2]
for i in range(a):
  if m>b[i]:
    print(m)
  else:
    print(s)

Solution (Python):
import numpy as np 
n = int(input())
a = [int(input()) for i in range(n)]
aa = np.array(a)
maxa = max(aa)
argmax = np.argmax(aa)

for i in range(n):
    if i == argmax:
        tmp = np.delete(aa,i)
        print(max(tmp))
    else:
        print(maxa)

Solution (Python):
n = int(input())
al = [int(input()) for i in range(n)]
m1, m2 = 0, 0
for a in al:
    if m1 < a:
        m1=a
    elif m2 < a:
        m2=a
for a in al:
    print(m2) if m1 == a else print(m1)

Solution (Python):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = sorted(A, reverse=True)
for i in range(N):
  if A[i] == B[0]:
    print(B[1])
  else:
    print(B[0])

Solution (Python):
N = int(input())
AList = [int(input()) for i in range(N)]
max_AList = max(AList)
max2nd_AList = sorted(AList, reverse = True)[1]

for i in range(N) :
    if AList[i] == max_AList :
        print(max2nd_AList)
    else :
        print(max_AList)

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

l.sort()
for b in range(n):
  if i != b:
    print(x)
  else:
    print(l[n-2])

Solution (Python):
import itertools

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

max_list = [0] + list(itertools.accumulate(a, func=max))
max_list_r = ([0] +list(itertools.accumulate(reversed(a), func=max)))[::-1]
for i in range(n):
    print(max(max_list[i], max_list_r[i + 1]))

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

N = int(input())
A = [int(input()) for _ in range(N)]
amax = max(A)
amaxcnt = A.count(amax)

for i in range(N):
    ai = A[i]
    if ai == amax and amaxcnt == 1:
        A.pop(i)
        print(max(A))
        A.insert(i, 0)
    else:
        print(amax)

Solution (Python):
from sys import stdin


def main():
    N = int(stdin.readline())
    A = [int(input()) for _ in range(N)]

    new_A = sorted(A, reverse=True)
    max_A = new_A.pop(0)
    next_max_A = new_A.pop(0)

    for a in A:
        if max_A == a:
            print(next_max_A)
        else:
            print(max_A)


if __name__ == "__main__":
    main()

Solution (Python):
import itertools
N=int(input())
A=[int(input()) for _ in range(N)]
B=list(itertools.accumulate(A,func=max))
C=list(itertools.accumulate(A[::-1],func=max))[::-1]
print(C[1])
for i in range(1,N-1):
    print(max(B[i-1],C[i+1]))
print(B[-2])

Solution (Python):
import copy

data = []
i = int(input())

data = [int(input()) for _n in range(i)]
maxInt = max(data)
data2 = copy.copy(data)
data2.remove(maxInt)
max2Int = max(data2)
for n in range(i):
	if maxInt != data[n]:
		print(maxInt)
	else:
		print(max2Int)

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

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

x = sorted(A, reverse=True)

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

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

ans = []
front_max_list, back_max_list = [0], [0]

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

for i in range(N):
    print(max(front_max_list[i], back_max_list[N - i - 1]))

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

a = [int(input()) for _ in range(n)]
b = sorted(a)
m1 = b[-1]
m2 = b[-2]

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

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

max_val = 0
for i in range(N):
    input_val = int(input())
    if (max_val < input_val):
        max_val = input_val
    A.append(input_val)
    if (i < N -1):
        M1.append(max_val)

max_val = 0
for i in range(N-1):
    input_val = A[N-1-i]
    if (max_val < input_val):
        max_val = input_val
    M2.append(max_val)

if (N<=2):
    print(A[1])
    print(A[0])
else:
    for i in range(N):
        print(max(M1[i], M2[N-1-i]))

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

maxmax=max(a)
maxmax_ind=a.index(maxmax)
a[maxmax_ind]=0
maxmax2=max(a)
a[maxmax_ind]=maxmax

if maxmax==maxmax2:
    for i in range(n):
        print(maxmax)

else:
    for i in range(n):
        if i==maxmax_ind:
            print(maxmax2)
        else:
            print(maxmax)

Solution (Python):
if __name__ == '__main__':
    a = int(input())
    list = []
    list2=[]
    for i in range(a):
        b = int(input())
        list.append(b)
        list2.append(b)
    list.sort(reverse=True)
    for i in list2:
        if i == list[0]:
            print(list[1])
        else:
            print(list[0])

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

    max1st = max(A)
    max1stIndex = A.index(max1st)

    for i in range(len(A)):
        if i == max1stIndex:
            tmp = A[i]
            A[i] = 0
            print(max(A))
            continue

        print(max1st)




if __name__ == '__main__':
    main()

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

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

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

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

new_li = sorted(li, reverse=True)

M = new_li[0]
m = new_li[1]

for i in range(N):
    if li[i] != M:
        print(M)
    elif li[i] == M:
        print(m)

Solution (Python):
import copy
n = int(input())
a = []
for s in range(n):
    a.append(int(input()))
m = max(a)
b = sorted(a)
if b[-2] == m:
  for c in range (n):
    print(m)
else:
  for t in range(n):
    if a[t] == m:
      b = copy.copy(a)
      b[t:t+1] = []
      print(max(b))
    else:
      print(m)

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

maxnumber = max(A)
secondmax = sorted(A)[-2]

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