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):
import sys
input=sys.stdin.readline
N=int(input()) 
a=[int(input()) for i in range(N)]
b=sorted(a)
n=0
c=a.index(max(a))
for n in range(N):
    if n==c:
        print(b[-2])
    else:
        print(b[-1])

Solution (Python):
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
maxA = max(A)
secondA = sorted(A)[-2]
for j in range(N):
    if (A[j] != maxA):
        print(maxA)
    else:
        print(secondA)

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
maxv = max(a)
if a.count(maxv) == 1:
    for i in range(n):
        if a[i] == maxv:
            print(sorted(a, reverse=True)[1])
        else:
            print(maxv)
else:
    for i in range(n):
        print(maxv)

Solution (Python):
N=int(input())
A=[int(input())for i in range(N)]
T=A.copy()
A.sort()
max1=A[-1]
mcount=A.count(max1)
max2=A[-2]
for i in range(N):
    if T[i]==max1 and mcount==1:
        print(max2)
    else:
        print(max1)

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

A = []

for n in range(N):
    A.append([n, int(input())])
As = sorted(A, reverse=True, key=lambda x: x[1])

for n in range(N):
    i = 0    
    if n == 0:
        if A[0] == As[0]:
            print(As[1][1])
        else:           
            print(As[0][1])
    else:
        while i < n:
            if A[n] == As[i]:
                i+=1
                print(As[i][1])
                break

            elif A[n][1] > As[i][1]:
                    i += 1
            else:
                print(As[i][1])
                break

Solution (Python):

n = int(input())
 
MAX = 0
MAX_index = []
MAX_sec = 0
for i in range(n):
    a = int(input())
    if MAX == a:
        MAX_index.append(i)
    elif MAX < a:
        if len(MAX_index)==i:
            MAX_sec = MAX
        MAX_index = [i]
        MAX = a
    elif MAX_sec < a:
        MAX_sec = a
    

        
if len(MAX_index)==1:
    for i in range(n):
        if i==MAX_index[0]:
            print(MAX_sec)
        else:
            print(MAX)
else:
    for i in range(n):
        print(MAX)

Solution (Python):
i=input;p=print;n=int(i());r=range(n);a=[int(i())for _ in r];m=max(a);o=sorted(a)[-2];[[p(m)for _ in r]if m==o else[p(o)if a[i]==m else p(m)for i in r]]

Solution (Python):
import numpy as np

N = input()
N = int(N)
A = []
for i in range(0,N):
    Ai=input()
    Ai = int(Ai)
    A.append(Ai)

A_set = set(A)
A_setlist = list(A_set)
Anp = np.array(A)
Amax = max(A)
maxidx = np.where(Anp==Amax)[0]

if(len(A_setlist)==1):
    for i in range(0,N):
        print(A_setlist[0])
else:
    if(len(maxidx)>1):
        ansNp = np.ones(N)*Amax
    else:
        Anp_bk =np.copy(Anp)
        Anp[Anp==Amax] = -1
        Anp2list = list(Anp)
        Amax2 = max(Anp2list)
        ansNp = np.where(Anp_bk==Amax,Amax2,Amax)
    for i in range(0,N):
        print(int(ansNp[i]))

Solution (Python):
a=[]
b=int(input())
c=[]
i=0
while i<b:
    a.append(int(input()))
    i+=1
for x in a:
    c.append(x)
c.sort()

i=1

if c[-1]!=c[-2]:
    while i<=b:
        if a[i-1]!=c[-1]:
            print(c[-1])
        else:
            print(c[-2])
        i+=1
else:
    while i<=b:
        print(c[-1])
        i+=1

Solution (Python):
import sys
from operator import itemgetter

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

if __name__ == "__main__":
    n = int(input())
    al = [(i, int(input())) for i in range(n)]

    al.sort(key = itemgetter(1), reverse = True)

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

Solution (Python):
n = int(input())
import numpy as np
a = np.array([int(input()) for _ in range(n)])
M = max(a)
if np.sum(a==M) >= 2:
  [print(M) for _ in range(n)]
