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 = []
first = 0
second = 0
for i in range(n):
    temp = int(input())
    a.append(temp)
    if i == 0:
        first = temp
    else:
        if temp >= first:
            second = first
            first = temp
        elif temp >= second:
            second = temp
for i in range(n):
    if a[i] == first:
        print(second)
    else:
        print(first)

Solution (Python):


N = int(input())

values = [0]*N
value_count_map = {}
for i in range(N):
    in_value = int(input())
    values[i] = in_value
    value_count = 0
    if in_value in value_count_map:
        value_count = value_count_map[in_value]
    value_count_map[in_value] = value_count + 1

sorted_values = sorted(value_count_map.keys(), reverse=True)
max_value = sorted_values[0]
max_value_count = value_count_map[max_value]
next_max_value = max_value
if len(sorted_values) > 1:
    next_max_value = sorted_values[1]

for row in range(N):
    if values[row] == max_value and max_value_count == 1:
        print(next_max_value)
    else:
        print(max_value)

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

num = a.index(max(a))
a_max = max(a)
a_second = sorted(a)[-2]
for i in range(n):
    if i == num:
        print(a_second)
    else:
        print(a_max)

Solution (Python):


N = int(input())

values = [0]*N
value_count_map = {}
for i in range(N):
    in_value = int(input())
    values[i] = in_value
    value_count = 0
    if in_value in value_count_map:
        value_count = value_count_map[in_value]
    value_count_map[in_value] = value_count + 1

max_value = max(value_count_map.keys())
value_count = value_count_map.pop(max_value)
if value_count == 1:
    next_max_value = max(value_count_map.keys())
for row in range(N):
    if value_count > 1:
        print(max_value)
    elif values[row] == max_value:
        print(next_max_value)
    else:
        print(max_value)

Solution (Python):
import copy
n=int(input())
list=[int(input()) for i in range(n)]
temp_list = copy.copy(list)
temp_list.sort(reverse=True)

max = 0
for c in list:
    if(c == temp_list[0]):
        print(temp_list[1])
    else:
        print(temp_list[0])

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

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
num = a.index(max(a))
a_max = max(a)
a_second = sorted(a)[-2]
for i in range(n):
    if i == num:
        print(a_second)
    else:
        print(a_max)

Solution (Python):
from collections import Counter

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

A_cp = A[:]
A_max1 = max(A_cp)
A_cp.remove(A_max1)
A_max2 = max(A_cp)

for i in A:
    print(A_max1 if i!=A_max1 else A_max2)

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

left = [0]
right = [0]


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



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





right.reverse()

