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



Sample input:
3
1
4
3


Sample output:
4
3
4

Submission status: Accepted

Solution code:
import numpy as np

def main():
    n = int(input())
    a = np.zeros([n], dtype=int)
    for i in range(n):
        a[i] = int(input())

    ma = np.argmax(a)
    sec = 0
    for i in range(n):
        if i == ma:
            continue
        if a[i] > sec:
            sec = a[i]
    for i in range(n):
        if a[i] < a[ma]:
            print(a[ma])
        else:
            print(sec)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import sqrt

def solve0(N, A):
    S = sorted(A)
    S0 = S[-1]
    S1 = S[-2]

    for a in A:
        if a == S0:
            print(S1)
        else:
            print(S0)

def solve(N, A):
    D = int(sqrt(N))
    M = []
    for i in range(0, N, D):
        M.append(max(A[i:i+D]))
    M.append(0)
    for i in range(0, N):
        d = i // D
        l = d*D
        m = 0
        for j in range(l, min(l+D, N)):
            if i != j and A[j] > m:
                m = A[j]
        m0 = m
        if d == 0:
            m = max(m, max(M[d+1:]))
        elif d >= len(M) - 1:
            m = max(m, max(M[:d]))
            pass
        else:
            #print(d, len(M))
            #print("M[:d]", M[:d])
            #print("M[d+1:]", M[d+1:])
            m = max(m, max(M[:d]), max(M[d+1:]))
        print(m)
        #print("d=%d,"%d, m, max(A[:i]+A[i+1:]))
        #assert m == max(A[:i]+A[i+1:])


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

#l = list(range(1, 200))
#solve(len(l), l)
main()

Submission status: Accepted

Solution code:
n=int(input())
t,s=0,0
a=[]
for i in range(n):
    _a=int(input())
    a.append(_a)
    if _a>t:
        t=_a
    elif _a==t or _a>s:
        s=_a
for _a in a:
    if _a==t:
        print(s)
    else:
        print(t)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
A = []
for i in range(N):
    Ai = int(input())
    A.append(Ai)

B = sorted(A, reverse=True)
maxnum1 = B[0]
maxnum2 = B[1]

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
list_a = [int(input()) for _ in range(N)]
list_np = np.array(list_a)
maxnum=list_np.max()
index_list = np.where(list_np == maxnum)[0]
if len(index_list) == 1:
  list_drop = [i for i in list_a if i != maxnum]
  a=[]
  for i in range(N):
    if i in index_list:
      a.append(max(list_drop))
    else:
      a.append(maxnum)
else:
  a = [maxnum for i in range(N)]
