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: Wrong Answer

Solution code:
def main():
	n  = int(input())
	arr = []
	for _ in range(n):
		arr.append(int(input()))
	mx = -10000
	mx2 = -11111
	for i in range(len(arr)):
		if arr[i]>mx:
			mx = arr[i]
		if arr[i]>mx2 and arr[i]<mx:
			mx2 = arr[i]
	if mx2==-11111:
		mx2 = mx
	for i in range(len(arr)):
		if arr[i]==mx:
			print(mx2)
		else:
			print(mx)


main()

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
maximum = 0
maximum_idx = 0
for i in range(n):
    a = int(input())
    A.append(a)
    if a > maximum:
        maximum = a
        maximum_idx = i

for i in range(n):
    if i != maximum_idx:
        print(maximum)
    else:
        print(sorted(A)[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
b = list(set(a))
maxnum = max(b)

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

Submission status: Wrong Answer

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

another_list = ls.copy()
another_list.sort()

for i in range(n):
    maximum = max(ls)
    if ls[i] == maximum:
        mxidx = another_list.index(max(another_list))
        print(another_list[mxidx - 1])
    else:
        print(maximum)

Submission status: Wrong Answer

Solution code:
import copy

s=str(input())
t=str(input())
ls=len(s)
lt=len(t)
S=list(s)
T=list(t)
#print(S,T)


def fill(List):
    for j in range(len(List)):
        if List[j]=='?':
            List[j]='a'
    return List


def change1(index):
    global lt

    cS=copy.copy(S)
    cT=copy.copy(T)
    for k in range(index+1,index+lt):
        if cS[k]=='?':
            cS[k]=cT[k-index]
        elif cS[k]==cT[k-index]:
            pass
        else:
            return False,''
            break
    else:
        return True,''.join(fill(cS))

def change2(index):
    global lt

    cS=copy.copy(S)
    cT=copy.copy(T)
    cS[index]=cT[0]
    for k in range(index+1,index+lt):
        if cS[k]=='?':
            cS[k]=cT[k-index]
        elif cS[k]==cT[k-index]:
            pass
        else:
            return False,''
            break
    else:
        return True,''.join(fill(cS))



L=[]
for i in range(ls-lt+1):
    #print(ls-lt)
    if S[i]==T[0]:
        #print('Yes')
        if change1(i)[0]:
            L.append(change1(i)[1])
    elif S[i]=='?':
        if change2(i)[0]:
            L.append(change2(i)[1])
    


if L:
    L.sort()
    print(L[0])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

B.sort(reverse=True)
max_first = B[0]
max_second = B[1]

for i in range(N):
    if A[i] == max_first:
        print(max_second)
    else:
        print(max_first)

Submission status: Wrong Answer

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

B = sorted(A, reverse=True)
max_first = B[0]
max_second = B[1]

for i in range(N):
    answer = max_first
    if A[i] == max_first:
        answer = max_second
    print(answer)

Submission status: Wrong Answer

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

B = sorted(A, reverse=True)
max_first = B[0]
max_second = B[1]

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

Submission status: Wrong Answer

Solution code:
import copy
 
N=int(input())
A=[]
for _ in range(N):
    A.append(input())
 
A_max=max(A)
#print(A_max)#check

B=copy.copy(A)
B.remove(A_max)
B_max=max(B)
#print(B_max)#check

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

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
input = sys.stdin.readline
A = [input() for i in range(N)]
B = sorted(A)
for j in range(N):
  if A[j] == B[0]:
    print(B[1])
  else:
    print(B[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


sorted_A = list(reversed(sorted(A)))

maxiuam = sorted_A[0]

is_there_tow_maximum = A.count(maxiuam) >= 2
if is_there_tow_maximum:
    answer = (str(maxiuam) + "\n") * N
    print(answer)

second = None
for Ai in sorted_A:
    if Ai < maxiuam:
        second = Ai
        break

answer = []
for Ai in A:
    if Ai == maxiuam:
        answer.append(second)
    else:
        answer.append(maxiuam)
answer = "\n".join(map(str, answer))

print(answer)

Submission status: Wrong Answer

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


sorted_A = list(reversed(sorted(A)))

maxiuam = sorted_A[0]

is_there_tow_maximum = A.count(maxiuam) >= 2
if is_there_tow_maximum:
    answer = str(maxiuam) * N
    print(answer)

second = None
for Ai in sorted_A:
    if Ai < maxiuam:
        second = Ai
        break

answer = []
for Ai in A:
    if Ai == maxiuam:
        answer.append(second)
    else:
        answer.append(maxiuam)
answer = "\n".join(map(str, answer))

print(answer)

Submission status: Wrong Answer

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


sorted_A = list(reversed(sorted(A)))

maxiuam = sorted_A[0]

is_there_tow_maximum = A.count(maxiuam) >= 2
if is_there_tow_maximum:
    answer = str(maxiuam) * (N - 1)
    print(answer)

second = None
for Ai in sorted_A:
    if Ai < maxiuam:
        second = Ai
        break

answer = []
for Ai in A:
    if Ai == maxiuam:
        answer.append(second)
    else:
        answer.append(maxiuam)
answer = "\n".join(map(str, answer))

print(answer)

Submission status: Wrong Answer

Solution code:
import collections


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


sorted_A = list(reversed(sorted(A)))

maxiuam = sorted_A[0]
is_there_tow_maximum = A.count(maxiuam) >= 2

if is_there_tow_maximum:
    answer = str(maxiuam * (N - 1))
    print(answer)

second = None
for Ai in sorted_A:
    if Ai < maxiuam:
        second = Ai
        break

answer = []
for Ai in A:
    if Ai == maxiuam:
        answer.append(second)
    else:
        answer.append(maxiuam)
answer = "\n".join(map(str, answer))

print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
#a = list(map(int, input().split()))
#b = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(int(input()))

b = sorted(a)
m = max(b)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[input() for i in range(n)]
Max=max(a)
Second=sorted(a)[-2]
Index=a.index(str(Second))
[print(Max) if i!=Max else print(Second) for i in a ]

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
b=sorted(a,reverse=True)
ans1=b[0]
ans2=b[1]
for i in range(n):
  if a[i]==ans1:
    print(ans2)
  else:
    print(ans1)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())

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


MAX = max(A)

if A.count(MAX) == N:
  for _ in range(N):
    print(MAX)

  
else:

  two = sorted(set(A))[-2]
  for i in range(N):
    if A[i] == MAX:
      print(two)
    else:
      print(MAX)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)
m1 = B[-1]
m2 = B[-2]
ANS = [m1 if x == m1 else m2 for x in A]
print('\n'.join(map(str,ANS)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [[int(x) for x in input()] for _ in range(N)]
B = sorted(A)
m1 = B[-1]
m2 = B[-2]
ANS = [m1 if x == m1 else m2 for x in A]
print('\n'.join(map(str,ANS)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [[int(x) for x in input()] for _ in range(N)]
A.sort()
m1 = A[-1]
m2 = A[-2]
ANS = [m1 if x == m1 else m2 for x in A]
print('\n'.join(map(str,ANS)))

Submission status: Wrong Answer

Solution code:
n = int(input())
num = []
maxnum = 0
count = 1
for i in range(n):
  a = int(input())
  if a!=maxnum:
    maxnum = max(maxnum,a)
  else:
    count += 1
  num.append(a)
  
for i in range(n):
  if count>1:
    print(maxnum)
  else:
    if num[i]!=maxnum:
      print(maxnum)
    else:
      subnum = num[0:i] + num[i+1:n]
      subnum = sorted(subnum)
      print(subnum[n-2])

Submission status: Wrong Answer

Solution code:
import copy

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

A_max=max(A)
ind_max=A.index(A_max)
B=copy.copy(A)
B.remove(A_max)
B_max=max(B)

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

Submission status: Wrong Answer

Solution code:
import copy

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

A_max=max(A)
ind_max=A.index(A_max)
B=copy.deepcopy(A)
B.remove(A_max)
B_max=max(B)

for i in range(N):
    if i!=ind_max:
        print(A_max)
    else:
        print(B_max)

Submission status: Wrong Answer

Solution code:
import copy

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

A_max=max(A)
ind_max=A.index(A_max)
B=copy.copy(A)
B.remove(A_max)
B_max=max(B)

for i in range(N):
    if i!=ind_max:
        print(A_max)
    else:
        print(B_max)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[]
for i in range(N):
	a.append(int(input()))
k=max(a)
count=0
for j in range(N):
	if count==1:
		print(k)
	else:
		if a[j]==k:
			b=a[:j]+a[j+1:]
			count=1
			print(max(b))

Submission status: Wrong Answer

Solution code:
import copy

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

A_max=max(A)
M=[i for i,x in enumerate(A) if x==A_max]

if len(M)>=2:
    for i in range(N):
        print(A_max)
else:
    for j in range(N):
        if j!=M[0]:
            print(A_max)
        else:
            B=copy.copy(A)
            B.remove(A_max)
            print(max(B))

Submission status: Wrong Answer

Solution code:
import copy

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

A_max=max(A)
M=[i for i,x in enumerate(A) if x==A_max]

if len(M)>=2:
    for i in range(N):
        print(A_max)
else:
    for i in range(N):
        if i!=M[0]:
            print(A_max)
        else:
            B=copy.copy(A)
            B.remove(A_max)
            print(max(B))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

B = sorted(set(A[:]))
firstMax = B[-1]
secondMax = firstMax

if len(B)>1:
    secondMax = B[-2]

for i in A:
    if i == firstMax:
        print(secondMax)
    else:
        print(firstMax)

Submission status: Wrong Answer

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

B = sorted(set(A[:]))
firstMax = B[-1]
secondMax = firstMax

if len(B)>1:
    secondMax = B[-2]

for i in A:
    if i == firstMax:
        print(secondMax)
    else:
        print(max(i, firstMax))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(input()) for i in range(n)]
l = 0
L = [l]
for a in A:
    L.append(max(l, a))
r = 0
R = [r]
for a in A[::-1]:
    R.append(max(r, a))
R.reverse()
for i in range(n):
    print(max(L[i], R[i+1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
mx = max(a)
mxi = a.index(mx)
mx2 = a[:mxi] + a[mxi+1:]

for i in range(n):
    if i == mxi: print(mx2) 
    else: print(mx)

Submission status: Wrong Answer

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

if len(a_set) > 1:
  for i in range(n):
    if a[i] != a_set[0]:
      print(a_set[0])
    elif a[i] == a_set[0]:
      print(a_set[1])
elif len(a_set) == 1 :
  for i in range(n):
    print(a[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
A=[0]*n
maxd = 0
smax = 0
for i in range(n):
	A[i] = int(input())
	if A[i] >= maxd:
		smax = maxd
		maxd =A[i]
for i in range(n):
	if A[i]==maxd:
		print(smax)
	else:
		print(maxd)

Submission status: Wrong Answer

Solution code:
n = int(input())
A=[0]*n
maxd = 0
smax = 0
for i in range(n):
	A[i] = int(input())
	if A[i] > maxd:
		smax = maxd
		maxd =A[i]
for i in range(n):
	if A[i]==maxd:
		print(smax)
	else:
		print(maxd)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [input() for _ in range(N)]
A_sort = sorted(A,reverse = True)
for i in range(N):
  if A[i] != A_sort[0]:
    print(A_sort[0])
  else:
    print(A_sort[1])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
[a.append(int(input())) for _ in range(n)]
b = sorted(a)
if len(set(b))==1:
  best=better=b[-1]
else:
  best=list(set(b))[-1]
  better=list(set(b))[-2]
for i in range(n):
  if a[i] == best:
    print(better)
  else:
    print(best)

Submission status: Wrong Answer

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

max1 = max(a)
max2 = sorted(a)[-2]

if a.count(max1) == 2:
    for i in range(n):
        print(max1)
elif a.count(max1) < 2:
    for i in range(n):
        if a[i] == max1:
            print(max2)
        else:
            print(max1)

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))

if len(b) == 1: #bの長さが1なら
    for i in range(n): #n回繰り返す
        print(b[0]) #最大値のみを表示

else: #bの長さが2以上なら
    for i in range(n): #n回繰り返す
        if a[i] == b[0]: #i番目が最大値だったら
            print(b[1]) #2番目に大きい値を出力
        else: #そうでなければ
            print(b[0]) #最大値を出力

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))
c = [i for i, x in enumerate(a) if x == b[0]] #最大値の位置

if len(b) == 1:
    for i in range(n):
        print(b[0])
else:
    for i in range(n):
        if a[i] == b[0]: #最大値だったら
            print(b[1]) #最大値から2番目を出力
        else: #そうでなければ
            print(b[0]) #最大値を出力

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
a = [int(input()) for i in range(n)]
b = heapq.nlargest(2, set(a))
c = [i for i, x in enumerate(a) if x == b[0]] #最大値の位置

for i in range(n):
    if a[i] == c: #最大値だったら
        print(b[1]) #最大値から2番目を出力
    else: #そうでなければ
        print(b[0]) #最大値を出力

Submission status: Wrong Answer

Solution code:
from collections import deque

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

leftA = [0]
tmp = A[0]
for a in A:
    tmp = max(tmp, a)
    leftA.append(tmp)
print(leftA)

rightA = deque([0])
tmp = A[-1]
for a in reversed(A):
    tmp = max(tmp, a)
    rightA.appendleft(tmp)
rightA.appendleft(0)
print(rightA)

for i in range(1, n+1):
    print(max(leftA[i-1], rightA[i+1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[input().split() for i in range(N)]
B=sorted(A)
for i in range(N):
    if B[-1]==A[i]:
        print(B[-2][0])
    else:
        print(B[-1][0])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[input().split() for i in range(N)]
B=sorted(A)
for i in range(N):
  if B[-1]==A[i]:
    print(B[-2][0])
  else:
    print(B[-1][0])

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
A = [list(map(int,input())) for i in range(N)]

for i in range(N):
    B = copy.deepcopy(A)
    B.remove(A[i])
    print(max(B))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import bisect

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []

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

if len(set(A)) == 1:
    for i in range(n):
        print(A[0])
else:
    A_ = sorted(set(A))
    max_1 = A_[-1]
    max_2 = A_[-2]
    for i in A:
        if i == max_1:
            print(max_2)
        else:
            print(max_1)

Submission status: Wrong Answer

Solution code:
import copy

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

s = copy.copy(a)
s.sort()

print(s)

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

Submission status: Wrong Answer

Solution code:
import copy

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

s = copy.copy(a)
s.sort()

print(s)

for l in a:
  if(l >= s[-1]):
    print(s[-1])
  else:
    print(s[-2])

Submission status: Wrong Answer

Solution code:
import copy

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

s = copy.copy(a)
s.sort()

print(s)

for l in a:
  if(l == s[-1]):
    print(s[-1])
  else:
    print(s[-2])

Submission status: Wrong Answer

Solution code:
#B
# import math
# n, d = map(int, input().split())
# print(math.ceil(n/(d*2+1)))

#C
from collections import Counter
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
first = sorted(set(a))[-1]
if sorted(set(a))[0] == sorted(set(a))[-1]:
    pass
else:
    second = sorted(set(a))[-2]
for i in a:
    if i == first:
        print(first)
    else:
        print(second)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
max1 = max(A)
index = []
max2 = sorted(A)[1]
for i in range(N):
    if(A[i] == max1):
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
max1 = max(A)
index = []
for i in range(N):
    if(A[i] == max1):
        index.append(i)
A2 = sorted(set(A))
if(len(index) > 1):
    max2 = max1
else:
    max2 = A2[1]
for i in range(N):
    if(i in index):
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
max1 = max(A)
a = np.array(A)
index = a.argsort()[N-1:N]
A2 = sorted(set(A))
if(len(A2) == 0):
    max2 = max1
elif(len(A2) == 1):
    max2 = A2[0]
else:
    max2 = A2[1]
for i in range(N):
    if(i == index):
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:
n = int(input())
_list = []

for _ in range(n):
    _list.append(int(input()))

_set = set(_list)
sort_list = sorted(list(_set))

if len(sort_list) != 1:
    first = sort_list[-1]
    second = sort_list[-2]

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

else:
    first = sort_list[0]

    for _ in range(n):
        print(first)

Submission status: Wrong Answer

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

try:
    q = max(set(a) - set([p]))
except ValueError:
    q = p

for i in a:
    print(q if i == p else p)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

def solve():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    B = deepcopy(A)
    B.sort()

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

print(solve())

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
my_max = 0
for _ in range(N):
    a = int(input())
    A.append(a)
    my_max = max(my_max, a)

max_count = A.count(a)

if max_count > 1:
    [print(my_max) for _ in range(N)]
else:
    my_next_max = max([a for a in A if a != my_max])
    [print(my_max) if a != my_max else print(my_next_max) for a in A]

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0]*N
for i in range(N):
  A[i] = int(input())
#print(A)
M = max(A)
ind = A.index(M)
print(ind)
A.pop(ind)
m = max(A)
for i in range(N):
  #print(i)
  if i != ind:
    print(M)
  else:
    print(m)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
m1=max(a)
m2=-1
for x in a:
    if x!=m1:m2=max(m2,x)
if m2==-1:m2=m1
for x in a:
    if x==m1:print(m2)
    else:print(m1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
ma=max(a)
b=a
for i in range(n):
  if b[i]==ma:
    b[i]=0
    p=i
    break
    
maa=max(b)
A=[]
for i in range(n):
  if i!=p:
    A.append(ma)
  else:
    A.append(maa)
    
print(A[i] for _ in range(n))

Submission status: Wrong Answer

Solution code:
def main():
	n = int(input())
	# n,m = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	l = [str(input()) for i in range(n)]
	#R行C列
	# a = [list(map(int,input().split())) for x in range(m)]
	# print(' '.join(map(str,)))

	# i = 0
	print(max(l[1:n]))
	m = max(l[1:n])

	# 0 < i < n
	for i in range(1,n):
		if l[i] == m:
			print(max(l[0:i],l[i+1:n]))
		else:
			print(m)


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	n = int(input())
	# n,m = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	l = [str(input()) for i in range(n)]
	#R行C列
	# a = [list(map(int,input().split())) for x in range(m)]
	# print(' '.join(map(str,)))

	# i = 0
	print(max(l[1:n]))
	m = max(l[1:n])

	# 0 < i < n
	for i in range(1,n):
		if l[i] == m:
			print(max(l[0:i] + l[i+1:n]))
		else:
			print(m)


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	n = int(input())
	# n,m = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	l = [str(input()) for i in range(n)]
	#R行C列
	# a = [list(map(int,input().split())) for x in range(m)]
	# print(' '.join(map(str,)))
	ans = []

	# i = 0
	print(max(l[1:n]))
	m = max(l[1:n])

	# 0 < i < n
	for i in range(1,n):
		if l[i] == m:
			print(l[0:i] + l[i+1:n])
		else:
			print(m)


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(input()) for _ in range(n)]
#print(l)
k=l
k.sort()
dic_lst={}
for i in l:
  if i not in dic_lst:
    dic_lst[i]=1
  else:
    dic_lst[i]+=1
for i in l:
  max_num=max(dic_lst.keys())
  if i<max_num:
    print(max_num)
  if i==max_num:
    if dic_lst[i]>1:
      print(max_num)
    elif dic_lst[i]==1:
      print(k[1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(stdin.readline().rstrip()) for _ in range(n)]

m1 = [x for i, x in enumerate(a) if x == max(a)]

for i in a:
    if len(m1) > 1:
        print(max(m1))
    else:
        m2 = max([x for x in a if x != max(m1)])
        print(max(m1) if a != max(m1) else m2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
A = [int(input()) for _ in range(N)] 
A_max1 = max(A)
if A.count(A_max1) >= 2:
    for i in range(N):
        print(A_max1)
        sys.exit()
elif  A.count(A_max1) == 1:
    A[A.index(A_max1)] = 0
    A_max2 = max(A)
    A[A.index(0)] = A_max1
    for i in range(N):
        if A[i] == A_max1:
            print(A_max2)
        else:
            print(A_max1)

Submission status: Wrong Answer

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

x = max(a)

b = sorted(list(set(a)), reverse=True)
if(len(b) == 1):
   y = x
else:
   y = b[1]

for i in range(n):
   if(a[i] < x):
      print(x)
   else:
      print(y)

Submission status: Wrong Answer

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

import copy

for i in range(n):
   if(a[i] < x):
      print(x)
   else:
      b = sorted(list(set(a)), reverse=True)
      if(len(b) == 1):
         print(x)
      else:
         print(b[1])

Submission status: Wrong Answer

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


def solve(N: int, A: "List[int]"):
    m = sorted(list(set(A)))

    for a in A:
        if a == m[-1] and len(m) > 1:
            print(m[-2])
        else:
            print(m[-1])

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

x = sorted(a, reverse = True)
  
max = x[0]
count = x.count(max)
for i in range(n):
  if a[i] == max:
      print(max)      
  else:
    print(x[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
a = sorted(set(A))
max_count = A.count(a[-1])
for i in range(N):
  if len(a) > 1:
    if A[i] != a[-1]:
      print(a[-1])
    else:
      if max_count < 1:
        print(a[-1])
      else:
        print(a[-2])
  else:
    print(a[-1])

Submission status: Wrong Answer

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

for i in range(N):
  if len(a) > 1:
    if A[i] != a[-1]:
      print(a[-1])
    else:
      print(a[-2])
  else:
    print(a[-1])

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *A = map(int, read().split())
Anp = np.array(A)

L = np.maximum.accumulate(Anp)
R = np.maximum.accumulate(Anp[::-1])[::-1]

LL = [0] + L.tolist()[:-1]
RR = R.tolist()[1:] + [0]
print(LL)
print(RR)

for x, y in zip(LL, RR):
    print(x if x > y else y)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list()
for i in range(N):
  A.append(int(input()))
ma = max(A)
am = sorted(A,reverse = True)
for i in range(N):
  if ma != A[i]:
    print(ma)
  else:
    print(am[1])
print(am)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list()
for i in range(N):
  A.append(int(input()))
ma = max(A)
am = sorted(A)
for i in range(N):
  if ma != A[i]:
    print(ma)
  else:
    print(am[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list()
for i in range(N):
  A.append(int(input()))
ma = max(A)
for i in range(N):
  if ma != A[i]:
    print(ma)
  else:
    A[i] = 0
    print(max(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for _ in range(N):
  A += [int(input())]
Amax = max(A)
Amax2 = sorted(A, reverse=True)[1]
for i in range(N):
  print(Amax if i != Amax else Amax2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = []
for i in range(N):
    A = int(input())
    A_list.append(A)
sort_A = sorted(A_list, reverse = True)
k = 0
for i in range(1, len(sort_A)):
    if sort_A[i] != sort_A[i-1]:
        A_second = sort_A[i]
        break
    if i == len(sort_A)-1:
        A_second = sort_A[0]
for i in range(N):
    if A_list[i] == sort_A[0]:
        print(A_second)
    else:
        print(sort_A[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = []
for i in range(N):
    A = int(input())
    A_list.append(A)
sort_A = sorted(A_list, reverse = True)
k = 0
for i in range(1, len(sort_A)):
    if sort_A[k] != sort_A[k-1]:
        A_second = sort_A[k]
        break
    if i == len(sort_A)-1:
        A_second = sort_A[0]
for i in range(N):
    if A_list[i] == sort_A[0]:
        print(A_second)
    else:
        print(sort_A[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
s = sum(a)
for i in a:
  print(s-i)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[]
for _ in range(N):
  a_=int(input())
  a.append(a_)
x=max(a)
b=a
if a.count(x)>=2:
  for i in range(N):
    print(x)
else:
  for i in range(N):
    if a[i]==x:
      b.sort()
      print(b[-2])
    else:print(x)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[]
b=a
for _ in range(N):
  a_=int(input())
  a.append(a_)
x=max(a)
if a.count(x)>=2:
  for i in range(N):
    print(x)
else:
  for i in range(N):
    if a[i]==x:
      b.sort()
      print(b[-2])
    else:print(x)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[]
for _ in range(N):
  a_=int(input())
  a.append(a_)
x=max(a)
if a.count(x)>=2:
  for i in range(N):
    print(x)
else:
  for i in range(N):
    if a[i]==x:
      a.sort()
      print(a[-2])
    else:print(x)