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[i] = int(input())

value_sorted = sorted(A.items(), key=lambda x:x[1])
max_value = 0

for i in range(N):
    max_value_tapple = value_sorted[-1]
    if max_value_tapple[0] == i:
        max_value_tapple = value_sorted[-2]
        max_value = max_value_tapple[1]
    else:
        max_value = max_value_tapple[1]
    print(max_value)

Solution (Python):
import numpy as np
import copy
def main():
    n = int(input())
    
    max_num = 0
    max_second = 0
    for i in range(n):
        a = int(input())
        if a > max_num:
            max_num = a
            max_index = i
        elif a > max_second:
            max_second = a

    for j in range(n):
        if j == max_index:
            print(max_second)
        else:
            print(max_num)



    
    
if __name__ == '__main__':
    main()

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

Solution (Python):
def mainFunc():
    N = int(input())
    ai = [0 for i in range(N)]
    m1, m2 = 0, 0
    for i in range(N):
        ai[i] = int(input())
        if m1 <= ai[i]:
            m2 = m1
            m1 = ai[i]
        elif m2 <= ai[i]:
            m2 = ai[i]

    ans = ""
    for i in range(N):
        ans += str(m1) if ai[i] < m1 else str(m2)
        ans += "\n"
    
    print(ans)
mainFunc()

Solution (Python):

import copy
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_sort = copy.deepcopy(a)
a_sort.sort()
max = a_sort[n-1]
max_next = a_sort[n-2]
for i in range(n):
    if a[i] == max:
        print(max_next)
    else:
        print(max)

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

Solution (Python):
from itertools import accumulate
N = int(input())
A = [int(input()) for _ in range(N)]
print(*list(map(max, [0]+list(accumulate(A, max))[:-1],
                list(accumulate(A[::-1], max))[::-1][1:]+[0])), sep="\n")

Solution (Python):
n = int(input())
l = [int(input()) for _ in [0]*n]


import sys
if l.count(max(l))>1:
  m1 = max(l)
  for i in range(n):
    print(m1)

else:
  s=set(l)
  m1 = max(s)
  s.remove(max(s))
  m2 = max(s)
  for i in l:
    if i == m1:
      print(m2)
    else:
      print(m1)

Solution (Python):
def calculate(arr):

    largest,second = findLargetAndSecond(arr)

    for i in range(len(arr)):
        value = arr[i]
        if largest != value:
            print(largest)
        else:
            print(second)


def findLargetAndSecond(arr):
    largest = 0
    second = 0

    for i in range(0,len(arr)):
        if arr[i] > largest:
            second = largest
            largest = arr[i]
        else:
            if arr[i] >= second:
                second = arr[i]

    return largest,second



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

calculate(arr)

Solution (Python):
n=int(input())
a=[int(input()) for _ in range(n)]
a_copy=a[:]
first=max(a)
a_copy.remove(first)
second=max(a_copy)

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

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

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

highmax = 0
maxs=0
for i in range(n):
    if highmax < a[i]:
        highmax = a[i]
        maxs = i

for i in range(n):
    max = 0
    if maxs != i:
        print(a[maxs])
    else:
        for j in range(n):
            if i != j:
                if max < a[j]:
                    max = a[j]
        print(max)

Solution (Python):
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    B = sorted(A)
    m = B[-1]
    mm = B[-2]

    if m == mm:
        for _ in range(N):
            print(m)

    else:
        for a in A:
            if a != m:
                print(m)
            else:
                print(mm)


main()

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

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

B.sort(reverse=True)
for i in range(N):
    if B[0][1] == i:
        print(B[1][0])
    else:
        print(B[0][0])

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

x=max(A)
count=(A.count(x))
index=[]
if count!=1:
    for i in range(N):
        print(x)
else:
    B=copy.copy(A)
    B.remove(x)
    y=max(B)
    for i in range(N):
        if A[i]==x:
            print(y)
        else:
            print(x)