for i in range(N):
    print(max(left[i], right[i+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:
    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 _ in range(N)]
A_s = sorted(A)[::-1]

for i in A:
    if (A_s[0] == i) & (A_s[1] == i):
        print(A_s[0])
    elif (A_s[0] == i) & (A_s[0] != A_s[1]):
        print(A_s[1])
    else:
        print(A_s[0])

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

Solution (Python):
N=int(input())
a=[0]*(N)
maxim=[0]*(N)
for i in range(N):
    a[i]=int(input())
maxim=sorted(list(a), reverse=True)
for k in range(N):
    if a[k]!=maxim[0]:
        print(maxim[0])
    else:
        print(maxim[1])

Solution (Python):


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

Solution (Python):
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
firstMax = max(a)
minVal = min(a)
secondMax = max(map(lambda x:x if x != firstMax else minVal, a)) if len(str(a).split(str(firstMax))) == 2 else firstMax
for i in range(len(a)):
    if a[i] < firstMax:
        print(firstMax)
    else:
        print(secondMax)

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

Solution (Python):
import sys

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
A = [read_int()[0] for _ in range(N)]

def solve() -> str:

    M = max(A)

    semi_M = 0
    num_of_M = 0
    for i in range(N):
        if A[i] == M:
            num_of_M += 1
        else:
            semi_M = max(semi_M, A[i])

    for i in range(N):
        if A[i] == M and num_of_M == 1:
            print(semi_M)
        else:
            print(M)
    return

if __name__ == "__main__":
    solve()

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

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

max1 = max(a)
location1 = a.index(max1)

a.remove(a[location1])
max2 = max(a)

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

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

max1 = list1.index(max(list1))
max2 = max(list1)
list2 = list1[:max1]+list1[max1+1:]
max3 = max(list2)

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

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

Amax = sorted(A,reverse=True)[0]
Anmax = sorted(A,reverse=True)[1]
for i in A:
  if i == Amax:
    print(Anmax)
  else:
    print(Amax)

Solution (Python):
n = int(input())
a_max = 0
data = [int(input()) for i in range(n)]
a_max = max(data)
flag = True if 2 <= data.count(a_max) else False
for i in range(n):
  if data[i] == a_max and not flag:
    tmp = data.pop(i)
    print(max(data))
    data.insert(tmp,0)
    
  else:
  	print(a_max)

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

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

sbmx, mx = sorted(a)[n-2:]
for m in a:
        if m==mx: print(sbmx)
        else: print(mx)

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

L = [0] * (N+1)
R = [0] * (N+2)

for i in range(1, N+1):
    L[i] = max(L[i-1], A[i-1])
    R[N-i+1] = max(R[N-i+2], A[N-i+2])

for i in range(1, N+1):
    print(max(L[i], R[i]))

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

B = A.copy()
B.sort(key=lambda x:-x)

last = B[0]
second = B[1]

for num in A:
  if num != last:
    print(last)
  else:
    print(second)

Solution (Python):
n = int(input())
list = [int(input()) for i in range(n)]
list2 = sorted(list)
m1 = list2[-1]
m2 = list2[-2]
 
for i in list:
    if i == m1:
        print(m2)
    else:
        print(m1)

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

A_max = max(A)
A_second = A_max

if A.count(A_max) == 1:
  AA = []
  for a in A:
    if a != A_max:
      AA.append(a)
  A_second = max(AA)

for i in range(len(A)):
  if A[i] == A_max:
    print(A_second)
  else:
    print(A_max)

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

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

B = sorted(A, reverse=True)
  
max_ = B[0]
max__ = B[1]

for i in range(N):
  if A[i] == max_:
    print(max__)
  else:
    print(max_)

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

Solution (Python):
n = int(input())
lis = [int(input()) for _ in range(n)]
lis2 = sorted(lis)
m1 = lis2[-1]
m2 = lis2[-2]

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

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

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

m = max(Alist)
for i in range(N):
    if Alist[i]==m:
        print(Alist_sorted[-2])
    else:
        print(m)

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    left = [A[0]] * N
    right = [A[-1]] * N

    for i in range(1,N):
        if(A[i] > left[i-1]):
            left[i] = A[i]
        else:
            left[i] = left[i-1]

    for i in reversed(range(0,N-1)):
        if(A[i] > right[i+1]):
            right[i] = A[i]
        else:
            right[i] = right[i+1]

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


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

import sys


def solve(N: int, A: "List[int]"):
    ml = A.copy()
    ml.sort(reverse=True)

    Am = ml[0]
    As = ml[1]

    for i in range(N):
        if(A[i] == Am):
            print(As)
        else:
            print(Am)
    

    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())
L = [ int(input()) for _ in range(N)]
L2 = sorted(enumerate(L),key=lambda i:i[1])
for i in range(N):
  if i == L2[-1][0]:
    print(L2[-2][1])
  else:
    print(L2[-1][1])

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

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

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

b = a.copy()
b.sort()
for number in a:
    if b[-1] != number:
        print(b[-1])
    else:
        print(b[-2])

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

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

a_sort = sorted(a, reverse=True)

for ele in a:
    if ele==a_sort[0]:
        print(a_sort[1])
    else:
        print(a_sort[0])

Solution (Python):
num = int(input())
a_list = []
for i in range(num):
    a_list.append(int(input()))
M = max(a_list)
M_num = a_list.index(M)
a_list.pop(M_num)
for i in range(num):
    if i != M_num:
        print(M)
    else:
        print(max(a_list))

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

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

max = max(tmp)

unk = sorted(tmp, reverse=True)
unk2 = unk[1]

counter = 0
for i in tmp:
    if i == max:
        counter += 1

if counter > 1:
    for i in range(n):
        print(max)
else:
    for i in tmp:
        if i == max:
            print(unk2)
        else:
            print(max)

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

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

A=[]
_max = 0
_max2 = 0
N=int(input())
for i in range(N):
    a=int(input())
    A.append(a)
    if _max<a:
        _max2=_max
        _max=a
    elif _max2<a:
        _max2=a

for a in A:
    print(_max if _max!=a else _max2)

Solution (Python):
A=[]
_max = 0
_max2 = 0
N=int(input())
for i in range(N):
    A.append(int(input()))
    if _max<A[-1]:
        _max2,_max=_max,A[i]
    elif _max2<A[-1]:
        _max2=A[i]
    

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

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

maxA1 = 0
maxi = 0
maxA2 = 0
for i in range(N):
    a = int(input())
    if maxA1<a:
        maxA2 = maxA1
        maxA1 = a
        maxi = i
    elif maxA2<a:
        maxA2 = a

for i in range(N):
    if i == maxi:
        print(maxA2)
    else:
        print(maxA1)

Solution (Python):
A=[]
_max = 0
_max2 = 0
N=int(input())
for i in range(N):
    A.append(int(input()))
    _,_max2,_max=sorted([A[-1],_max2,_max])

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

Solution (Python):


A=[]
B = []
max = 0
max2 = 0
count = 0
N=int(input())
for i in range(N):
    A.append(int(input()))
for i in range(len(A)):
    if A[i] > max:
        max = A[i]
        B.append(A[i])
for i in range(len(A)):
    if A[i] == max:
        count +=1

    
for i in range(len(A)):
    if count >= 2:
        print(max)
    if count == 1:
        if A[i] > max2 and A[i] != max:
            max2 = A[i]
for i in range(len(A)):
    if count ==1:
        if A[i] == max:
            print(max2)
        else:
            print(max)

Solution (Python):

n = int(input())

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

max_value = max(numbers)

count_max = numbers.count(max_value)
index_max = numbers.index(max_value)

numbers_second = numbers
del numbers_second[index_max]
second_max_value = max(numbers_second)

if count_max >= 2:
    for i in range(n):
        print(max_value)

else:
    for i in range(n):
        if i == index_max:
            print(second_max_value)
        else:
            print(max_value)

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

sorted_a = sorted(a)
first_a = sorted_a[-1]
second_a = sorted_a[-2]

for i in range(len(a)):
    if a[i] == first_a:
        print(second_a)
    else:
        print(first_a)

Solution (Python):
n = int(input())
s = [int(input()) for _ in range(n)]
max1 = max(s)
max2 = sorted(s)[-2]
max1_index = s.index(max1)
for i in range(n):
  if(max1_index == i):
    print(max2)
  else:
    print(max1)

Solution (Python):
n=int(input())
l=[]
for i in range(n):
  l.append(int(input()))
m=max(l)
a=l.index(m)
for i in range(n):
  if i==a:
    l[i]=0
    print(max(l)) 
  else:print(m)

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

A = [int(input()) for _ in range(N)]
A_sort = sorted(A, reverse=True)

A_max = A_sort[0]
A_max_ = A_sort[1]

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

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

Solution (Python):
N = int(input())
As = [int(input()) for _ in range(N)]
As2 = sorted(As)
m1 = As2[-1]
m2 = As2[-2]
for a in As:
    if a == m1:
        print(m2)
    else:
        print(m1)

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

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

for a in A:
    if a == sa[0]:
        print(sa[1])
    else:
        print(sa[0])

Solution (Python):
import numpy as np

S = input()
N = int(S)

A = np.zeros([N])
A_temp = np.zeros([N])

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

max = 0

index_max = np.argmax(A)
A_temp = np.copy(A)
A_temp[index_max] = 0
index_max_second = np.argmax(A_temp)

result = np.full(N, A[index_max])
result[index_max] = A[index_max_second]

for i in range(0, N, 1):
    print(int(result[i]))

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[0])
    else:
        print(B[1])

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

