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:
import sys, re
input = sys.stdin.readline

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

temp_list = sorted(a)
m = temp_list[-1]
m_dash = m + 1

for i in range(1, n):
  if temp_list[-i] == m:
    continue
  else:
    m_dash = temp_list[-i]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
data = [int(input()) for k in range(n)]
for i in range(n):
	s = data
	s[i] = 0
	s.sort()
	print(s[-1])

Submission status: Wrong Answer

Solution code:

N = int(input())
if 2 <= N <= 200000:
    Input = [input() for i in range(N)]

result = []
n = N
s = 1
m = 2

for i in range(N):

    if n <= m:
        m = 0
    if n <= s:
        s = 0

    if Input[s] < Input[m]:
        result.append(Input[m])
        m  += 1
        s  += 1
    else:
        result.append(Input[s])
        m  += 1
        s  += 1


for i in  range(len(result)):
    print(result[i])

Submission status: Wrong Answer

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(bl)
print(br)
print(br[1])
for i in range(1, n - 1):
    print(max(bl[i - 1],br[i + 1]))
print(bl)
print(br)
print(bl[n - 2])

Submission status: Wrong Answer

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

for i in a:
    a.remove(i)
    print( max(a) )
    a.append(i)

Submission status: Wrong Answer

Solution code:
import numpy as np

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


for _ in range(N):
    A.append(int(input()))
    
a = b = A[0]
    
for i in range(N):
    if A[i] > a:
        a = A[i]
    elif A[i] > b:
        b = A[i]

for i in range(N):
    if A[i] < a:
        print(a)
    else:
        print(b)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
t=list(enumerate(a))
t.sort(key=lambda x:x[1])
print(t)
mx=t[-1][1]
ans=[mx for i in a]
ans[t[-1][0]]=t[-2][1]
for k in ans:
    print(k)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
max_a = max(a)
if a.count(max(a)) == 1:
  sec_max = sorted(a)[1]
else:
  sec_max = max_a

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

Submission status: Wrong Answer

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()
for i in range(n - 1):
    print(max(bl[i],br[i + 1]))
print(bl[n - 1])

Submission status: Wrong Answer

Solution code:

n=int(input())
a=[]
b=[]
for i in range(n):
    num=int(input())
    a.append(num)
    b.append(num)
b.sort(reverse=True)
x=a.count(a[0])
for i in range(n):
    if(a[i]==b[0]):
        if(x==1):
            print(b[1])
        else:
            print(b[0])
    else:
        print(b[0])

Submission status: Wrong Answer

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

v_max = max(v)
for i in range(n):
    if v[i] == max:
        v_i = v.pop(i)
        print(max(v))
        v.insert(i, v_i)
    else:
        print(v_max)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
t=list(enumerate(a))
t.sort(key=lambda x:x[1])