Solution (Python):
N=int(input())
A=[]
max1=0
max2=0
for i in range(N):
	A.append(int(input()))
	
max1=max(A)
cnt=0
for i in range(N):
	if max1 is A[i]:
		cnt += 1
	elif max2 < A[i]:
		max2 = A[i]	
		
for i in range(N):
	if cnt >= 2:
		print(max1)
	else:	
		if max1 == A[i]:
			print(max2)
		else:
			print(max1)

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

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

M = max(A)
I = A.index(M)
del A[I]

K = max(A)

for i in range(N):
    if i == I:
        print(K)
    else:
        print(M)

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

F, S = sorted(A, reverse=True)[:2] 

for i in A:
    if i == F:
        print(S)
    else:
        print(F)

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

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

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

maxA = max(A)
index = A.index(maxA)
A.sort()

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

Solution (Python):
def main():
    n = int(input())
    a_list = [int(input()) for _ in range(n)]
    a_sorted = sorted(a_list)
    a_first = a_sorted[-1]
    a_second = a_sorted[-2]
    a_count = a_list.count(a_first)

    if a_count >= 2:
        for a in a_list:
            print(a_first)
    else:
        for a in a_list:
            if a == a_first:
                print(a_second)
            else:
                print(a_first)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n = int(input())
    a_list = [int(input()) for _ in range(n)]
    a_sorted = sorted(a_list)
    a_first = a_sorted[-1]
    a_second = a_sorted[-2]

    for a in a_list:
        if a == a_first:
            print(a_second)
        else:
            print(a_first)


if __name__ == '__main__':
    main()

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

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())
A = [int(input()) for i in range(N)]
Amax = max(A)
cnt = A.count(Amax)
if cnt >= 2:
    for i in range(N):
        print(Amax)
else:
    A[A.index(Amax)] = 0
    b = max(A)
    for a in A:
        if a == 0:
            print(b)
        else:
            print(Amax)

Solution (Python):
N=int(input())
A=[int(input()) for _ in range(N)]
MAX1=max(A)
for n in range(N):
    if MAX1==A[n]:
        A[n]=0
        break
MAX2=max(A)
A[n]=MAX1
for a in A:
    if MAX1==a:
        print(MAX2)
    else:
        print(MAX1)

Solution (Python):
n = int(input())
a_lis = []
for i in range(n):
    a_lis.append(int(input()))
a_s = sorted(a_lis)
max_a = a_s[-1]
n_max_a = a_s[-2]
for i in range(n):
    if a_lis[i] == max_a:
        print(n_max_a)
    else:
        print(max_a)

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

a_sort = sorted(a)


max_number = a_sort[-1]
sub_max_number = a_sort[-2]

for i in range(n):
  if a[i] == max_number:
    print(sub_max_number)
  else:
    print(max_number)

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

one_ind = A.index(max(A))
one_max = max(A)
del A[one_ind]
sec_ind = A.index(max(A))
sec_max = max(A)

for i in range(N):
    if i != one_ind:
        print(one_max)
    else:
        print(sec_max)

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

sorted_L=sorted(L)


a=sorted_L[-1]
b=sorted_L[-2]

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

Solution (Python):
def exception_handling(N: int, A: list)->list:
    sorted_A = sorted(A)
    return [sorted_A[-1] if a != sorted_A[-1] else sorted_A[-2] for a in A]


if __name__ == "__main__":
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = exception_handling(N, A)
    for a in ans:
        print(a)

Solution (Python):
n = int(input())
a = []
for i in range(n):
    a.append([i, int(input())])
a.sort(key=lambda x: x[1])
ans = [0 for _ in range(n)]
for i in range(n):
    index = a[i][0]
    ans[index] = a[-2][1] if i == (n-1) else a[-1][1]
for a in ans:
    print(a)

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