A.sort()
d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

ans1 = A[-1]
if d[ans1] >= 2:
    ans2 = A[-1]
else:
    ans2 = A[-2]

for b in B:
    if b == ans1:
        print(ans2)
    else:
        print(ans1)

Solution (Python):
import copy
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for i in range(N)]
copy_A = copy.copy(A)
copy_A.sort(reverse=True)
max_a, sec_a = copy_A[0], copy_A[1]
for i in range(N):
  if A[i] == max_a:
    print(sec_a)
  else:
    print(max_a)

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

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

        print(x[n-2])

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

a_sort=sorted(a,reverse=True)

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

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

L = [1]
for n in range(N-1):
    L.append(max(L[-1], A[n]))

R = [1]
A.reverse()
for n in range(N-1):
    R.append(max(R[-1], A[n]))
R.reverse()

for i in range(N):
    print(max(L[i], R[i]))

Solution (Python):
n=int(input())
a=[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):
if __name__ == '__main__':
    N = int(input())
    A = [int(input()) for _ in range(N)]

    sorted_A = sorted(A)

    max_A = sorted_A[-1::][0]
    next_max_A = sorted_A[-2:-1:][0]

    for i in range(N):
        if A[i] == max_A:
            print(next_max_A)
        else:
            print(max_A)

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