for i in range(N):
  print(a[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import copy

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

Amax = max(A)
TMP = copy.deepcopy(A)
TMP.remove(Amax)
Amax2 = max(TMP)

for i in range(N):
        if A[i] == Amax:
                print(Amax2)
        else:
                print(Amax)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    a_list = []
    max_num = 0
    second_max = 0
    max_count = 0
    for i in range(n):
        a = int(input())
        a_list.append(a)
        if a > max_num:
            max_num = a
            max_count = 1
        elif a > second_max:
            second_max = a

    for i in range(n):
        if a_list[i] != max_num:
            print(max_num)
        else:
            print(second_max)

Submission status: Accepted

Solution code:
N = int(input())
A = []  # (index, Ai)
m = 0
m2 = 0
for i in range(N):
    a = int(input())
    A.append(a)
    if a > m:
        m2 = m
        m = a
    elif m >= a and a >= m2:
        m2 = a

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

Submission status: Accepted

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

sorted_a_lst = sorted(a_lst)
max_a = sorted_a_lst[-1]

for a in a_lst:
    if a == max_a:
        print(sorted_a_lst[-2])
    else:
        print(max_a)

Submission status: Accepted

Solution code:
N=int(input())
ind=[0]
maxA=0
A=[]
for i in range(N):
    a=int(input())
    if a>maxA:
        ind=[i]
        maxA=a
    elif a==maxA:
        ind.append(i)
    A.append(a)

if len(ind)>1:
    for _ in A:
        print(maxA)
else:
    tmp=A.copy()
    tmp.sort(reverse=True)
    for t in tmp:
        if t!=maxA:
            secondA=t
            break
    for a in A:
        if a==maxA:
            print(secondA)
        else:
            print(maxA)

Submission status: Accepted

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

mx = max(a)
count = a.count(mx)

mx2 = -1
for i in a:
  if(mx2 < i and i != mx):
    mx2 = i

if(mx2 == -1):
  mx2 = mx
  
for i in a:
  if(i!=mx):
    print(mx)
  else:
    if(count>1):
      print(mx)
    else:
      print(mx2)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
m=max(a)
midx=a.index(max(a))
l=sorted(a)[-2]
for i in range(n):
    if i==midx:
        print(l)
    else:
        print(m)

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
A = []#value
for i in range(N):
    A.append(int(input()))
B = A[:]
B.sort()
one = B[-1]
two = B[-2]
for i in range(N):
    if A[i] == one:
        print(two)
    else:
        print(one)

Submission status: Accepted

Solution code:
import bisect

N = int(input())
aList = [0] * N
for i in range(N):
    aList[i] = int(input())

maxTmp = max(aList)
tmpList = sorted(aList, reverse=True)
max2Tmp = tmpList[1]
maxCnt = aList.count(maxTmp)
ansList = [0] * N

for i in range(N):
    if aList[i] == maxTmp:
        if maxCnt > 1:
            for j in range(N):
                ansList[j] = maxTmp
            break
        else:
            ansList[i] = max2Tmp

    else:
        ansList[i] = maxTmp

for i in ansList:
    print(i)

Submission status: Accepted

Solution code:
#A
#n = int(input())
#print(3*n**2)
#B
#n, d = map(int, input().split())
#canseerange = 2*d+1
#if n % canseerange == 0:
#    print(int(n/canseerange))
#else:
#    print(int(n/canseerange)+1
#C
n = int(input())
ans = 0
most1 = 0
most2 = 0
ed = False
for i in range(n):
    t = int(input())
    ed = False
    if most1 <= t:
        most2 = most1
        most1 = t
        ans = i
        ed = True
    elif most2 <= t and ed == False:
        most2 = t
for i in range(n):
    if i==ans:print(most2)
    else:print(most1)

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline())
a = [int(input()) for x in range(n)]
sort_a = sorted(a, reverse=True)

for i, ai in enumerate(a):
    max = sort_a[0]
    if max == ai:
        max = sort_a[1]

    print(max)

Submission status: Accepted

Solution code:
import copy

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

ans = [max(lst)] * n

if lst.count(max(lst)) == 1:
    tmp = copy.deepcopy(lst)
    tmp.pop(lst.index(max(lst)))
    ans[lst.index(max(lst))] = max(tmp)

for l in ans:
    print(l)

Submission status: Accepted

Solution code:
import copy

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

A_sorted = sorted(A, reverse=True)

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

Submission status: Accepted

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

m1, m2, *_ = sorted(A, reverse=True)
for i in range(N):
    if A[i] == m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
N=int(input())
A=[]
tmp=-1
ltor=[]
rtol=[]
for i in range(N):
    A.append(int(input()))
    tmp=max(tmp,A[i])
    ltor.append(tmp)
ltor=[0]+ltor
ltor.append(0)

tmp=-1
for i in range(N):
    tmp=max(tmp,A[N-1-i])
    rtol.append(tmp)
rtol=[0]+rtol
rtol.append(0)
rtol.reverse()

for i in range(1,N+1):
    print(max(ltor[i-1],rtol[i+1]))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = np.array(A)
all_max = np.max(A)
max_ind = np.argmax(A)
max_remove = np.ones(N, dtype=bool)
max_remove[max_ind] = False
second_max = np.max(A[max_remove])
# print(all_max)
# print(second_max)
for n in range(N):
    if n == max_ind:
        print(second_max)
    else:
        print(all_max)

Submission status: Accepted

Solution code:
import collections

n = int(input())

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

b=sorted(a,reverse=True)
c=collections.Counter(a)
if c[b[0]] > 1:
	for i in range(n):
		print(b[0])
else:
	for i in range(n):
		if a[i] == b[0]:
			print(b[1])
		else:
			print(b[0])

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
aa = sorted(a)
p = aa[-1]
q = aa[-2]
for e in a:
    if e == p:
        print(q)
    else:
        print(p)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
Max = max(A)
Index = [i for i, x in enumerate(A) if x == Max]
if len(Index) != 1:
    for i in range(N):
        print(Max)
else:
    Copy = A[:]
    Copy[Index[0]] = 0
    Ans = [Max for i in range(N)]
    Ans[Index[0]] = max(Copy)
    for i in range(N):
        print(Ans[i])

Submission status: Accepted

Solution code:
import math

def main():
    N = int(input())
    A = []
    ma1 = 0
    ma2 = 0
    for i in range(N):
        a = int(input())
        A.append(a)
        if i == 1:
            if a >= A[0]:
                ma2 = 0
            else:
                ma2 = 1 
        if A[ma2] <=  a:
            if A[ma1] <= a:
                ma2 = ma1
                ma1 = i
            else:
                ma2 = i
    # print(ma, ma2)
    for i in range(N):
        if ma1 == i:
            print(A[ma2])
        else:
            print(A[ma1])
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
l  = []

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

l_max = max(l)
max_index = l.index(max(l))

for i in range(N):
	if i == max_index:
		b = l.pop(i)
		print(max(l))
	else:
		print(l_max)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
sortA = sorted(A, reverse=True)
maxA = sortA[0]
secondA = sortA[1]
for i in range(N):
    if A[i] != maxA:
        print(maxA)
    else:
        print(secondA)

Submission status: Accepted

Solution code:
N = int(input())
Maxi = [0] * N
Ai = []
for i in range(N):
	Ai.append((i, int(input())))

Ai.sort(key = lambda t: t[1], reverse=True)

mi,max = Ai[0]

for i in range(N):
	Maxi[i] = max

Maxi[mi] = Ai[1][1]

for i in range(N):
	print(Maxi[i])

Submission status: Accepted

Solution code:
n=int(input())
a=[]
a1=0
a2=0
for i in range(n):
    k=int(input())
    a.append(k)
    if a1<k:
        a2=a1
        a1=k
    elif a2<k:
        a2=k

for i in range(n):
    if a[i]==a1:
        print(a2)
    else:
        print(a1)

Submission status: Accepted

Solution code:
N = int(input())
numbers = []
for i in range(N):
    numbers.append(int(input()))
    
    
aaa = max(numbers)
bbb = sorted(numbers)[-2]

for n in numbers:
    if aaa == n:
        print(bbb)
    else:
        print(aaa)

Submission status: Accepted

Solution code:
first = 1
second = 1
n=int(input())
x = []
for i in range(0,n):
    s = int(input())
    if first <= s:
        second = first
        first = s
    elif second <= s:
        second = s
    x.append(s)

for i in range(0,n):
    if x[i] == first:
        print(second)
    else:
        print(first)

Submission status: Accepted

Solution code:
import sys

#+++++
		
def main():
	n = int(input())
	ll=[int(input()) for _ in range(n)]
	
	mm = sorted(ll)
	#print(ll)
	ma=mm[-1]
	mb=mm[-2]
	
	for i in ll:
		pp = ma if i != ma else mb
		print(pp)
		
	
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

one, two = sorted(A, reverse=True)[:2]

for i in A:
    print(two if one == i else one)

Submission status: Accepted

Solution code:

N = int(input())
A_lst = []
max_num = -1
max_index_lst = []
next_num = -1

for i in range(N):
    Ai = int(input())
    A_lst.append(Ai)
    if max_num == -1:
        max_num = Ai
        max_index_lst.append(i)
    elif next_num == -1:
        if max_num > Ai:
            next_num = Ai
        else:
            if max_num == Ai:
                max_index_lst.append(i)
            else:
                max_index_lst = [i]
            next_num = max_num
            max_num = Ai


    elif max_num <= Ai:
        if max_num == Ai:
            max_index_lst.append(i)
        else:
            max_index_lst = [i]
        next_num = max_num
        max_num = Ai

    
    elif next_num < Ai:
        next_num = Ai
#print()
ans_lst = [max_num]*N

if len(max_index_lst) == 1:
    ans_lst[max_index_lst[0]] = next_num

for i in ans_lst:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
b, c = sorted(a)[-2:]
j = a.index(c)
for i in range(n):
    print((c, b)[i == j])

Submission status: Accepted

Solution code:
N = int(input())
a = [int(input()) for i in range(N)]
b = []
for i in range(N):
    b.append([a[i], i])
b.sort(key=lambda x: x[0])

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

Submission status: Accepted

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

li2 = sorted(li)
max1 = li2[-1]
max2 = li2[-2]
max_index = li.index(max1)

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for n in range(N)]
 