max_num = max(A)
A_bk = A[:]
if (A.count(max_num)>=2):
    for i in range(N):
        print(max_num)
else:
    for i in range(N):
        if (A[i] != max_num):
            print(max_num)
        else:
            A_bk.remove(max_num)
            print(max(A_bk))

Solution (Python):
import copy
N = int(input())
A = [int(input()) for i in range(N)]
B = A.copy()
B.sort()
M,m = B[-1],B[-2]
for a in A:
    print(M if a != M else m)

Solution (Python):
n=int(input())
l=[int(input()) for i in range(n)]
s=sorted(l)
p=s[-1]
q=s[-2]
for i in range(n):
  if l[i]==p:
    print(q)
  else:
    print(p)

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):
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = [INT() for _ in range(N)]

B = sorted(A,reverse = True)
max_a = B[0]
second_a = B[1]

for a in A:
	if a != max_a: print(max_a)
	else: print(second_a)

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

Solution (Python):
import sys
def main():
    N = int(sys.stdin.readline())
    A = [int(sys.stdin.readline()) for i in range(N)]
    maxa = max(A)
    if A.count(maxa) > 1:
        for i in range(N):
            print(maxa)
    else:
        for i in range(N):
            if A[i] != maxa:
                print(maxa)
            else:
                print(sorted(A)[-2])
                
main()

Solution (Python):
import sys
def main():
    N = int(sys.stdin.readline())
    A = [int(sys.stdin.readline()) for i in range(N)]
    maxa = max(A)
    maxb = sorted(A)[-2]
    if A.count(maxa) > 1:
        for i in range(N):
            print(maxa)
    else:
        for i in range(N):
            if A[i] != maxa:
                print(maxa)
            else:
                print(maxb)
                
main()

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

t = sorted(a, reverse=True)

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

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

Solution (Python):
from collections import deque

num = int(input())

arr = []

for i in range(num):
    arr.append(int(input()))

arr0 = sorted(arr,reverse=True)
arr00 = arr0[0]
arr01 = arr0[1]

for i in range(num):
    if arr[i] != arr00:
        print(arr00)
    else:
        print(arr01)

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

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

b=sorted(a,reverse=True)
max_a=b[0]
max_a2=b[1]

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

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

L_sorted = sorted(L,reverse=True)
for i in L:
    if i == L_sorted[0]:
        print(L_sorted[1])
    else:
        print(L_sorted[0])

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

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

max_A = max(A)
max_c = A.count(max_A)

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

Solution (Python):

import sys
import copy

N = int(input())

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

a_list_copy = copy.copy(a_list)
maximum_list = []
for i in range(2):
    maximum_list.append(max(a_list_copy))
    a_list_copy.remove(max(a_list_copy))

if maximum_list[0] == maximum_list[1]:
    for a in a_list:
        print(maximum_list[0])
else:
    for a in a_list:
        if a == maximum_list[0]:
            print(maximum_list[1])
        else:
            print(maximum_list[0])

Solution (Python):
N=int(input())
L=[]
s,e,s1,e1,t=0,0,0,0,0
for i in range(N):
  L.append(int(input()))
s=L.index(max(L))
e=L[s]
L[s]=0
s1=L.index(max(L))
e1=L[s1]
for i in range(N):
  if i!=s:
    print(e)
  else:
    print(e1)

Solution (Python):
import copy

n = int(input())
a = [int(input()) for i in range(n)]
b = copy.deepcopy(a)
b.sort(reverse=True)
c = b[0]
d = b[1]

for i in range(n):
    if a[i] == c:
        print(d)
    else:
        print(c)

Solution (Python):
n = int(input())
A = [int(input()) for _ in range(n)]
semi_max_num, max_num = sorted(A)[-2:]
for a in A:
    if a != max_num:
        print(max_num)
    else:
        print(semi_max_num)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
a_max = max(a)
max_c = a.count(a_max)