max_num = max(s)
max_ind = s.index(max_num)
s.remove(max_num)
max2_num = max(s)
 
for i in range(N):
    if i == max_ind:
        print(max2_num)
    else:
        print(max_num)

Solution (Python):
n = int(input())
li = [int(input()) for _ in range(n)]
maximam = 0
second_maximam = 0

for i in li:
    if i >= maximam:
        second_maximam = maximam
        maximam = i
    elif i >= second_maximam:
        second_maximam = i

for i in li:
    if i == maximam:
        print(second_maximam)
    else:
        print(maximam)

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

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

comp = data.copy()
data.sort()


for _ in comp:
    if _ == data[-1]:
        print(data[-2])
    else:
        print(data[-1])

Solution (Python):
N=int(input())
lis=[]
for i in range(N):  
  lis.append(int(input()))
lis2=sorted(lis)
ma1=lis2[-1]
ma2=lis2[-2]

for i in range(N):
  if lis[i] == ma1:
    print(ma2)
  else:
    print(ma1)

Solution (Python):
num = int(input())
hako = [int(input()) for _ in range(num)]
hako_mirror = hako.copy()
hako_mirror.sort(reverse=True)
for h in hako:
  if h == hako_mirror[0]:
    print(hako_mirror[1])
  else:
    print(hako_mirror[0])

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

a_sort = sorted(set(a))

max_val_1 = a_sort[-1]
max_total_1 = a.count(max_val_1)

if len(a_sort) >= 2:
    max_val_2 = a_sort[-2]




for i in range(n):
    if max_total_1 >=2:
        print(max_val_1)
    
    elif a[i] < max_val_1:
        print(max_val_1)

    elif a[i] == max_val_1 and max_total_1 == 1:
        print(max_val_2)
    else:
        print("err")

Solution (Python):
n = int(input())
numlist = []
for i in range(n):
    numlist.append(int(input()))
argmax = numlist.index(max(numlist))
maxnum = max(numlist)
del numlist[argmax]
secondnum = max(numlist)
                       
for i in range(argmax):
    print (maxnum)
print (secondnum)
for i in range(argmax+1,n):
    print (maxnum)