max_A = max(A)
max_index = A.index(max(A))

A[max_index] = 0
max_A2 = max(A)
A[max_index] = max_A

for n in range(N):
  if A[n] != max_A:
    print(max_A)
  else:
    print(max_A2)

Submission status: Accepted

Solution code:
num = int(input())

ans = 0
next_ans = 0
count = 0
index = 0

for i in range(num):
  s = int(input())
  if s > ans:
    next_ans = ans
    ans = s
    index = i
    count = 1
  elif s == ans:
    count += 1
  elif s > next_ans:
    next_ans = s
    
if count > 1:
  for i in range(num):
    print(ans)
else:
  for i in range(num):
    if i == index:
      print(next_ans)
    else:
      print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

def main():
    # # 整数の入力
    # a = int(input())
    # # スペース区切りの整数の入力
    # b, c = map(int, input().split())
    # # 文字列の入力
    # s = input()
    # # 出力
    # print("{} {}".format(a+b+c, s))
    N = int(input())
    A_list = [int(input()) for i in range(N)]
    A_argsorted = np.argsort(A_list)[::-1]
    for i in range(N):
        max_value = A_list[A_argsorted[0]] if i != A_argsorted[0] else A_list[A_argsorted[1]]
        print(max_value)

    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for i in range(n)] 