for i in range(n) :
  if a[i] != a_max :
    print(a_max)
  else :
    if max_c == 1 :
      a[i] = 0
      print(max(a))
    else :
      print(a_max)

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

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
sorted_a = []
for item in a:
    sorted_a.append(item)
sorted_a.sort(reverse=True)
for num in a:
    if num == sorted_a[0]:
        print(sorted_a[1])
    else:
        print(sorted_a[0])

Solution (Python):
N = int(input())
max_1st = -1
max_1st_index = -1
max_2nd = -1
only_max = False
for i in range(0, N):
  if i == 0:
    max_1st = int(input())
    max_1st_index = 0
  elif i == 1:
    tmp = int(input())
    if (tmp > max_1st):
      max_1st, max_2nd = tmp, max_1st
      max_1st_index = 1
    else:
      max_2nd = tmp
  else:
    tmp = int(input())
    if (max_2nd < tmp) and (tmp < max_1st):
      max_2nd = tmp
    elif (max_1st < tmp):
      max_1st, max_1st_index = tmp, i
      only_max = False
    elif (max_1st == tmp):
      only_max = True

for j in range(0, N):
  if only_max:
    print(max_1st)
  else:
    if j == max_1st_index:
      print(max_2nd)
    else:
      print(max_1st)

Solution (Python):
N = int(input())
f = (-1, -1)
s = (-1, -1)
for n in range(N):
    A = int(input())
    if f[1] <= A:
        s = f
        f = (n, A)
    elif s[1] <= A:
        s = (n, A)
for n in range(N):
    print(f[1] if n != f[0] else s[1])

Solution (Python):

import math
import heapq
import bisect

MOD = 10**9+7

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

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

Solution (Python):

import math
import heapq
import bisect

MOD = 10**9+7

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

max_1 = 0
max_2 = 0
max_index = -1
for i in range(N):
    if A[i] > max_1:
        max_1 = A[i]
        max_index = i
    elif A[i] > max_2:
        max_2 = A[i]

for i in range(N):
    if max_1 == max_2:
        print(max_1)
    else:
        if i == max_index:
            print(max_2)
        else:
            print(max_1)

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

max1id,max1val=max(a,key=a.get),max(a.values())
a.pop(max1id)
max2id,max2val=max(a,key=a.get),max(a.values())
a[max1id]=max2val
for i in range(n):
  if i==max1id:
    print(max2val)
  else:
    print(max1val)

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

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

max1 = max1ad = max2 = 0
for i in range(n):
    a = int(input())
    if a > max1:
        max2 = max1
        max1 = a
        max1ad = i
    elif a > max2:
        max2 = a

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

Solution (Python):
n =int(input())
a = list()
 
for _ in range(n):
    a.append(int(input()))
 
b = sorted(a)

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

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

n = int(input())
a = [int(input()) for _ in range(n)]
a_max_1 = max(a)
b = sorted(a, reverse=True)
a_max_2 = b[1]

for i in range(n):
    if a[i] == a_max_1:
        print(a_max_2)
    else:
        print(a_max_1)

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

if b.count(m)>=2:
    for i in range(a):
        print (m)
else:
    c=b.copy()
    c.sort(reverse=True)
    m2=c[1]
    for i in range(a):
        if b[i]==m:
            print(m2)
        else:
            print (m)

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

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

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

ma = max(a)
max_i = a.index(ma)
b = []

for j in range(n):
    if j != max_i:
        b.append(a[j])

mb = max(b)

for i in range(n):
    if i != max_i:
        print(ma)
    else:
        print(mb)

Solution (Python):
def resolve():
    n = int(input())
    aaa = [int(input()) for _ in range(n)]
    sorta = sorted(aaa, reverse=True)
    maxa = sorta[0]
    seconda = sorta[1]
    for i in range(n):
        if maxa == aaa[i]:
            print(seconda)
        else:
            print(maxa)
resolve()