Solution (Python):
N=int(input())
maxi=0
maxinum=0
submaxi=0
for n in range(N):
    tmp=int(input())
    if tmp>maxi:
        submaxi=maxi
        maxi=tmp
        maxinum=n
    elif tmp>submaxi:
        submaxi=tmp
for n in range(N):
    if n==maxinum:
        print(submaxi)
    else:
        print(maxi)

Solution (Python):
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
m=max(a)
ind=a.index(m)
m2=-1e10
for i in range(n):
    if i!=ind:
        m2=max(m2,a[i])
for i in range(n):
    if i==ind:
        print(m2)
    else:
        print(m)

Solution (Python):
n = int(input())
a = [0]*n
max1=0
max2=0

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

Solution (Python):



import itertools as ite
import math
import random
import sys
import codecs
from collections import defaultdict

INF = 10 ** 18
MOD = 10 ** 9 + 7

sys.setrecursionlimit(1000000)

N = input()
A = [input() 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 max(A[:i] + A[i + 1:])
        else:
            print maxA

Solution (Python):
import numpy as np

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

_a = np.array(a)
max_index = np.argmax(_a)
max_val_1 = np.max(_a)
_a[max_index] = 0
max_val_2 = np.max(_a)

for i in range(n):

    if max_val_1 == max_val_2:
        print(max_val_1)
        
    elif max_val_1 != max_val_2 and a[i] == max_val_1:
        print(max_val_2)
    
    else:
        print(max_val_1)

Solution (Python):

N = int(input())

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

A_max = sorted(A)[-1]

A_2ndmax = sorted(A)[-2]


for i in range(N):
    
    if A[i] == A_max:
        print("{}".format(A_2ndmax))
    
    else:
        print("{}".format(A_max))

Solution (Python):
A=[int(input()) for i in range(int(input()))]
sorted_A=sorted(A)[::-1]
for i in A:
    if i==sorted_A[0]:
        print(sorted_A[1])
    else:
        print(sorted_A[0])

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

a_sort = sorted(set(a))

max_val_1 = a_sort[-1]
max_total_1 = a.count(max_val_1)

if len(a_sort) >= 2:
    max_val_2 = a_sort[-2]




for i in range(n):
    if max_total_1 >=2:
        print(max_val_1)
    
    elif a[i] < max_val_1:
        print(max_val_1)

    elif a[i] == max_val_1 and max_total_1 == 1:
        print(max_val_2)
    else:
        print("err")

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


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


new_list = sorted(list,reverse=True)


for c in range(n):
    if new_list[0] == list[c]:
        print(new_list[1])
    else:
        print(new_list[0])

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

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

max_val = max(a)
max_total = a.count(max_val) - 1

for i in range(n):
    if max_val > a[i]:
        print(max_val)

    elif max_val == a[i] and max_total != 0:
        print(max_val)
        max_total -= 1
    else:
        temp = a[i]
        a[i] = 0
        print(max(a))
        a[i] = temp

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
A_Index = sorted(range(len(A)), key = lambda k: A[k])
A = sorted(A)

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

Solution (Python):
n = int(input())
a = [int(input()) for x in range(n)]
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):
n=int(input())
a=[int(input()) for i in range(n)]
max1=sorted(a)[-1]
if n==2:
    print(a[1])
    print(a[0])
elif sorted(a)[-2]!=max1:
    max=sorted(a)
    max2=0
    for i in range(2,n):
        if max[-i]!=max1:
            max2=max[-i]
            break
    for i in range(n):
        if a[i]==max1:
            print(max2)
        else:
            print(max1)
else:
    for i in range(n):
        print(max1)

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

max = max(A)
max_idx = A.index(max)

[print(max) for _ in range(max_idx)]
print(sorted(A)[-2])
max_idx += 1
[print(max) for _ in range(max_idx, N)]

Solution (Python):

import copy

n=int(raw_input())
a=[]
for i in xrange(n):
 a.append(int(raw_input()))