m=a[0]
k=0

for i in range(n):
    if m<a[i]:
        m=a[i]
        k=i

for j in range(n):
    if j==k:
        print(sorted(a)[-2])
    else:
        print(m)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N = int(input())
A = []
for i in range(N):
    a = [i , int(input())]
    A.append(a)
    
A.sort(key = lambda x : x[1])

ans = [0]*N

for i in A:
    index = i[0]
    if i[1] == A[-1][1]:
        ans[index] = A[-2][1]
    else:
        ans[index] = A[-1][1]

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import copy
s=[]
i=0
n=int(input())
while i!=n:
    s.append(int(input()))
    i+=1
maxx=max(s)
g=s.count(maxx)
i=0
j=0

#print(g)
while i!=n:
    a = s[j]
    if maxx == a and g < 2:
        a=s[j]
        del s[j]
        print(max(s))
        s.append(a)
    else:
        print(maxx)
        j+=1

    i+=1

Submission status: Accepted

Solution code:
n = int(input())

max1 = 0
max2 = 0

tmp = 0

for i in range(n):
    A = int(input())
    if A > max1 :
        max1 = A
        tmp = i
    elif A > max2:
        max2 = A

for i in range(tmp):
    print(max1)

print(max2)

for i in range(n-tmp-1):
    print(max1)

Submission status: Accepted

Solution code:
num = []
aaa = []
nmax = 0
n2max = 0
count = 0
n = int(input())
for i in range(n):
    a = int(input())
    aaa.append(a)
    if(nmax < a):
        n2max = nmax
        nmax = a
        count = 1
        num = [i]
    elif(nmax == a):
        count += 1
        num.append(i)
    elif(n2max < a):
        n2max = a