Solution (Python):
def main():

    N, *A = map(int, open(0).read().split())
    first, second = sorted(A, reverse=True)[:2]
    print("\n".join(map(str, (first if a != first else second for a in A))))
    return


main()

Solution (Python):
def main():

    N, *A = map(int, open(0).read().split())
    first, second = sorted(A, reverse=True)[:2]
    print("\n".join(map(str, [first if a != first else second for a in A])))
    return


main()

Solution (Python):
def main():

    *A, = map(int, open(0).read().split()[1:])
    first, second = sorted(A, reverse=True)[:2]
    print("\n".join(map(str, [first if a != first else second for a in A])))
    return


main()

Solution (Python):
def main():

    *A, = map(int, open(0).read().split()[1:])
    first, second = sorted(A, reverse=True)[:2]
    print("\n".join(map(str, (first if a != first else second for a in A))))
    return


main()

Solution (Python):
def main():

    *A, = map(int, open(0).read().split()[1:])
    first, second = sorted(A)[:-3:-1]
    print("\n".join(map(str, (first if a != first else second for a in A))))
    return


main()

Solution (Python):
def main():

    *A, = map(int, open(0).read().split()[1:])
    first, second = sorted(A)[:-3:-1]
    ans = [str(first) if a != first else str(second) for a in A]
    print("\n".join(ans))
    return


main()

Solution (Python):
def main():

    *A, = map(int, open(0).read().split()[1:])
    first, second = sorted(A)[:-3:-1]
    ans = (str(first) if a != first else str(second) for a in A)
    print("\n".join(ans))
    return


main()

Solution (Python):
def main():

    *A, = map(int, open(0).read().split()[1:])
    first, second = sorted(A)[:-3:-1]
    print("\n".join(str(first) if a != first else str(second) for a in A))
    return


main()

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

a_max = max(a_list)
a_max_list = [i for i, v in enumerate(a_list) if v == a_max]

if len(a_max_list) == 1:
  a_max_2 = sorted(set(a_list))[-2]
  for i in range(n):
    if i in a_max_list:
      print(a_max_2)
    else:
      print(a_max)
else:
  for i in range(n):
    print(a_max)

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

b = sorted(a)

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
A_max = max(A)
A_max2 = sorted(A)[-2]
for a in A:
    if a==A_max:
        print(A_max2)
    else:
        print(A_max)

Solution (Python):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = sorted(A)
MM = B[-1]
M2 = B[-2]
for i in A:
  if i == MM:
    print(M2)
  else:
    print(MM)

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

amax,b=max(a),a.index(max(a))
a.remove(amax)
bmax=max(a)
for i in range(n):
  if i==b:
    print(bmax)
  else:
    print(amax)

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

cA = list(Counter(A).items())

cA.sort(reverse=True)

for i in A:
  if i == cA[0][0] and cA[0][1] == 1:
    print(cA[1][0])
  else:
    print(cA[0][0])

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

Solution (Python):
n = int(input())
rank1 = 0
rank2 = 0
ax = []
for i in range(n) :
  a = int(input())
  if rank1 <= a : 
    rank2 = rank1 
    rank1 = a
  elif rank2 < a :
    rank2 = a
  ax.append(a)
    

for i in range(n) :
  if ax[i] == rank1 :
    print(rank2)
  else :
    print(rank1)

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

max1 = max(array)  
max1count = array.count(max1)

array2 = array[:]  
array2.remove(max1)
max2 = max(array2)

for e in array:
    if e != max1:
        print(max1)
    else:
        if 1 < max1count:
            print(max1)
        else:
            print(max2)

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

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

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

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

Solution (Python):
import copy
s=int(input())
list1=[input() for _ in range(s)]
list2=copy.copy(list1)
list2=sorted(list2,key=lambda x:-int(x))
for i in list1:
    if list2[0]==i:
      print(list2[1])
    else:
      print(list2[0])

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

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

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

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

