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 copy
n=int(input())
a=[int(input()) for i in range(n)]
a_copy=copy.deepcopy(a)
a_copy=sorted(a_copy)
max_num=a_copy[-1]
sec_num=a_copy[-2]
answer=[]
for j in range(len(a)):
  if a[j]==max_num:
    answer.append(sec_num)
  else:
    answer.append(max_num)
for k in range(len(answer)):
  print(answer[k])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
a = [int(input()) for i in range(N)]

# a = np.array(a)
max_a = np.max(a)
premax_a = np.sort(a)[::-1][1]

for i in range(N):
    if a[i] == max_a:
        print(premax_a)
    else:
        print(max_a)

Submission status: Accepted

Solution code:
n=int(input())
A=[int(input()) for _ in range(n)]
ma=max(A)
ma_i=A.index(ma)
for i in range(n):
    if i==ma_i:
        print(max(A[:i]+A[i+1:]))
    else:
        print(ma)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N = int(input())
A = [int(input()) for _ in range(N)]
largest_num = 0
largest_ind = -1
second_large_num = 0

for i in range(N):
	if A[i] > largest_num:
		second_large_num = largest_num
		largest_num = A[i]
		largest_ind = i
	elif A[i] > second_large_num:
		second_large_num = A[i]
		
for i in range(N):
	if i == largest_ind:
		print(second_large_num)
	else:
		print(largest_num)

Submission status: Accepted

Solution code:
N = int(input())
a = []
for i in range(N):
        x = int(input())
        a.append(x)
m = max(a)
n = a.index(max(a))
for i in range(N):
        if i == n:
                b = a[:n] + a[n+1:]
                print(max(b))
        else:
                print(m)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
m=sorted(l)
m1=m[-1]
m2=m[-2]
c=l.count(m1)

for j in l:
    if j==m1:
        if c>1:
            print(m1)
        else:
            print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import numpy as np

def main():
    N = int(input().strip())
    arr = np.zeros(N, np.int32)
    for i in range(N):
        arr[i] = int(input().strip())
    arr2 = np.sort(arr)[::-1]
    max1, max2 = arr2[0], arr2[1]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
l = [int(input()) for _ in range(n)]
Max1 = sorted(l)[-1]
Max2 = sorted(l)[-2]
for i in range(n):
    print(Max1 if l[i] != Max1 else Max2)

Submission status: Accepted

Solution code:
N = int(input())
M = 1
prev_M = 0
A = []
for i in range(N):
  a = int(input())
  A += [a]
  if a == M:
    prev_M = M
  elif a > M:
    prev_M = M
    M = a
  elif a > prev_M:
    prev_M = a
for i in range(N):
  if A[i] != M:
    print(M)
  else:
    print(prev_M)

Submission status: Accepted

Solution code:
import numpy as np

N=int(input())

X=[]
for x in range(N):
    X.append(int(input()))

Y=[]
Y=np.sort(X)[::-1]

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

Submission status: Accepted

Solution code:
n=int(input())
arr=[int(input()) for _ in range(n)]
lmax=[0]*n
rmax=[0]*n
tmp=arr[0]
for i in range(1,n):
  lmax[i]=tmp
  tmp=max(tmp,arr[i])
tmp=arr[-1]
for i in range(n-2,-1,-1):
  rmax[i]=tmp
  tmp=max(tmp,arr[i])
for i in range(n):
  print(max(lmax[i],rmax[i]))

Submission status: Accepted

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

sorted_a = sorted(a, reverse=True)
first_max = sorted_a[0]
second_max = sorted_a[1]

ans = ""
ans += (str(first_max) + '\n') * (a.index(first_max))
ans += (str(second_max) + '\n')
ans += (str(first_max) + '\n') * (N - a.index(first_max) - 1)
print(ans.rstrip('\n'))

Submission status: Accepted

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

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline
from collections import defaultdict

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

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

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

B.sort(reverse=True)

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

Submission status: Accepted

Solution code:
_,*a=map(int,open(0))
b=sorted(a)
for a in a:print(b[(a<b[-1])-2])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
AA = sorted(A)
maxAA = max(AA)
for i in A:
    if maxAA == i:
        print(AA[-2])
    else:
        print(maxAA)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
 
def main():
  n = int(input())
  numList  = [int(input()) for _ in range(n)]
  maxVal = max(numList)
  workList = numList[:]
  workList.remove(maxVal)
  secondVal = max(workList)
  for num in numList:
    if num != maxVal:
      print(maxVal)
    else:
      print(secondVal)
      
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
first = 0
second = 0
As = []
for i in range(N):
    n = int(input())
    As.append(n)
    if first < n:
        first = n
    elif second < n:
        second = n

for a in As:
    if a == first:
        print(second)
    else:
        print(first)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
ma = max(a)
sma = sorted(a)[-2]

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array([int(input()) for i in range(N)])
max_index=np.argmax(A)
a_max=int(A[max_index])
a_second=int(np.amax(np.delete(A,max_index)))
for i in range(N):
    if i==max_index:
        print(a_second)
    else:
        print(a_max)

Submission status: Accepted

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

Submission status: Accepted

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

m1=0
m2=0
for a in A:
  if a>=m1:
    m1,m2 = a,m1
  elif m1>a>=m2:
    m1,m2 = m1,a

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n = int(input()) 
num = [int(input()) for _ in range(n)] 
ma=max(num)
ind=num.index(ma)
ma2=sorted(num)[-2]
for i in range(n):
    if ind==i:
        print(ma2)
    else:
        print(ma)

Submission status: Accepted

Solution code:
from itertools import accumulate, chain, islice

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

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

L = chain([-1], L)
R = chain([-1], R)
R = islice(reversed(list(R)), 1, None)

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