num1=sorted(a)[-1]
num2=sorted(a)[-2]
if a.count(num1)>1:
 for i in xrange(n):
  print num1
else:
 for i in xrange(n):
  if a[i]==num1:
   print num2
  else:
   print num1

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
max_A = max(A)
B = set(A)
if len(B) == 1 or A.count(max_A) >= 2:
    for i in range(N):
        print(max_A)
else:
    C = list(A)
    for i in range(N):
        if A[i] == max_A:
            C.remove(max_A)
            print(max(C))
        else:
            print(max_A)

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

b = sorted(a, reverse = True)

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

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

A_s = sorted(A, reverse=True)
top1 = A_s[0]
top2 = A_s[1]

for i in A:
    if i == top1:
        print(top2)
    else:
        print(top1)

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

Solution (Python):
n=int(input())
i=0
b=[]
pos=0
maxi=0
while(i<n):
  k=int(input())
  b.append(k)
  if(k>maxi):
    pos=i
    maxi=k
  i+=1
b.sort()
ns=b[n-2]
i=0
while(i<n):
  if(i==pos):
  	print(ns)
  else:
    print(b[n-1])
  i+=1

Solution (Python):
def solve(n, a):
    l = [0] * n
    r = [0] * n
    v = 0
    for i in range(n):
        l[i] = v
        v = max(v, a[i])
    v = 0
    for i in range(n-1, -1, -1):
        r[i] = v
        v = max(v, a[i])
    for i in range(n):
        print(max(l[i], r[i]))

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

Solution (Python):
n=int(input())
num_list=[]
top1=0
top2=0
for i in range(n):
    num_list.append(int(input()))
    if top1<num_list[i]:
        top1=num_list[i]
    elif top2<num_list[i]:
        top2=num_list[i]
for j in range(n):
    if num_list[j]==top1:
        print(top2)
    else:
        print(top1)

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

No1 = 0
No2 = 0
for i in range(N):
    if A[i] > No1:
        No2 = No1
        No1 = A[i]
    elif A[i] > No2:
        No2 = A[i]

for i in range(N):
    if A[i] == No1:
        print(No2)
    else:
        print(No1)

Solution (Python):
n=int(input())
L=[]
for i in range(n):
    L.append(int(input()))
    
L_sort=sorted(L)
L_sort.reverse()
m_1=L_sort[0]
m_2=L_sort[1]

if m_1==m_2:
    for i in range(n):
        print(m_1)
else:
    for i in range(n):
        if L[i]==m_1:
            print(m_2)
        else:
            print(m_1)

Solution (Python):




import math
import statistics


def qsort(seq):
	if len(seq) < 1:
		return seq
	pivot = seq[0]
	left = []
	right = []
	for x in range(1, len(seq)):
		if seq[x] <= pivot:
			left.append(seq[x])
		else:
			right.append(seq[x])
	left = qsort(left)
	right = qsort(right)
	foo = [pivot]
	return (left + foo + right)


n = int(input())


a = []

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

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

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

m = max(a)
s = sorted(a)

for i in range(n):
  if m is a[i]:
    print(s[-2])
  else:
    print(m)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input().strip())
an = [int(input().strip()) for i in range(n)]
san = sorted(an)
m_a = san[-1]
m_b = san[-2]

for i in range(n):
  if an[i] == m_a:
    print(m_b)
  else:
    print(m_a)

Solution (Python):
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    N = int_raw()
    As = [int_raw() for _ in range(N)]
    As2 = sorted(As)
    m1 = As2[-1]
    m2 = As2[-2]
    for a in As:
        if a ==m1:
            print(m2)
        else:
            print (m1)

main()

Solution (Python):
n=int(input())
a = [int(input()) for _ in range(n)]
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):
n=int(input())
a = [int(input()) for _ in range(n)]
b=sorted(a)
for i in range(n):
    if a[i]==b[n-1]:
        print (b[n-2])
    else:
        print(b[n-1])