left_i = [0] * N
right_i = [0] * N

for i in range(1, N):
    left_i[i] = max(left_i[i-1], A[i-1])
    right_i[i] = max(right_i[i-1], A[N-i])

for i in range(N):
    print(max(left_i[i], right_i[N-1-i]))

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

a = [0] * n

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

a_sorted = sorted(a, reverse=True)

ans = [0] * n
no1 = a_sorted[0]
no2 = a_sorted[1]

for i in range(n):
  if a[i] == no1:
    ans[i] = no2
  else:
    ans[i] = no1
  
for i in range(n):
  print(ans[i])

Solution (Python):
N=int(input())
A=[]
MAX=0
for _ in range(N):
    A.append(int(input()))
    if MAX<A[-1]:
        MAX=A[-1]
count=0
for i in range(N):
    if A[i]==MAX:
        count+=1
for j in range(N):
    if A[j]==MAX and count==1:
        A[j]=0
        print(max(A))
    else:
        print(MAX)

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

MAX_1 = max(A)
MAX_2 = sorted(A)[-2]

for i in range(N):
    if A[i] == MAX_1:
        print(MAX_2)
    else:
        print(MAX_1)

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

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

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

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

R = sorted(L)
a = R[-2]
b = R[-1]

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

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

Solution (Python):


n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)
if b[-1] == b[-2]:
  for i in range(n):
    print(b[-1])
else:
  p = a.index(b[-1])
  for i in range(n):
    if i == p:
      print(b[-2])
    else:
      print(b[-1])

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

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

mx = max(lst)
clst = sorted(lst)
mx2 = clst[-2]

for j in range(N):
    if mx != lst[j]:
        print(mx)
    else:
        print(mx2)

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

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

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

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
max1=0
max2=0
a=[int(input()) for i in range(n)]
for i in a:
    if i>=max1:
        max2=max1
        max1=i
    elif i>=max2:
        max2=i
if max2==0:
    for i in range(n):
        print(max1)
    exit()
for i in a:
    if i==max1:
        print(max2)
    else:
        print(max1)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
maxind = A.index(max(A))
maxa = max(A)
A = sorted(A)
ans = [maxa]*maxind
ans.append(A[-2])
[ans.append(i) for i in [maxa]*(N-maxind-1)]
print(*ans,sep="\n")

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

ans = max(lint)
index = lint.index(max(lint))
lint.remove(max(lint))
ans2 = max(lint)

if ans == ans2:
    for i in range(n):
        print(ans)
else:
    for i in range(0, index):
        print(ans)
    print(ans2)
    for i in range(index+1, n):
        print(ans)

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

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

Solution (Python):

import sys










def main():
    n, *a = [int(x) for x in sys.stdin.read().split()]
    b = a.copy()
    b.sort()
    largest = b[-1]
    second_largest = None
    if b[-2] == largest:
        pass
    else:
        second_largest = b[-2]
    
    if not second_largest:
        for i in range(n):
            print(largest)
    else:
        for i in range(n):
            if a[i] == largest:
                print(second_largest)
            else:
                print(largest)


if __name__ == "__main__":
    main()

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


def main():
    sc = Scan()
    n = sc.intarr()[0]
    array = []
    for i in range(n):
        array.append(sc.intarr()[0])
    sorted_array = sorted(array)
    maximum = sorted_array[-1]

    for i in array:
        if i == maximum:
            print(sorted_array[-2])
        else:
            print(maximum)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()

Solution (Python):
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
A = np.array([inp() for _ in range(n)])
mA = max(A)
smA = np.sort(A)[::-1][1]
for i in range(n):
    if A[i] == mA: print(smA)
    else: print(mA)

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

N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)
first = B[-1]
second = B[-2]

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

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

a.sort(reverse=True)

m_1=a[0]
m_2=a[1]
for i in range(n):
    if c[i]==m_1:
        print(m_2)
    else:
        print(m_1)