for m in M:
    print(m)

Submission status: Accepted

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

Submission status: Accepted

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

m2,m1 = sorted(A)[N-2:]

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
n = int(input()) 
num = [input() for _ in range(n)] 
num = np.array(num).astype("int64")
#ma=max(num)
#ind=num.index(ma)
sorted_num=sorted(num)
ma=sorted_num[-1]
ma2=sorted_num[-2]
for i in range(n):
    if ma != num[i]:
        print(str(ma).strip())
    else:
        print(str(ma2).strip())

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
 
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    max_val = max(A)
    AA = A[:]
    AA.remove(max_val)
    second_max_val = max(AA)
    for a in A:
        if a != max_val:
            print(max_val)
        else:
            print(second_max_val)
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
l=[int(input()) for _ in range(n)]
l_s=sorted(l,reverse=True)
id=l.index(l_s[0])
for i in range(n):
    if i==id:print(l_s[1])
    else: print(l_s[0])

Submission status: Accepted

Solution code:
N = int(input())
A = []
 
for _ in range(N):
    A.append(int(input()))
    
a = max(A)
b =  sorted(A)[-2]
 
for i in range(N):
    if A[i] < a:
        print(a)
    else:
        print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
a = []
for i in range(N):
        a.append(input())
b = sorted(a)
b0,b1 = b[-1],b[-2]
for i in range(N):
        if a[i]!=b0 :
                print(b0)
        else:
                print(b1)

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x = sorted(A)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [int(input()) for _ in range(n)]
a_unique = list(sorted(set(a), reverse=True))
max_value = a_unique[0]
max_value_count = a.count(max_value)

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

Submission status: Accepted

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

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


Amax = max(A)

i = A.index(Amax)
t = A[i]
A[i] = 0
A2nd = max(A)
A[i] = t

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

Submission status: Accepted

Solution code:

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

# S = sorted(A)
# MAXS = max(A)
# two = S[-2]
# print("MAX {} two {}".format(MAXS,two))
# count = S.count(max(S))
#
# for i in range(N):
#     if A[i] == MAXS:
#         if count > 1:
#             print(MAXS)
#         else:
#             print(two)
#     else:
#         print(MAXS)

# 


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


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

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


# #
# for i in range(N):
#
#     if i == 0:
#         print(max(A[1:]))
#
#     elif i == N-1:
#         print(max(A[:i]))
#
#     else:
#         low = max(A[0:i])
#         high = max(A[i+1:])
#
#         if high > low:
#             print(high)
#         else:
#             print(low)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
b=sorted(a)
f=b[-1]
s=b[-2]
for ans in a:
  if ans < f:
    print(f)
  else:
    print(s)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

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

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

Submission status: Accepted

Solution code:
N = int(input())

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


A2 = sorted(A)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# N = int(input())
# A = list(map(int, input().split()))
# 
# S = sorted(A)
# MAXS = max(A)
# 
# for i in range(N):
#     if A[i] == MAXS:
#         print(S[-2])
#     else:
#         print(S[-1])
# 


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

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
#print(A)
B = A.copy()
#print(B)
B.sort()


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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import copy

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

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


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

Submission status: Accepted

Solution code:
N = int(input())

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input()) for _ in range(N)]
AS=sorted(A)
# for i in range(N):
#     if AS[-1]==A[i]:
#         print(AS[-2])
#     else:
#         print(AS[-1])
for i in range(N):
    print(AS[-2] if AS[-1]==A[i] else AS[-1])

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:
N = int(input())
A = [int(input()) for i in range(N)]
ans = [0]*N
count = 0
ans_tmp2 = 0
ans_tmp = 0

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

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

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

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

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

Submission status: Accepted

Solution code:

from itertools import accumulate,chain

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
b = list(a)
a.sort(reverse=True)

max_num = max(a)
count = a.count(max_num)

for i in a:
    if i < max_num:
        max_num2 = i
        break

for i in range(n):
    if b[i] == max_num and count == 1:
        print(max_num2)
    else:
        print(max_num)

Submission status: Accepted

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

# 複数の最大値のインデックスを全て取得
max_index = [i for i, v in enumerate(A) if v == max_A]

# 最大値は1個か?
one_max = (len(max_index) == 1)
answer = [max_A] * N

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

Submission status: Accepted

Solution code:
import sys, re
input = sys.stdin.readline

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

# a をソートして、一番大きい要素を取り出す
temp_list = sorted(a)
m = temp_list[::-1][0]


# 最も大きな数が複数あった場合
if temp_list[::-1][1] == m:
    m_dash = m
else:
    m_dash =temp_list[::-1][1]

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

Submission status: Accepted

Solution code:
import math

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

B = sorted(A)

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

Submission status: Accepted

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

left_max=0
right_max=max(Arr)

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

        print(right_max)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    return first, second;


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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input()) #1行目のNを取得する
s = [int(input()) for i in range(N)] #複数行の数値の入力を取得
num = len(s)
s1 = sorted(s,reverse=True)[:2]
for i in range(num):
    if s1[0] == s[i]:
        print(s1[1])
    else:
        print(s1[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, *d = map(int, open(0).read().split())
m=d.index(max(d))
c=[max(d)] *N
d[m]=0
y=max(d)
c[m]=y
for i in range(len(c)):
    print(c[i])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

list = []
list.append(a)
list.append(b)
#print(max1,max2)                                                              
for _ in range(N-2):
    i = int(input())
    list.append(i)
    if i > max1:
        max2 = max1
        max1 = i
    elif i > max2:
        max2 = i
if max1==max2:
    for i in range(N):
        print(max1)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

readline = stdin.readline


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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import heapq

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

Submission status: Accepted

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