for i in range(len(aaa)):
    if(count >= 2) or (nmax != aaa[i]):
        print(nmax)
    else:
        print(n2max)

Submission status: Accepted

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

max_i=a.index(max(a))
max_n=max(a)
a.pop(max_i)
semi_n=max(a)

for j in range(n):
  if j != max_i:
    print(max_n)
  else:
    print(semi_n)

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
m1, m2 = -1, -1
for e in a:
  if e > m1:
    m2 = m1
    m1 = e
  elif e > m2:
    m2 = e
for e in a:
  if e == m1:
    print(m2)
  else:
    print(m1)

Submission status: Accepted

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

sorted_list = sorted(arr)
max = sorted_list[N-1]
sub_max = sorted_list[N-2]
max_count = arr.count(max)

if max_count == 1:
    max_index = arr.index(max)
    for i in range(N):
        if i == max_index:
            print(sub_max)
        else:
            print(max)
else:
    for _ in range(N):
        print(max)

Submission status: Accepted

Solution code:
N = int(input())
a_list = [None] * N
for i in range(N):
    a_list[i] = int(input())

#remove duplicate
sorted_a = sorted(a_list, reverse = True)
max_a = sorted_a[0]

result = []
for a in a_list:
    if a == max_a:
        print(sorted_a[1])
    else:
        print(max_a)

Submission status: Accepted

Solution code:
import copy

n = int(input())

a = [0] * n

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

a_sort = sorted(a, reverse=True)

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

Submission status: Accepted

Solution code:
# ' 'dで区切ってprintする方法
# print(*a, sep=' ')

import math

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

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

max_a = max(a)

if a.count(max_a) == 1:
    b = a.copy()
    b.remove(max_a)
    second_max = max(b)
    for aa in a:

        if aa == max_a:
            print(second_max)
        else:
            print(max_a)
else:
    for i in range(n):
        print(max_a)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import numpy as np


def solv(a):
    idx = np.argsort(a)
    top_index = idx[-1]
    top = a[top_index]
    second = a[idx[-2]]
    for i in range(n):
        if i != top_index:
            print(top)
        else:
            print(second)


if __name__ == '__main__':

    n = int(input())
    a = np.empty(n, dtype=np.int)

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

    solv(a)

Submission status: Accepted

Solution code:
import sys

N=int(sys.stdin.readline().rstrip())
AList=[]
for i in range(N):
  AList.append(int(sys.stdin.readline().rstrip()))
  
Alistsort=sorted(AList,reverse=True)
last=Alistsort[0]
semiLast=Alistsort[1]

for a in AList:
  if a == last:
    print(semiLast)
  else:
    print(last)

Submission status: Accepted

Solution code:
N = int(input()) #1行目のNを取得する
s = [int(input()) for i in range(N)] #複数行の数値の入力を取得
max = max(s)

p = sorted(s)
next = p[-2]

ind = s.index(max)

for j in range(len(s)):
    if j==ind:
        print(next)
    else:
        print(max)

Submission status: Accepted

Solution code:
n = int(input())

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

S = sorted(A)

m1 = max(A)
m2 = S[-2]

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

Submission status: Accepted

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

idx = num.index(max(num))
max_a = max(num)

num_c = num
num_c[idx] = 0
idx_2 = num_c.index(max(num_c))
max_a2 = max(num_c)

for i in range(n):
    if i == idx:
        print(max_a2)
    else:
        print(max_a)

Submission status: Accepted

Solution code:
import copy
N = int(input())
a = [input() for i in range(N)]
a = list(map(int, a))
max_a = sub_max_a = max(a)
count = 0
for i in range(N):
    if max_a == a[i]:
        count += 1
        max_i = i
if count == 1:
    a.pop(max_i)
    sub_max_a = max(a)

for j in range(N):
    if max_i == j:
        print(sub_max_a)
    else:
        print(max_a)

Submission status: Accepted

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