mx=t[-1][1]
ans=[mx for i in a]
ans[t[-1][0]]=t[-2][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

maxA = max(A)

for i in range(N):
    if A[i] != maxA:
        print(maxA)
    else:
        a = [x for x in A if A[i] != x]
        if a == []:
            print(maxA)
        else:
            print(max(a))

Submission status: Wrong Answer

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

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

A_set = set(A)
if len(A_set)==1:
  val = A[0]
  for i in range(N):
    print(val)
  sys.exit()
else:
  second_max = sorted(A_set)[-2]
tmp_max = max(set(A))
tmp_max_list = [i for i, x in enumerate(A) if x == tmp_max]


for i in range(N):
  if i in tmp_max_list:
    print(second_max)
  else:
    print(tmp_max)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list()
for i in range(N) :
	A.append(int(input()))
a = max(A)
B = sorted(set(A))[::-1]
if(len(B) > 1) :
	b = B[1]
else :
	b = B[0]
for i in range(N) :
	if(A[i] == a) :
		print(b)
	else :
		print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [int(input()) for i in range(N)]
ld = sorted(s, reverse=True)
print(ld)
D = int(s.index(ld[0]))

if N == 1:
    print(s[0])
else:
    for i in range(D):
        print(ld[0])
    print(ld[1])
    for i in range(N-D-1):
        print(ld[0])

Submission status: Wrong Answer

Solution code:
N = int(input())

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

new_A = sorted(A, reverse=True)

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

Submission status: Wrong Answer

Solution code:
N=int(input())
L=[]
T=[]
for _ in range(N):
  x=int(input())
  L.append(x)
  if x not in T:
    T.append(x)

T.sort()
T.reverse()

for i in range(N):
  for j in range(len(T)):
    if T[j]!=L[i]:
      print(T[j])
      break
    elif len(T)==1:
      print(T[j])

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
a=[]
m=[]
ans=[]
for i in range(n):
  a.append(int(input()))
m.append(a.index(max(a)))
m.append(a.pop(m[0]))
m.append(max(a))

ans=np.full(n,m[1])
ans[m[0]]=m[2]
for i in range(n):
  print(ans[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [input() for i in range(N)]
ld = sorted(s, reverse=True)

D = int(s.index(ld[0]))

if N == 1:
    print(s[0])
else:
    for i in range(D):
        print(ld[0])
    print(ld[1])
    for i in range(N-D-1):
        print(ld[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list()
for i in range(N) :
	A.append(int(input()))
a = max(A)
B = sorted(set(A))
if(len(B) > 1) :
	b = B[-2]
else :
	b = B[0]
for i in range(N) :
	if(A[i] == a) :
		print(b)
	else :
		print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [input() for i in range(N)]
ld = sorted(s, reverse=True)

D = int(s.index(ld[0]))

for i in range(D):
    print(ld[0])
print(ld[1])
for i in range(N-D-1):
    print(ld[0])

Submission status: Wrong Answer

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)

if len(set(a)) == 1:
    premax_a = max_a
    for i in range(N):
        print(max_a)
else:
    premax_a = np.max(a[a<max_a])
    max_idxes = np.where(a == max_a)[0]
    for i in range(N):
        if i in max_idxes:
            print(premax_a)
        else:
            print(max_a)
    
# max_idxes = np.where(a == max_a)[0]

# for i in range(N):
#     if i in max_idxes:
#         print(premax_a)
#     else:
#         print(max_a)
    
# for i in range(N):
#     if a[i] != max_a:
#         print(max_a)
#     else:
# #         print(i)
# #         print(a[0:i]+a[i+1:])
#         premax_a = np.max(a[0:i]+a[i+1:]) 
#         print(premax_a)

Submission status: Wrong Answer

Solution code:
n = int(input())
max_1 = None
max_2 = None

for i in range(n):
    a = int(input())
        
    if max_1 is None:
        max_1 = a
        max_i = [i]
        
    elif max_1 == a:
        max_i.append(i)
    
    if max_2 is None:
        if a < max_1:
            max_2 = a
       
    else:    
        if max_2 < a:
            if max_1 < a:
                max_2 = max_1
                max_i = [i]
                max_1 = a
            else:
                max_2 = a
    
if len(max_i) >= 2:
    out_list = [max_1 for i in range(n)]
else:
    out_list = [max_1 for i in range(n)]
    out_list[max_i[0]] = max_2
    
print("\n".join(map(str, out_list)))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
n=int(input())
a=[]
m=[]
ans=[]
for i in range(n):
  a.append(int(input()))
m.append(a.index(max(a)))
m.append(a.pop(m[0]))
m.append(a.index(max(a)))
m.append(a[m[2]])

ans=np.full(n,m[1])
ans[m[0]]=m[3]
for i in range(n):
  print(ans[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
AList = [input() for i in range(N)]
max_AList = max(AList)
max2nd_AList = 0

for i in range(N) :
    if AList[i] == max_AList :
        if max2nd_AList == 0 :
            max2nd_AList = max(AList[0:i] + AList[i+1:N])
            print(max2nd_AList)
        else :
            print(max2nd_AList)
    else :
        print(max_AList)

Submission status: Wrong Answer

Solution code:
import numpy as np

i = input()
N = int(i)
A = np.array([0]*N)
i = input()
a = int(i)
A[0] = a
i = input()
b = int(i)
A[1] = b
snd = min(a, b)
fst = max(a, b)
for x in range(N - 2):
    j = input()
    y = int(j)
    A[x+2] = y
    snd = min(fst, y)
    fst = max(fst, y)

for x in range(N):
    if A[x] < fst:
        print(fst)
    else:
        print(snd)

Submission status: Wrong Answer

Solution code:
N = int(input())
AList = [input() for i in range(N)]
max_AList = max(AList)
max2nd_AList = 0

for i in range(N) :
    if AList[i] == max_AList :
        if max2nd_AList == 0 :
            max2nd_AList = max(AList[0:i] + AList[i+1:N])
        else :
            print(max2nd_AList)
    else :
        print(max_AList)

Submission status: Wrong Answer

Solution code:
n = int(input())
al = [int(input()) for i in range(n)]
s = set(al)
m2 = m1 = max(s)
if len(s) > 1:
    s.remove(m1)
    m2 = max(s)
for a in al:
    print(m2) if m1 == a else print(m1)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [input() for i in range(N)]
for i in range(0,N):
    if max(s) != s[i]:
        print(max(s))
    else:
        sorted(s)[-2]

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[]
for i in range(n):
  x.append(int(input()))
cnt = [0] * 50
for i in range(n):
  for j in range(n):
    if i is not j and cnt[i] < x[j]:
      cnt[i]=x[j]
  cnt[i]=str(cnt[i])+"\n"
print(cnt)

Submission status: Wrong Answer

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)

if len(set(a)) == 1:
    premax_a = max_a
else:
    premax_a = np.max(a[a<max_a])
    
max_idxes = np.where(a == max_a)[0]

for i in range(N):
    if i in max_idxes:
        print(premax_a)
    else:
        print(max_a)
    
# for i in range(N):
#     if a[i] != max_a:
#         print(max_a)
#     else:
# #         print(i)
# #         print(a[0:i]+a[i+1:])
#         premax_a = np.max(a[0:i]+a[i+1:]) 
#         print(premax_a)

Submission status: Wrong Answer

Solution code:
n=input()
n=int(n)
a=[]
for i in range(n):
  s=input()
  a.append(s)
m=max(a)
k=a.index(m)
a.remove(m)
for j in range(k):
  print(m)
if int(max(a))>=0:
  print(max(a))
else:
  print(min(a))
for t in range(n-k-1):
  print(m)

Submission status: Wrong Answer

Solution code:
data = []
i = int(input())

data = [int(input()) for _n in range(i)]
maxInt = max(data)
for n in range(i):
	print([maxInt,data[n]])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [input() for i in range(N)]
ans = 0
wk = A[:]
Max1 = max(A)
wk.remove(Max1)
Max2 = max(wk)
wk.clear()
indexes = [i for i, x in enumerate(A) if x == Max1]
for i in range(N):
    ans = Max2 if len(indexes) < 2 and A[i] == Max1 else Max1
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
a=np.zeros(n)
print(a)
for _ in range(n):
  x=int(input())
  a[_]=x
a=list(a)
for _ in range(n):
  b=a[0:_]+a[_+1:n]
  print(max(b))

Submission status: Wrong Answer

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

maxnumber = max(A)
secondmax = sorted(A)[-2]

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

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())

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

i = 0

while i < n:
    if columns[i] == max(columns):
        print(sorted(set(columns))[-1])
    else:
        print(max(columns))
    i += 1

Submission status: Wrong Answer

Solution code:
import numpy as np

i = input()
N = int(i)
A = np.array([0]*N)
fst = 0
snd = 0
for x in range(N):
    j = input()
    y = int(j)
    A[x] = y
    snd = min(fst, y)
    fst = max(fst, y)

for x in range(N):
    if A[x] < fst:
        print(fst)
    else:
        print(snd)

Submission status: Wrong Answer

Solution code:
N = int(input())

m0 = 1
m1 = 1
max_i = []
for i in range(N):
    a = int(input())
    if a > m0:
        m1 = m0
        m0 = a
        max_i.append(i)
    elif a == m0:
        m1 = a
    elif a > m1:
        m1 = a
for i in range(N):
    if i in max_i:
        print(m1)
    else:
        print(m0)

Submission status: Wrong Answer

Solution code:
n = int(input())
t = [int(input()) for i in range(n)]
for i in range(len(t)-1):
  s = t[:]
  del s[i]
  print(max(s))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [input() for _ in range(N)]
max_A = max(A)
max_index = [i for i, v in enumerate(A) if v == max_A]
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: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
else:
    MAX = max(A)

for i in range(N):
    if MAX != A[i]:
        print(MAX)
        continue
    if i > 1 and i < N - 2:
        print(max(A[:i]),max(A[i+1:]))
        continue
    if i == 0:
        print(max(A[1:]))
        continue
    if i == 1 and N == 2:
        print(A[0])
        continue
    if i == 1 and N > 2:
        print(max(A[0], max(A[2:])))
        continue
    if i == N -2:
        print(max(max(A[:N-2]), A[N-1]))
        continue
    if i == N - 1:
        print(max(A[:N-1]))

Submission status: Wrong Answer

Solution code:
import copy
from sys import stdin
n=int(input())
A=[int(stdin.readline().rstrip()) for _ in range(n)]
z=max(A)
B=sorted(A)
o=B[1]
for j in range(0,n):
    if A[j]<z:
       print(z)
    else:
        if B[0]==B[1]:
           print(z)
        else:
           print(o)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    N = int(stdin.readline())
    A = [int(input()) for _ in range(N)]

    for a in A:
        # if max(A) == a:
        #     new_A = sorted(A)
        #     print(new_A[1])
        # else:
        #     print(max(A))
        print(max(A))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

import math

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

    value = sorted(A)
    first = value[N-1]
    second = -1
    for i in range(N-1, -1 , -1):
        if value[i] != first:
            second = value[i]
            break


    # print(A)

    for i in range(N):
        if A[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 = 0
for j in a:
    if j > max1:
        max1 = j
min1 = 2000001
for t in a:
    if t < min1:
        min1 = t
max2 = 0
for e in a:
    if e > max2 and e < max1:
        max2 = e

if max1 == min1:
    max2 = max1

for k in a:
    if max1 == k:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
k = max(a)
for i in range(n):
    if a[i] <= k:
        print(k)
    else:
        tmp = a[i]
        a[i] = 0
        print(max(a))
        a[i] = tmp

Submission status: Wrong Answer

Solution code:
a = int(input()) 
b = [int(input()) for i in range(a)] 
m=max(b)
for i in range(a):
  if m>=b[i]:
    print(max(b))
  else:
    print(b[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [input() for i in range(N)]
sinit = s[0]
t = s[:]
t.pop(0)
smax = max(t)
if sinit>smax:
    print(smax)
    for i in range(N-1):
        print(sinit)

else:
    D = int(s.index(smax))
    x = s[:]
    x.pop(D)
    xmax = max(x)
    for i in range(D):
        print(smax)
    print(xmax)
    for i in range(N-D-1):
        print(smax)

Submission status: Wrong Answer

Solution code:
N = int(input())
L=[]
i = 0
s = 0
for i in range (0,N):
    L.append(int(input()))
M = L[0]
for s in range(1,N):
    if  L[s] > M:
        M = L[s]
i = 0
for i in range(0,N):
    F = L[0]
    for s in range(1,N):
        if F == M:
            continue
        else:
            if L[s] == L[i]:
                continue
            else:
                if L[s] > F:
                    F = L[s]
    print(F)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
M1=[0]
M2=[0]

max_val = 0
for i in range(N):
    input_val = int(input())
    if (max_val < input_val):
        max_val = input_val
    A.append(input_val)
    if (i < N -1):
        M1.append(max_val)

max_val = 0
for i in range(N-1):
    input_val = A[N-1-i]
    if (max_val < input_val):
        max_val = input_val
    M2.append(max_val)

if (N<=2):
    print(A[0])
    print(A[1])
else:
    for i in range(N):
        print(max(M1[i], M2[N-1-i]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)

if len(a[a<max_a]) == 0:
    premax_a = max_a
else:
    premax_a = np.max(a[a<max_a])
    
max_idxes = np.where(a == max_a)[0]

for i in range(N):
    if i in max_idxes:
        print(premax_a)
    else:
        print(max_a)
    
# for i in range(N):
#     if a[i] != max_a:
#         print(max_a)
#     else:
# #         print(i)
# #         print(a[0:i]+a[i+1:])
#         premax_a = np.max(a[0:i]+a[i+1:]) 
#         print(premax_a)

Submission status: Wrong Answer

Solution code:
sequence = []

N = int(input())

count = 0

for i in range(N):
    curr_el = int(input())
    sequence.append(curr_el)
    if (i == 0):
        max_el = second = curr_el
    elif (curr_el >= max_el):
        max_el = curr_el
    elif (curr_el >= second):
        second = curr_el

# print('sequence', sequence)

for curr_el in sequence:
    answer = max_el if (curr_el == max_el) else second
    print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
AList = [input() for i in range(N)]
max_AList = max(AList)
max2nd_AList = sorted(AList, reverse = True)[1]

for i in range(N) :
    if AList[i] == max_AList :
        print(max2nd_AList)
    else :
        print(max_AList)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
n=int(input())
a=[]
m=[]
ans=[]
for i in range(n):
  a.append(int(input()))
m.append(a.index(max(a)))
m.append(a.pop(m[0]))
m.append(a.index(max(a)))
m.append(a[m[2]])
if m[1]==m[3]:
  for i in range(n):
    print(m[1])
else:
  ans=np.full(n,m[1])
  ans[m[0]]=m[3]
  for i in range(n):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a_list = []
    for i in range(n):
        a = int(input())
        #[タグ、値]
        a_list.append([i,a])

    ans = sorted(a_list, key=lambda x:x[1])
    #print(ans)

    print("-"*75)
    for i in range(n):
        #if 値 == max(ans)
        if a_list[i][1] == ans[-1][1]:
            #ansの最後から二番目の値
            print(ans[-2][1])
        else:
            print(ans[-1][1])

main()

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import copy

n = int(input())
ls = [int(input()) for _ in range(n)]
p = 50
ans = 0
if p>n:p=n

def cul(n, x):
    l = len(x)
    b = [x[i] for i in range(l)]
    b.pop(n)
    return max(b)
    
for i in range(p):
    s = cul(i,ls[:p])
    print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
a_list = []
max_v = -1
sec = -1
max_ind = []
for i in range(N):
    a_list.append(int(input()))
    if a_list[-1]>max_v:
        max_v = a_list[-1]
        max_ind = [i]
    elif a_list[-1]<max_v:
        if a_list[-1]>sec:
            sec = a_list[-1]
    else:
        max_ind.append(i)
if len(max_ind)>1:
    for i in range(N):
        print(max_v)
else:
    for i in range(N):
        if i in max_ind:
            print(sec)
        else:
            print(max_v)

Submission status: Wrong Answer

Solution code:
n = int(input())

li = [int(input()) for i in range(n)]
ls = sorted(li, reverse = True)

m1 = ls[0]
m2 = ls[0]
for i in range(0,n):
    if(ls[i] != m1):
        m2 = ls[i]
        break
    

for i in li:
    print(m1 if(i != m1) else m2)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(N):
    ans = A[:i] + A[i+1:]
    print(max(ans))

Submission status: Wrong Answer

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

ans = []
front_max = back_max = 0

for i in reversed(range(N)):
    now = A[-1]
    A[-1] = 0
    front_max = max(A) if A else 0
    ans.append(max(front_max, back_max))
    back_max = max(now, back_max)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
AList = [input() for i in range(N)]
max_AList = max(AList)
max2nd_AList = sorted(AList)[1]

for i in range(N) :
    if AList[i] == max_AList :
        print(max2nd_AList)
    else :
        print(max_AList)

Submission status: Wrong Answer

Solution code:
N=int(input())
cnt=0
flg=0
max1=0
max2=0
for i in range(N):
    A=int(input())
    if A > max1:
        cnt = 0
        flg = 0
        if i == 0:
            max2 = A
        else:
            max2 = max1
        max1 = A
        maxi = i
    elif A == max1:
        cnt+=1
    if A > max2 and max1 > A :
        max2 = A
    if cnt > 1:
        flg = 1
if flg == 1:
    for i in range(N):
        print(max1)
elif max1 != max2:
    for i in range(N):
        if i != maxi:
            print(max1)
        else:
            print(max2)
else:
    for i in range(N):
        print(max1)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
s = [input() for i in range(N)]
sinit = s[0]
t = s[:]
t.pop(0)
smax = max(t)
if sinit>=smax:
    print(smax)
    for i in range(N-1):
        print(sinit)

else:
    D = int(s.index(smax))
    x = s[:]
    x.pop(D)
    xmax = max(x)
    for i in range(D):
        print(smax)
    print(xmax)
    for i in range(N-D-1):
        print(smax)

Submission status: Wrong Answer

Solution code:
import copy
from sys import stdin
n=int(input())
A=[int(stdin.readline().rstrip()) for _ in range(n)]
m=max(A)
for j in range(0,n):
    B=copy.copy(A)
    s=A[j]
    A.pop(j)
    print(m)
    A = copy.copy(B)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []
max1 = 0
max2 = 0
for _ in range(N):
    ai = int(input())
    if max1 < ai:
        max1 = ai
    elif max2 < ai:
        max2 = ai

    if max2 == 0:
        max2 = ai

    A.append((ai, max2, max1))

for i in range(N):
    if i == N - 1:
        t = N - 2
    else:
        t = N - 1

    ai, _, _ = A[i]
    _, max2, max1 = A[t]


    if max1 == ai:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:
N = int(input())
num_list = [input() for i in range(N)]
a = max(num_list)
if num_list.count(a) > 1:
  for j in range(N):
    print(a)
elif len(num_list) == 1:
  print(a)
else:
  b = sorted(num_list)[-2]
  for k in range(int(num_list.index(a))):
    print(a)
  print(b)
  for l in range(N-int(num_list.index(a))-1):
    print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())

li = [int(input()) for i in range(n)]
ls = sorted(li, reverse = True)

m1 = ls[0]

for i in range(1,n):
    if(ls[i] != m1):
        m2 = ls[i]
        break
    else:
        m2 = m1

for i in li:
    print(m1 if(i != m1) else m2)

Submission status: Wrong Answer

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

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

# solve & output
ans = A
ans.sort()
m = ans[-1]
for i in range(N):
    if A[i] != m:
        print(m)
    else:
        print(ans[N - 2])

Submission status: Wrong Answer

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

for j in range(n-1):
    a[j] = 0
    print(max(a))
    a[j] = b[j]

Submission status: Wrong Answer

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

l = []
for i in range(N):
    d = D.copy()
    d.pop(i)
    l.append(max(d))
print(l)

Submission status: Wrong Answer

Solution code:
N = int(input())

m0 = 1
m1 = 1
max_i = []
for i in range(N):
    a = int(input())
    if a > m0:
        m0 = a
        max_i.append(i)
    elif a == m0:
        m1 = a
    elif a > m1:
        m1 = a
for i in range(N):
    if i in max_i:
        print(m1)
    else:
        print(m0)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    N = int(stdin.readline())
    A = [int(input()) for _ in range(N)]

    for a in A:
        if max(A) == a:
            new_A = sorted(A)
            print(new_A[1])
        else:
            print(max(A))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

max_v = max(A)
max_c = A.count(max_v)
for i in range(N):
    tmp = A[i]
    if tmp != max_v:
        print(max_v)
    else:
        if max_c > 1:
            print(max_v)
        else:
            print(B[-2])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
A_m = str(max(A))
a = A.index(int(A_m))
A = sorted(A)
if A.count(int(A_m)) >= 2:
    print((A_m + '\n')*N)
else:
    print(a)
    print((A_m + '\n')*a + str(A[-2]))
    print((A_m + '\n')*(N-(a+1)))

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
a=[int(input()) for i in range(N)]
for i in range(N):
  b = copy.copy(a)
  print(b)
  b.pop(i)
  print(max(b))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a_list = []
    for i in range(n):
        a = int(input())
        #[タグ、値]
        a_list.append([i,a])

    ans = sorted(a_list, key=lambda x:x[1])
    #print(ans)

    for i in range(n):
        #if 値 == max(ans)
        if ans[i][1] == max(ans[1]):
            #ansの最後から二番目の値
            print(ans[-2][1])
        else:
            print(ans[-1][1])

main()

Submission status: Wrong Answer

Solution code:
# C

N = int(input())
A = [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: Wrong Answer

Solution code:
n=input()
n=int(n)
a=[]
for i in range(n):
  s=input()
  a.append(s)
m=max(a)
k=a.index(m)
a.remove(m)
for j in range(k):
  print(m)
print(max(a))
for t in range(n-k-1):
  print(m)

Submission status: Wrong Answer

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


for i in range(N):
    li.append(input())

new_li = sorted(li, reverse=True)

M = new_li[0]
m = new_li[1]

for i in range(N):
    if li[i] != M:
        print(M)
    elif li[i] == M:
        print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

b = sorted(a)


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

Submission status: Wrong Answer

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

li = [int(input()) for i in range(n)]
m = max(li)
for j in range(n):
  if m < li[j]:
    print(m)
  else:
    print(max(li))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sort = temp[:]

sort.sort()

maximum = sort[-1]

print(maximum)

for i in temp:
	if i != maximum:
		print(maximum)

	else:
		print(sort[-2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

import math
import sys
import itertools
import queue
from fractions import gcd
import time


def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N= int(sys.stdin.readline())
    A = list(map(int,sys.stdin.readlines()))
    k=A.pop(0)
    m = max(A)
    A.insert(0,k)
    print(m)
    for i in range(1,len(A)):
        if m == A[i]:
            k=A.pop(i)
            m = max(A)
            A.insert(i,k)
            print(m)
        else:
            print(m)

Submission status: Wrong Answer

Solution code:
import numpy as np
n= int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
    
b = np.array(a)
np.sort(b)[::-1]
ans = [0]*n

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