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 numpy as np

N = int(input())

A = np.array([])

for i in range(N):
	a = int(input())
	A = np.hstack( (A,a) )


B = A
ans = np.amax(A)
j = np.argmax(A)
ans2 = np.amax(np.delete(A,j))

for i in range(N):
	if i == j:
		ans = ans2
	print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
aMax=0
multi=0
a = [0 for i in range(n)]
for i in range(n):
  a[i] = int(input())
  if aMax == a[i]:
    multi = 1
  elif aMax < a[i]:
    aMax = a[i]
    multi = 0

if multi == 1:
  for i in range(n):
    print(aMax)
else:
  for i in range(n):
    if aMax != a[i]:
      print(aMax)
    else:
      if i == 0:
        aMax1=max(a[1:n])
        print(aMax1)
      else:
        aMax2=max(a[0:i],a[i+1:n])
        print(aMax2[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
max1 = 0
max2 = 0
index = 0
for i in range(n):
    a = int(input())
    new_max = max(a, max1)
    if (a == new_max and max2 < max1) or (a == new_max and max2 < max1 and a == max1):
        max2 = max1
        index = i
    elif (a != new_max and max2 < a) or (a != new_max and max2 < a and a == max1):
        max2 = a
    max1 = new_max

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

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
a = [int(input()) for i in range(n)]
max_list = list(itertools.accumulate(a, func=max))
max_list_r = list(itertools.accumulate(reversed(a), func=max))

for i in range(n):
    print(max(max_list[i - 1], max_list_r[i - 1]))

Submission status: Wrong Answer

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

if len(set(A)) == 1:
  for _ in range(N):
    print(max(A))
else:
  for i in range(N):
    if A[i] == max(A):
      print(sorted(set(A))[-2])
    else:
      print(max(A))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
n=int(input())
a=[]
ans=[]
for i in range(n):
  a.append([i,int(input())])
b=sorted(a, key=lambda x: x[1])
if b[n-1][1]==b[n-2][1]:
  for i in range(n):
    print(b[n-1][1])
else:
  ans=np.full(n,b[n-1][1])
  ans[b[n-1][0]]=b[n-2][1]
  for i in range(n):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
max1 = 0
max2 = 0
index = 0
for i in range(n):
    a = int(input())
    new_max = max(a, max1)
    if a == new_max and max2 < max1:
        max2 = max1
        index = i
    elif a != new_max and max2 < a:
        max2 = a
    max1 = new_max

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

A_set = set(A)
if len(A_set)==1:
  second_max = A[0]
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 =int(input())
b=int(input())
if a==b:
    max1 = a
    max2 = 0
elif 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 and i!=max1:
        max2 = i
#print(max1,max2)                                                              
if max2 == 0:
    max2 = max1
for i in list:
    if i == max1:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
string_list = [input() for i in range(n)]

max_num = max(string_list)

for j in string_list:
    if j != max_num:
        print(max_num)
    else:
        templist= copy.deepcopy(string_list)
        templist.remove(j)
        print(max(templist))

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
    if A > max2 and max1 > A :
        max2 = A
    if A == max1:
        cnt+=1
    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:
N = int(input())
A = [input() for i in range(N)]
ans = 0

wk = A[:]
wk.sort()
Max = wk[-1]

for i in range(N):
    ans = Max if A[i] == Max else wk[-2]
    print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

    index = sorted(range(len(A)), key=lambda k: A[k])
    value = sorted(A)

    # print(A)

    for i in range(N):
        if index[i] < N-1:
            print(value[N-1])
        else:
            print(value[N-2])

Submission status: Wrong Answer

Solution code:
i=input;p=print;n=int(i());a=[int(i())for _ in [0]*n];m=max(a);o=sorted(a)[-2];[[p(m)for _ in[0]*n]if m==o else[p(o)if a[i]==m else p(m)for i in[0]*n]]

Submission status: Wrong Answer

Solution code:
n = int(input())

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

#print(ls)

for i in li:
    j = 0
    while(j < n):
        #print("{}, {}.format(i,j))
        if(i != ls[j]):
            print(ls[j])
            break
        if (j == n-1):
            print(i)
        j+=1
    #print(max(p1,p2))

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []

for n in range(N):
    A.append([n, int(input())])
print(A)
As = sorted(A, reverse=True, key=lambda x: x[1])
print(As)
    

for n in range(N):
    i = 0    
    if n == 0:
        if A[0] == As[0]:
            print(As[1][1])
        else:           
            print(As[0][1])
    else:
        while i < n:
            if A[n] == As[i]:
                i+=1
                print(As[i][1])
                break

            elif A[n][1] > As[i][1]:
                    i += 1
            else:
                print(As[i][1])
                break

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n = int(input())
 
MAX = 0
MAX_index = []
MAX_sec = 0
for i in range(n):
    a = int(input())
    if i==0:
        MAX = a
        MAX_index.append(i)
        MAX_sec = a
        continue
    if MAX == a:
        MAX_index.append(i)
    elif MAX < a:
        MAX_index = [i]
        MAX = a
    elif MAX_sec < a:
        MAX_sec = a
    
#print(MAX_index)
        
if len(MAX_index)==1:
    for i in range(n):
        if i==MAX_index[0]:
            print(MAX_sec)
        else:
            print(MAX)
else:
    for i in range(n):
        print(MAX)

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
        if i == 0:
            max2 = A
        else:
            max2 = max1
        max1 = A
        maxi = i
    if A > max2 and max1 > A :
        max2 = A
    if A == max1:
        cnt+=1
    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:
s = int(input())
list =[]
for i in range(s):
  a=int(input())
  list.append(a)
d = max(list)
count=-1
for q in list:
  count +=1
  if q == d:
    list[count]=0
    print(max(list))
  else:
    print(d)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
ind_M = a.index(a_max)
tmpl = a
oth = tmpl.pop(ind_M)
for i in range(n):
    if i != ind_M:
        print(a_max)
    else:
        print(oth)

Submission status: Wrong Answer

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

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

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())
a = [int(input()) for i in range(n)]
a_r = a[::-1]
max_list = [max(a[:i + 1]) for i in range(n)]
max_list_r = [max(a_r[:i + 1]) for i in range(n)]

for i in range(n):
    print(max(max_list[i - 1], max_list_r[i - 1]))

Submission status: Wrong Answer

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

import math

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

    index = sorted(range(len(A)), key=lambda k: A[k])
    value = sorted(A)

    # print(A)

    for i in range(N):
        if index[i] < N-1:
            print(value[N-1])
        else:
            print(value[N-2])

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
max2 = 0
for t in a:
    if t > max2 and t < max1:
        max2 = t
check = 0
for q in range(n-1):
    if a[q] != a[q+1]:
        check = 1

if check == 0:
    max2 = max1

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

Submission status: Wrong Answer

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

n = 5
a = [1,2,3,4,5]

max1 = 0
max1_ind = 0
max2 = 0
max2_ind = 0
 
for i in range(n):
    if max2 <= a[i]:
        if max1 <= a[i]:
            max2 = max1
            max2_ind = max1_ind
            max1 = a[i]
            max1_ind = i
            
        else:
            max2 = a[i]
            max2_ind = i
    
for j in range(n):
    if j == max1_ind:
        print(max2)
    else:
        print(max1)
        
print(max1, max1_ind)
print(max2, max2_ind)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

b = sorted(a, reverse=True)


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    max_value = max(A)
    max_index = A.index(max_value)

    for i in range(N):
        if i != max_index:
            print(max_value)
        else:
            if i == 0:
                print(max(A[1:]))
            elif i == N - 1:
                print(max(A[:N]))
            else:
                print(max(max(A[:i]), max(A[i + 1 :])))

    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

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

print(A)

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())
A = [input() for i in range(N)]