else:
  result = [M]*n
  result[np.argmax(a)] = sorted(a)[-2]
  [print(i) for i in result]

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

FIRST = max(A)
if A.count(FIRST) > 1:
    for i in range(N):
        print(FIRST)
else:
    SECOND = max([a for a in A if a != FIRST])
    for a in A:
        if a == FIRST:
            print(SECOND)
        else:
            print(FIRST)

Solution (Python):

import numpy as np

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

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

MAX = int(np.max(A))
A.remove(MAX)
MAX2 = int(np.max(A))

for i in range(N):
    if B[i] == MAX:
        print(MAX2)
    
    else:
        print(MAX)

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

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

As = ld = sorted(A, reverse=True)

m = As[0:2]

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

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


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
b=sorted(a, reverse=True)
maxa=b[0]
nexta=b[1]
for i in a:
  if i==maxa:
    print(nexta)
  else:
    print(maxa)

Solution (Python):
import math

max = [0, 0]
max2 = 0

n = int(input())

for i in range(n):
    sub = int(input())
    if(max2 < sub):
        if(max[0] < sub):
            max2 = max[0]
            max[0] = sub
            max[1] = i
        else: 
            max2 = sub

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

Solution (Python):

import sys
import copy


def solve(N: int, A: "List[int]"):
    Ap = copy.copy(A)

    A.sort()
    maxA = A[-1]
    A2 = A[-2]

    if maxA == A2:
        for _ in range(N):
            print(maxA)
    else:
        for a in Ap:
            if a == maxA:
                print(A2)
            else:
                print(maxA)
    return



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

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input().strip())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)
m = 0
m2 = 0
var = 0
z = 0
for k in range(N):
  a = grid[k][0]
  if a > m:
    m2 = m
    m = a
    z = k
    if var > 0:
      var = 0
  elif a == m:
    var = var+1
  elif a > m2: 
    m2 = a
if var ==0:
  for k in range(N):
    if k == z:
      print(m2)
    else:
      print(m)
if var > 0:
  for k in range(N):
    print(m)

Solution (Python):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
ind_M = a.index(a_max)
tmpl = a
tmpl.pop(ind_M)
for i in range(n):
    if i != ind_M:
        print(a_max)
    else:
        print(max(tmpl))

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

max1 = 0
max1_ind = 0
max2 = 0
max2_ind = 0
 
for i in range(n):
    if max2 <= a[i]:
        if max1 <= a[i]:
            max2 = max1
            max2_ind = max1_ind
            max1 = a[i]
            max1_ind = i
            
        else:
            max2 = a[i]
            max2_ind = i
    
for j in range(n):
    if j == max1_ind:
        print(max2)
    else:
        print(max1)

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

biggest = 0
biggest_arg = 0
second_biggest = 0
second_biggest_arg = 0

for i in range(n):
  num = int(input())
  if num >= biggest:
    second_biggest = biggest
    second_biggest_arg = biggest_arg
    
    biggest = num
    biggest_arg = i
  elif num >= second_biggest:
    second_biggest = num
    second_biggest_arg = i

for i in range(n):
  if i == biggest_arg:
    print(second_biggest)
  else:
    print(biggest)