max_ = -1
max_2 = -1
for i in range(n):
    if i == 0:
        tmp = a[i]
        a[i] = 0
        max_ = max(a)
        print(max_)
        a[i] = tmp
        if a[0]>=max_:
            max_ = a[0]
        continue
    else:
        if max_<=a[i]:
            if max_2 == -1:
                tmp = a[i]
                a[i] = 0
                max_2 = max(a)
                print(max_2)
                a[i] = tmp
            else:
                print(max_2)
        else:
            print(max_)

Submission status: Accepted

Solution code:
N = int(input())

A = []
max1 = 0
max1i = 0
max2 = 0
max2i = 0

for i in range(N):
  B = int(input())
  if B>max1:
    max1i = i
    max1 = B
  else:
    if B>max2:
      max2 = B
      max2i = i

for i in range(N):
  A.append(max1)
A[max1i] = max2

for i in range(N):
  print(A[i])

Submission status: Accepted

Solution code:
n = int(input())
n_1 = -1
n_2 = -1
index1 = -1
index2 = -1
for i in range(n):
    a = int(input())
    if a >= n_1:
        n_1 , n_2 = a ,n_1 
        index1, index2 = i, index1
    elif a >= n_2:
        n_2 = a
        index2 = i
    
for i in range(n):
    if i == index1:
        print(n_2)
    else:
        print(n_1)

Submission status: Accepted

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

sorted_a = sorted(a, reverse=True)


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

Submission status: Accepted

Solution code:
import sys
import numpy as np

N = int(sys.stdin.readline())
a = np.fromstring(sys.stdin.read(), dtype=np.uint32, sep=' ')
maxi = np.argmax(a)
max_value = a[maxi]
a[maxi] = 0
mnext = a.max()

for i in range(N):
    if i == maxi:
        print(mnext)
    else:
        print(max_value)

Submission status: Accepted

Solution code:

import numpy as np
n = int(input())

a = np.zeros((n))
for i in range(n):
    a_tmp = int(input())
    a[i] = a_tmp

f_max = np.zeros((n))
b_max = np.zeros((n))
for i in range(n):
    if i == 0:
        f_max[0] = a[0]
        b_max[n-1] = a[n-1]
    else:
        f_max[i] = max(f_max[i-1],a[i])
        b_max[n-1-i] = max(b_max[n-1-i+1],a[n-1-i])

#print(f_max)
#print(b_max)

for i in range(n):
    if i == 0:
        print(int(b_max[1]))
    elif i == (n-1):
        print(int(f_max[n-2]))
    else:
        #print(b_max[i+1],f_max[i-1])
        print(int(max(b_max[i+1],f_max[i-1])))

Submission status: Accepted

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

m = max(a)
idxs = [i for i, v in enumerate(a) if v == m]

if len(idxs) > 1:
    for i in range(n):
        print(m)

if len(idxs) == 1:
    idx = idxs[0]
    for i in range(n):
        if idx == i:
            _a = a.copy()
            _a.pop(i)
            print(max(_a))
        else:
            print(m)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

A = [0] * N

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

B = np.argsort(A)
A = np.sort(A)

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
# 一番でかいやつと二番目のやつを見つける。
# 1番でかいやつが１つなら、基本最大値で、そいつがえらばれたら2番目の値教える。

max_val = max(A)
if len([i for i, x in enumerate(A) if x == max_val]) > 1:
    for i in range(0,N):
        print(max_val)
else:
    max_val_index = A.index(max_val)
    A[max_val_index] = 0
    sec_max_val = max(A)
    for i in range(0,N):
        if i == max_val_index:
            print(sec_max_val)
        else:
            print(max_val)
            
# 一番でかいやつが２つ以上いるなら、つねに1番の値を表示する。

Submission status: Accepted

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

info2=sorted(info,reverse=True)
max1=info2[0]
max2=info2[1]

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

Submission status: Accepted

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

A_no1 = max(A)
Index_A_no1 = [i for i, x in enumerate(A) if x == A_no1]

if len(Index_A_no1) > 1:
  for n in range(N):
    print(A_no1)