S = sorted(A)
MAXS = max(S)
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)

Submission status: Wrong Answer

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


l_max = -1

r_max = max(lst[1:])
print(r_max)

flag = False

for i in range(1, n - 1):
    if lst[i] == r_max:
        r_max = max(lst[i + 1:])

    print(max(l_max, r_max))

    if lst[i] > l_max:
        l_max = lst[i]

if lst[n - 1] > l_max:
    l_max = lst[n - 1]


print(l_max)

Submission status: Wrong Answer

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

numset = set(arr)
maxval = max(numset)

if len(numset) == 1:
    for i in range(n):
        print(maxval)
else:
    numset.remove(maxval)
    semimax = max(numset)
    for i in range(n):
        if arr[i] == maxval and not arr[i] in arr:
            print(semimax)
        else:
            print(maxval)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=[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:
N=int(input())
L=[int(input()) for i in range(N)]
tl=sorted(L)
index1=L.index(tl[-1])
index2=L.index(tl[-2])
for i in range(N-1):
	if i==index1:
		print(L[index2])
	print(L[index1])

Submission status: Wrong Answer

Solution code:
import copy,numpy
n=int(input())
A=[int(input()) for _ in range(n)]
for i,_ in enumerate(A):
    print(numpy.max(A[:i-1]+A[i-1:]))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
for n in range(N):
    if n == 0:
        print(max(A[n + 1:]))
    elif n == N - 1:
        print(max(A[:n]))
    else:
        print(max(max(A[:n]), max(A[n:])))

Submission status: Wrong Answer

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


l_max = -1

r_max = max(lst[1:])
print(r_max)

flag = False

for i in range(1, n - 1):
    if lst[i] == r_max:
        r_max = max(lst[i + 1:])

    if lst[i] > l_max:
        l_max = lst[i]

    print(max(l_max, r_max))

if lst[n - 1] > l_max:
    l_max = lst[n - 1]


print(l_max)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
max_A = max(A)
for i in A:
    if i == max_A:
        if A.count(max_A) > 1:
            print(max_A)
        else:
            tmp = A.copy()
            sorted(tmp)
            print(tmp[-1*A.count(max_A)])
    else:
        print(max_A)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
max1 = 0
max1_ind = 0
max2 = 0
max2_ind = 0
 
for i in range(n):
    if max2 <= a[i]:
        if max1 <= a[i]:
            max1 = a[i]
            max1_ind = i
            max2 = max1
            max2_ind = max1_ind
        else:
            max2 = a[i]
            max2_ind = i
    
for j in range(n):
    if j == max1_ind:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

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

numset = set(arr)
maxval = max(numset)

if len(numset) == 1:
    for i in range(n):
        print(maxval)
else:
    numset.remove(maxval)
    semimax = max(numset)
    for i in range(n):
        if arr[i] == maxval:
            print(semimax)
        else:
            print(maxval)

Submission status: Wrong Answer

Solution code:
N=int(input())

max_index=-1
max_number=0
second_number=0
max_count=0
i=0
while(i<N):
    a=int(input())
    if(max_number<a):
        second_number=max_number
        
        max_number=a
        max_index=i
    elif(max_number==a):
        max_count+=1
        max_index=-1
    elif(second_number<a):
        second_number=a
    i+=1

j=0
while(j<N):
    if(j==max_index and max_count==0):
        print(second_number)
    else:
        print(max_number)
    j+=1

Submission status: Wrong Answer

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 and i!=max1:
        max2 = i
#print(max1,max2)                                                              
if max2 == 0:
    max2 = max1
for i in list:
    if i == max1:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:

n = int(input())
li = [0]*n
for i in range(n):
    li[i] = int(input())

max_ = max(li)
print(max_)
max_i = li.index(max_)
li.pop(max_i)
max2 = max(li)
res = [max_]*n
res[max_i] = max2

for a in res:
    print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
tmp = max(A)
li = [i for i, x in enumerate(A) if x == tmp]
li2 = list(set(A))
li2.sort(reverse=True)
if len(li2)>1:
    tmp2 = li2[1]
elif len(li2) == 1:
    tmp2 = li2[0]
for i in range(N):
    if li.count(i)==0:
        print(tmp)
    else:
        print(tmp2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
if len(R) >= 2:
  max_v2 = R[1]
  signal = 1
else:
  max_v2 = R[0]

for i in range(N):
  if A[i] == max_v:
    print(max_v2)
  else:
    print(max_v)

Submission status: Wrong Answer

Solution code:
N = int(input())
L=[]
i = 0
s = 0
for i in range (0,N):
    L.append(int(input()))
print(L)
i = 0
for i in range(0,N):
    F = L[0]
    for s in range(1,N):
        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 = []
for i in range(N):
    a.append(int(input()))
a_max = max(a[1:])
print(a_max)
for i in range(1,N-1):
    if(a[i]==a_max):
        a_max = max(a[:i])
        n_a_max = max(a[i+1:])
        if(a_max>=n_a_max):
            print(a_max)
        else:
            print(n_a_max)
    else:
        if(a[i-1]>a_max):
            print(a[i-1])
        else:
            print(a_max)
print(max(a[:N-1]))

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
        if i == 0:
          max2 = A
        max1 = A
        maxi = i
    if max1 > A > max2 :
        max2 = A
    if A == max1:
        cnt+=1
    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:
n = int(input())
list = []
for i in range(0,n):
  list.append(int(input()))
  
new_list = sorted(list, reverse=True)
for lst in new_list:
  print(lst)

Submission status: Wrong Answer

Solution code:
# ABC 134, C -
from operator import itemgetter

n = int(input())

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

B = sorted(A)
maxima, maxima_ind = B[len(B)-1], len(B)-1
sec_maxima, sec_maxima_ind = B[len(B)-2], len(B)-2




for i in range(n):
    if i == maxima_ind:
        print(sec_maxima)
    else:
        print(maxima)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array([int(input()) for _ in range(N)])
B = np.copy(A)
B = np.sort(B)[::-1]
a = A[np.where(B[0])]
for i in range(N):
    if i == a:
        print(B[1])
    else:
        print(B[0])

Submission status: Wrong Answer

Solution code:
n = int(input())

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

max_element = max(arr)
second_max = -12123122

for i in arr:
	if  i > second_max and i <= max_element:
		second_max = i

for i in arr:
	if i != max_element:
		print(max_element)
	else:
		print(second_max)

Submission status: Wrong Answer

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

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

max_value, max_cnt, sub_max = -1, 0, -1
for v in A:
	if v > max_value:
		sub_max = max_value
		max_value = v
		max_cnt = 1
	elif v == max_value:
		max_cnt += 1
	elif v > sub_max:
		sub_max = v

if max_cnt == 2:
	print('\n'.join([str(max_value)] * N))
else:
	for v in A:
		print('%d' % (max_value if v != max_value else sub_max))

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)
    else:
        print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

#print(ls)

for i in li:
    for j in ls:
        #print("{}, {}".format(i,j))
        if(i != j):
            print(j)
            break
    #print(max(p1,p2))

Submission status: Wrong Answer

Solution code:
data = input().split()
N = int(data[0])
A = [[int(line) for line in input()]for i in range(N)]

for i in range(N):
    tmp = A.pop(i)
    ans = max(A)[0]
    A.insert(i, tmp)
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a1 = max(a)

b = [x for x in a if x != a1]
if b == []:
    a2 = a1
else:
    a2 = max(b)

for ai in a:
    if ai == a1:
        print(a2)
    else:
        print(a1)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [0]*n
s = set()
f_max,s_max = 0,0
for i in range(n):
    a = int(input())
    l[i] = a
    
    if a not in s:
        s.add(a)

    #if f_max < a:
    #    s_max = f_max
    #    f_max = a
    #elif s_max < a < f_max:
    #    s_max = a

#s.sort()

if len(s)==1:
    for i in range(n):
        print(l[0])

    exit()

for i in range(n):
    #if l[i]==f_max:
    #    print(s_max)
    #else:
    #    print(f_max)
    #if l[i]==s[-1]:
    #    print(s[-2])
    #else:
    #    print(s[-1])
    s.remove(l[i])
    print(max(s))
    s.add(l[i])

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
a_list = []
for _ in range(N):
    a_list.append(int(input()))
inds = list(np.argsort(a_list))
for i in range(N):
    tmp = inds.copy()
    tmp[i] = -1
    print(a_list[np.argmax(tmp)])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(list(set(a[:])),reverse=True)
maxa=aa[0]
for i in range(n):
    if a[i] == maxa:
        print(aa[1] if len(aa) != 1 else maxa)
    else:
        print(maxa)

Submission status: Wrong Answer

Solution code:
import sys
N = int(sys.stdin.readline().strip())
sequence = []
biggest = 0
for i in range(N):
    x = int(sys.stdin.readline().strip())
    biggest = max(biggest, x)
    sequence.append(x)

for i in range(N):
    if sequence[i] == biggest:
        print(max(sequence[:i] + sequence[min(N-1,i+1):]))
    else:
        print(biggest)

Submission status: Wrong Answer

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

la=sorted(a)
re=la[-2]
check=max(a)

x=a.count(check)

for i in range(n):
    if a[i]==check:
        if x>1:
            print(check)
        if x==1:
            print(re)
    else:
        print(check)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

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

    print(max)

Submission status: Wrong Answer

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


A_hash = {}
for i in range(N):
        if A[i] in A_hash:
                A_hash[A[i]] += 1
        else:
                A_hash[A[i]] = 1


A_max = max(A)
A_second_max = list(A_hash.keys())
A_second_max.sort()

if len(A_second_max) > 1:
        A_second_max = A_second_max[1]
else:
        A_second_max = A_second_max[0]

for i in range(N):
        if A[i] == A_max:
                if A_hash[A_max] == 1:
                        print(A_second_max)
                else:
                        print(A_max)
        else:
                print(A_max)

Submission status: Wrong Answer

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

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

for i in range(N):
    k = max(A)
    if k != A[i]:
        print(k)
    else:
        j = A.pop(i)
        print(k)
        A.insert(i,j)

Submission status: Wrong Answer

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

normal = max(A)
hoge = A.copy()
hoge.remove(normal)
exception = max(hoge)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for _ in range(N):
    A.append(input())

max_list = sorted(A, reverse=True)
max_index = A.index(max(A))

for i in range(0, len(A)):
    if i == max_index:
        print(max_list[1])
    else:
        print(max_list[0])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())