Solution (Python):
import copy
N = int(input())
A = [int(input()) for i in range(N)]
B = copy.copy(A)
Max_1 = max(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((i, int(input())))

a_sorted = sorted(a, key = lambda k:k[1])
max_index = a_sorted[-1][0]



a_max = a_sorted[-1][1]
a_sec_max = a_sorted[-2][1]

for i in range(0,n):
    if i != max_index:
        print(a_max)
    else:
        print(a_sec_max)

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

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

Solution (Python):

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

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

right = [0]
left = [0]

for a in A:
    left.append(max(a, left[-1]))

for a in reversed(A):
    right.append(max(a, right[-1]))

for i in range(N):
    print(max(left[i], right[N-i-1]))

Solution (Python):
n = int(input())
        
a = [(int(input()), i) for i in range(n)]
a.sort()
max_, max_index = a[-1]

for i in range(n):
  if i != max_index:
  	print(max_)
  else:
  	print(a[-2][0])

Solution (Python):
n = int(input())
s = []
p = []
for i in range(n):
    s.append(int(input()))
    
p = s[:] 
s.sort()
for i in p:
    if i != s[-1]:
        print(s[-1])
    else:
        print(s[-2])

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
tmp = max(A)
li = list(A)
li.sort(reverse=True)
if len(li)==1:
    tmp2 = li[0]
else:
    tmp2 = li[1]
for i in range(N):
    if A[i] != tmp:
        print(tmp)
    else:
        print(tmp2)

Solution (Python):

n = int(input())
li = [0]*n
for i in range(n):
    li[i] = int(input())

max_ = max(li)
max_i = li.index(max_)
li.pop(max_i)
max2 = max(li)
res = [max_]*n
res[max_i] = max2

for a in res:
    print(a)

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

    max_value = max(A)
    max_index = A.index(max_value)

    for i in range(N):
        if i != max_index:
            print(max_value)
        else:
            if i == 0:
                print(max(A[1:]))
            elif i == N - 1:
                print(max(A[: N - 1]))
            else:
                print(max(max(A[:i]), max(A[i + 1 :])))

    return


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = []
ans = []
m = 0
sec = 0
c = 0
for i in range(n):
    num = int(input())
    a.append(num)
    m = max(num, m)

for i in range(n):
    if a[i] < m:
        sec = max(a[i], sec)

c = a.count(m)

if c == 1:
    for i in range(n):
        if a[i]==m:
            ans.append(sec)
        else:
            ans.append(m)
else:
    for i in range(n):
        if a[i]==m:
            if c>0:
                ans.append(m)
                c -= 1
            else:
                ans.append(sec)
        else:
            ans.append(m)

for i in range(len(ans)):
    print(ans[i])

Solution (Python):
import heapq
n = int(input())
q = []
for i in range(n):
  heapq.heappush(q, [-int(input()), i])
mx_1, idx = heapq.heappop(q)
mx_2, _ = heapq.heappop(q)
for i in range(n):
  if i == idx:
    print(-mx_2)
  else:
    print(-mx_1)

Solution (Python):
count = int(input())
nlist = []
for i in range(count):
    a = int(input())
    nlist.append(a)
mlist = tuple(nlist)
biggest = max(mlist)
nlist.remove(biggest)
c = max(nlist)

for i in range(count):
    if mlist[i] == biggest:
        print(c)
    else:
        print(biggest)

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

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

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

m = max(a)
l = [m] * n
index = a.index(m)
a.remove(m)
nm = max(a)
l[index] = nm
for j in range(0, n):
    print(l[j])

Solution (Python):
import numpy as np
n = int(input())
A = np.array([int(input()) for i in range(n)])
idxs = np.argsort(A)
m1 = A[idxs[-1]]
m2 = A[idxs[-2]]
for i in range(n):
  if i != idxs[-1]:
    print(m1)
  else:
    print(m2)

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

sort_A = sorted(A)
max = sort_A[N - 1]
sec = sort_A[N - 2]

count = A.count(max)

if count == 1:
  p = A.index(max)
  
  for i in range(p):
    print(max)
  
  print(sec)
  
  for j in range(p,N - 1):
    print(max)

else:
  for k in range(N):
    print(max)

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

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

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

for number in number_list:
  if output_always_max:
    print(str(number_max))
  else:
    if number == number_max:
      print(str(number_second_max))
    else:
      print(str(number_max))

Solution (Python):

N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
if len(R) >= 2:
  max_v2 = R[1]
else:
  max_v2 = R[0]
R2 = sorted(A, reverse=True)
if R2[0] == R2[1]:
  signal = 1
else:
  signal = 0
  
for i in range(N):
  if A[i] == max_v and signal == 0:
    print(max_v2)
  else:
    print(max_v)

Solution (Python):
N=int(input())
I=[int(input()) for i in range(N)]
r=max(I)
if I.count(r)>=2:
	for j in range(N):
		print(r)
else:
	for k in range(N):
		X=int(I[k])
		if X!=r:
			print(r)
		else:
			I.remove(I[k])
			print(max(I))
			I.insert(k,X)

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

m1 = m2 = 0

for x in A:
    if x > m2:
        if x >= m1:
            m1, m2 = x, m1
        else:
            m2 = x

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

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

ans=sorted(A, reverse=True)[:2]
for n in A:
    if n == ans[0]:
        print(ans[1])
    else:
        print(ans[0])

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

Solution (Python):
n=int(input())
a=[0]*n
adic={}
amod=[]
for i in range(n):
    aa=int(input())
    a[i]=aa
    if aa in adic:
        adic[aa]+=1
    else:
        adic[aa]=1
    if adic[aa]<3:
        amod.append(aa)    
amod=sorted(amod)
p=len(amod)
for i in range(n):
    m = p - 1
    while a[i] == amod[m] and adic[a[i]]==1 and m > 0:
        m -= 1
    print(amod[m])

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

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

for i in range(n):
	if A[i] == A_max:
		print(B_max)
	else:
		print(A_max)

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

npA = np.array(A)
max_number = max(A)
max_itr = np.where(npA == npA.max())
if len(max_itr[0]) == 1:
  for i in range(N):
    if i != max_itr[0][0]:
      print(max_number)
    else:
      print(sorted(A)[-2])
else:
  for i in range(N):
    print(max_number)

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

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

max_num, index = max(a), a.index(max(a))
a = sorted(a, reverse=True)

for i in range(n):
    if i == index:
        print(a[1])
    else:
        print(max_num)

Solution (Python):
N = int(input())
A = []
m = 0
for i in range(N):
    A.append(int(input()))
task = 0
m = max(A)
m2 = sorted(A)[-2]
maxindex = []
for i in range(N):
    if A[i] == m:
        print(m2)
    else:
        print(m)

Solution (Python):
n = int(input())
li = []
for i in range(n):
    x = int(input())
    li.append(x)
p = max(li)
r = li.index(p)
li.remove(p)
q = max(li)
for i in range(n):
    if i == r:
        print(q)
    else:
        print(p)

Solution (Python):
from copy import copy

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

DD = copy(D)
v1 = max(D)
m1 = D.index(v1)

del D[m1]
v2 = max(D)

[print(v2) if i == v1 else print(v1) for i in DD]

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

    set_A = set(A)
    max_A = max(A)
    count_A = A.count(max_A)
    for a in A:
        if a == max_A and count_A == 1:
            print(sorted(set_A)[-2])
        else:
            print(max_A)

main()

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

max_index=-1
max_number=-1
second_number=-1
max_count=0
i=0
while(i<N):
    a=int(input())
    if(max_number<a):
        second_number=max_number
        
        max_number=a
        max_index=i
        max_count=0
    elif(max_number==a):
        max_count+=1
        max_index=-1
    elif(second_number<a):
        second_number=a
    i+=1

j=0
while(j<N):
    if(j==max_index and max_count==0):
        print(second_number)
    else:
        print(max_number)
    j+=1

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
sa = sorted(a)
maxi = sa.count(sa[-1])
ans = sa[-1]
max_index = a.index(sa[-1])
if maxi == 1:
    for i in range(n):
        if i == max_index:
            print(sa[-2])
        else:
            print(ans)
else:
    for i in range(n):
        print(ans)

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 = [int(input()) for _ in range(N)]
A_max = max(A)
a = A.index(A_max)
A.sort(reverse=True)
for i in range(N):
    if i == a:
        print(A[1])
    else:
        print(A[0])

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

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

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
a = sorted(A.copy())
a1 = a[len(A)-1]
a2 = a[len(A)-2]

for i in A:
    if i == a1:
        print(a2)
    else:
        print(a1)

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

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

    if d > max_lst[1]:
        tmp = max_lst[1]
        max_lst[1] = d 
        max_lst[0] = tmp
    
    elif d > max_lst[0]:
        max_lst[0] = d
        
max_lst = sorted(max_lst, reverse=True)

for i in a:
    if i != max_lst[0]:
        print(max_lst[0])
    else:
        print(max_lst[1])

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

Solution (Python):
N=int(input())
A=[int(input()) for _ in range(N)]
B=sorted(A)
maximum=A.index(max(A))
for i in range(N):
    if i==maximum:
        print(B[-2])
    else:
        print(B[-1])

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

m1 = 0
m1i = 0
m2 = 0
for i,a in enumerate(A):
    if a > m2:
        m2 = a
    if a > m1:
        m2 = m1
        m1 = a
        m1i = i

for n in range(N):
    if n == m1i:
        print(m2)
    else:
        print(m1)

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

Solution (Python):
from itertools import accumulate

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

inf = float('inf')

L = list(accumulate(A, max))
R = list(accumulate(reversed(A), max))

L = [-inf] + L
R = [-inf] + R[:-1]

M = (max(l, r) for l, r in zip(L, reversed(R)))

for m in M:
    print(m)

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

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

max_value, max_cnt, sub_max = -1, 0, -1
for v in A:
	if v > max_value:
		sub_max = max_value
		max_value = v
		max_cnt = 1
	elif v == max_value:
		max_cnt += 1
	elif v > sub_max:
		sub_max = v

if max_cnt >= 2:
	print('\n'.join([str(max_value)] * N))
else:
	for v in A:
		print('%d' % (max_value if v != max_value else sub_max))

Solution (Python):
import sys

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


if __name__ == '__main__':

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

Solution (Python):
n = input()
A=[]
for i in range(0,int(n)):
  a=input()
  A.append(int(a))
B=[]
B =sorted(A)
  
for i in range(0,int(n)):
  if ( B[-1] == A[i]):
  	print (B[-2])
  else:
    print(B[-1])

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

llss=sorted(ls)
for i in range(n):
    if llss[n-1]==ls[i]:
        print(llss[n-2])
    else:
        print(llss[n-1])

Solution (Python):

n = int(input())
l = [0]*n
s = set()
f_max,s_max = 0,0
c = 0
for i in range(n):
    a = int(input())
    l[i] = a
    if f_max < a:
        s_max = f_max
        f_max = a
        c = 0
    elif s_max < a < f_max:
        s_max = a
    elif f_max == a:
        c+=1



if len(s)==1:
    for i in range(n):
        print(l[0])

    exit()

if c==0:
    for i in range(n):
        if l[i]==f_max:
            print(s_max)
        else:
            print(f_max)
else:
    for i in range(n):
        print(f_max)

Solution (Python):


import sys

sys.setrecursionlimit(10**7)


input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    n, = read_h()
    arr = read_v(n)

    max_asc = [0]
    for a in arr[:n - 1]:
        max_asc.append(max(max_asc[-1], a))
    

    max_desc = [0]
    for a in arr[::-1][:n - 1]:
        max_desc.append(max(max_desc[-1], a))
    max_desc = max_desc[::-1]
    

    
    

    for a, d in zip(max_asc, max_desc):
        print(max(a, d))


if __name__ == '__main__':
    main()

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

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

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

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

sorted_A_LIST = sorted(A_LIST)
largest = sorted_A_LIST[-1]
second_largest = sorted_A_LIST[-2]

for i in range(N):
    if A_LIST[i] < largest:
        print(largest)
    else:
        print(second_largest)

Solution (Python):




def main():
    n = int(input())

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

    a_sorted = sorted(a, reverse=True)
    a_max = max(a)

    for i in a:
        if i != a_max:
            print(a_max)
            continue

        index = a_sorted.index(i)
        if index == 0:
            print(a_sorted[index + 1])


if __name__ == '__main__':
    main()

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

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

most_max = max(value_list)

if len([i for i, x in enumerate(value_list) if x == most_max]) == 2:
    for i in range(n):
        print(most_max)
else:
    most_max_index = value_list.index(most_max)
    value_list[most_max_index] = 0
    second_max = max(value_list) 
    value_list[most_max_index] = most_max
    
    for i in range(n):
        if value_list[i] == most_max:
            print(second_max)
        else:
            print(most_max)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
max_a = max(A)
max_count = A.count(max_a)
if max_count == 1:
    ind = A.index(max_a)
    max_b = max(A[:ind]+A[ind+1:])

for i in range(N):
    if max_count > 1:
        print(max_a)
    else:
        if A[i] == max_a:
            print(max_b)
        else:
            print(max_a)

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

imax = max(a)
b = sorted(a)

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

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


A_hash = {}
for i in range(N):
        if A[i] in A_hash:
                A_hash[A[i]] += 1
        else:
                A_hash[A[i]] = 1


A_max = max(A)
A_keys = list(A_hash.keys())
A_keys.sort()

if len(A_keys) > 1:
        A_second_max = A_keys[-2]
else:
        A_second_max = A_keys[-1]



for i in range(N):
        if A[i] == A_max:
                if A_hash[A_max] == 1:
                        print(A_second_max)
                else:
                        print(A_max)
        else:
                print(A_max)

Solution (Python):
import numpy as np
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
    
b = sorted(a,reverse=True)
maxa = b[0]
submaxa = b[1]
maxid = np.argmax(a)
for i in range(n):
    if i == maxid:
        print(submaxa)
    else:
        print(maxa)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(input()) for _ in range(N)]
    leftmax = [-1] * N
    rightmax = [-1] * N
    for i in range(1, N):
        leftmax[i] = max(leftmax[i-1], A[i-1])
        rightmax[N-i-1] = max(rightmax[N-i], A[N-i])
    
    
    ans = ""
    for i in range(N):
        ans += str(max(leftmax[i], rightmax[i])) + " "
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

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