else:
  AA = [a for a in A if a != A_no1]
  A_no2 = max(AA)
  Index_A_no1 = [i for i, x in enumerate(A) if x == A_no1]
  
  for n in range(N):
    if n in Index_A_no1:
      print(A_no2)
    else:
      print(A_no1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
max1 = max(a)
idx = a.index(max1)
a[idx] = 0
max2 = max(a)

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

Submission status: Accepted

Solution code:
import math  
n = int(input())

A_list = [int(input()) for i in range(n)]
sort_A = sorted(A_list)
mA =  sort_A[-1]
second = sort_A[-2]
for i in A_list :
  if i == mA :
    print(second)
  else :
    print(mA)

Submission status: Accepted

Solution code:
N = int(input())
a = [0]*N
b = [0]*N
for i in range(N):
    a[i] = int(input())
    b[i] = a[i]
m = max(b)
b.remove(m)
n = max(b)

for i in range(N):
    if a[i] == m:
        print(n)
    else:
        print(m)

Submission status: Accepted

Solution code:
import copy

n = int( input() )

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

max_num = max(a)
semi_max = 0
if a.count(max_num) == 1:
    tmp = copy.copy(a)
    tmp.remove(max_num)
    semi_max = max(tmp)
    for i in range(n):
        if a[i] == max_num:
            print(semi_max)
        else:
            print(max_num)
else:
    for i in range(n):
        print(max_num)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
aa=[]
for i in range(n):
    aa.append(int(input()))
ma = max(aa)
if aa.count(ma) > 1:
    for _ in range(n):
        print(ma)
else:
    for i in range(n):
        if aa[i] != ma:
            print(ma)
        else:
            print(max(aa[:i]+aa[i+1:]))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    a = [INT() for _ in range(n)]
    a_ = a.copy()
    a_.sort()
    m1, m2=a_[-1], a_[-2]

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

if  __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import copy
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
a=max(A)
b=A.index(a)
for j in range(N):
    if j!=b:
        print(a)
    else:
        B=copy.copy(A)
        C=B.pop(j)
        print(max(B))

Submission status: Accepted

Solution code:
import copy
n = int(input())
ls = []
for i in range(n):
    a = int(input())
    ls.append(a) 
ls2 = copy.copy(ls)
ls.sort()
max1 = ls[-1]
max2 = ls[-2]


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

Submission status: Accepted

Solution code:
#coding : utf-8

import os
import sys

N = int(input())

A = []

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

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


X.sort(key = lambda x: x[0], reverse=True)


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

Submission status: Accepted

Solution code:
#A
#n = int(input())
#print(3*n**2)
#B
#n, d = map(int, input().split())
#canseerange = 2*d+1
#if n % canseerange == 0:
#    print(int(n/canseerange))
#else:
#    print(int(n/canseerange)+1
#C
n = int(input())
ans = 0
most1 = 0
most2 = 0
ed = False
for i in range(n):
    t = int(input())
    ed = False
    if most1 <= t:
        most2 = most1
        most1 = t
        ans = i
        ed = True
    elif most2 <= t and ed == False:
        most2 = t
for i in range(n):
    if i==ans:print(most2)
    else:print(most1)

Submission status: Accepted

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

AL=[A[0]]
AR=[A[-1]]
for i in range(1,N):
    AL.append(max(A[i],AL[i-1]))
    AR.append(max(A[N-i-1],AR[i-1]))
AR.reverse()
del AL[-1]
del AR[0]

print(AR[0])
for i in range(1,N-1):
    print(max(AL[i-1],AR[i]))
print(AL[-1])

Submission status: Accepted

Solution code:
N=int(input())
maxi=0
smaxi=0
flag=0
ls=[]
x=0
for i in range(N):
  x=int(input())
  ls.append(x)
  if (maxi<x):
    smaxi=maxi
    maxi=x
  elif (maxi==x):
    smaxi=maxi
  elif (smaxi<x):
    smaxi=x
for i in range(N):
  if (ls[i]==maxi):
    print(smaxi)
  else:
    print(maxi)

Submission status: Accepted

Solution code:
n = int(input())

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

a1 = sorted(a, reverse=True)
maxmax = max(a)
max2 = a1[1]

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