a = []
b = set()
for _ in range(n):
    tmp = int(input())
    a.append(tmp)
    b.add(tmp)

max_num = max(b)
c = b - {max_num}
if len(c) == 0:
    second_max_num = max_num
else:
    second_max_num = max(c)

for elem in a:
    if not elem == max_num:
        print(max_num)
    else:
        print(second_max_num)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

max_element = max(arr)
second_max = -12123122

for i in arr:
	if i != max_element and i > second_max:
		second_max = i

if second_max == -12123122:
	second_max = max_element

for i in arr:
	if i != max_element:
		print(max_element)
	else:
		print(second_max)

Submission status: Wrong Answer

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

arg_sorted = list(set(arg))
arg_sorted.sort(reverse=True)

for val in arg:
  if val == arg_sorted[0] and len(arg_sorted) >= 2:
    print(arg_sorted[1])
  else:
    print(arg_sorted[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
l1 = []
l2 = []
for i in range(n):
    l1.append(int(input()))
l2 = sorted(l1)
for i in range(n):
    m = max(l1)
    if (m == l1[i]):
        print(l2[1])
    else:
        print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

l_max = -1

r_max = max(lst[1:])
print(r_max)

flag = False

for i in range(1, n - 1):
    if lst[i] == r_max:
        r_max = max(lst[i + 1:])

    if lst[i] == l_max:
        flag = True
        l_max = max(lst[:i])

    print(max(l_max, r_max))

if lst[n - 1] == l_max:
    l_max = max(lst[:n - 1])

if not flag:
    l_max = max(lst[:n - 1])


print(l_max)

Submission status: Wrong Answer

Solution code:

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for i in range(n):
  if a[i] != aMax:
    print(aMax)
  else:
    if i == 0:
      aMax1=max(a[1:n])
      print(aMax1)
    else:
      aMax2=max(a[0:i],a[i+1:n])
      print(aMax2[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [input() for i in range(N)]
maxA = max(A)
secA = sorted(A)[-2]
num=A.count(maxA)
#print(N,A,maxA,secA,num)

for i in range(N):
  if num>1:
    print(maxA)
  elif A[i]==maxA:
    print(secA)
  else:
    print(maxA)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
max1 = 0
max1_ind = 0
max2 = 0
max2_ind = 0
 
for i in range(n):
    if max2 < a[i]:
        if max1 < a[i]:
            max1 = a[i]
            max1_ind = i
            max2 = max1
            max2_ind = max1_ind
        else:
            max2 = a[i]
            max2_ind = i
    
for j in range(n):
    if j == max1_ind:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

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

llss=ls
llss.sort()

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

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)
if n==1:
  print(m)
else:
  k=a.index(m)
  a.remove(m)
  if m==max(a):
    for j in range(n):
      print(m)
  else:
    for j in range(k):
      print(m)
    print(max(a))
    for t in range(n-k-1):
      print(m)