m = 0
m_index = -1
for i in range(N):
    if A[i] > m : 
        m = A[i]
        m_index = i

mm = 0
mm_index = -1
for i in range(N):
    if i != m_index:
        if A[i] > mm : 
            mm = A[i]
            mm_index = i          

for i in range(N):
    if i == m_index : 
        print(mm)
    else :
        print(m)

Solution (Python):
import numpy as np

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


sorted_nums = sorted(nums, reverse=True)
max_num = sorted_nums[0]

second_max_num = sorted_nums[1]

for i in range(N):
    
    exclude_num = nums[i]
    
    if exclude_num == max_num:
        print(second_max_num)
    
    else:
        print(max_num)

Solution (Python):
import copy

n = int(input())
arr = [int(input()) for i in range(n)]
brr = sorted(arr, reverse=True)
ind = arr.index(max(arr))




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

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

maxleft = [0] * (N+2)
maxright = [0] * (N+2)

for i in range(N):
    maxleft[i+1] = max(maxleft[i],A[i])
    maxright[N-i] = max(maxright[N-i+1],A[N-i-1])

for i in range(N):
    print(max(maxleft[i], maxright[2+i]))

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

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

temp = sorted(arr)
max_element = temp[-1]
second_max = temp[-2]

for i in arr:
	if i != max_element:
		print(max_element)
	else:
		print(second_max)

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

max1=max(A)
if A.count(max(A))>1:
    for i in range(N):
        print(max1)
else:
    max2=sorted(A)[-2]
    for a in A:
        if a==max1:
            print(max2)
        else:
            print(max1)

Solution (Python):
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(list(set(a[:])),reverse=True)
maxa=aa[0]
f=False if a.count(maxa) != 1 else True
for i in range(n):
    if a[i] == maxa and f:
        print(aa[1] if len(aa) != 1 else maxa)
    else:
        print(maxa)