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:
n = int(input())
suretsu0 = []

biggest_num = 0
secondly_biggest_num=0
for i in range(n):
    a = int(input())
    suretsu0.append(a)

suretsu = [x for x in suretsu0]
suretsu.sort()


biggest_num = suretsu[-1]
secondly_biggest_num=biggest_num

for i in reversed(range(len(suretsu))):
    if suretsu[i]==biggest_num:
        pass
    else:
        secondly_biggest_num = suretsu[i]
        break


for ele in suretsu0:
    if ele==biggest_num:
        print(secondly_biggest_num)
    else:
        print(biggest_num)

Submission status: Wrong Answer

Solution code:

import math




def main():
    n = int(input())
    lista = []
    for i in range(0, n):
        lista.append(int(input()))
    maxim1 = -999999
    maxim2 = -9999999
    for element in lista:
        if element > maxim1:
            maxim2 = maxim1
            maxim1 = element
        elif element < maxim1 and element > maxim2:
            maxim2 = element
    
    for element in lista:
        if element == maxim1:
            print(maxim2)
        else:
            print(maxim1)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

import math




def main():
    n = int(input())
    lista = []
    for i in range(0, n):
        lista.append(int(input()))
    print(lista)
    maxim1 = -999999
    maxim2 = -9999999
    for element in lista:
        if element > maxim1:
            maxim2 = maxim1
            maxim1 = element
        elif element < maxim1 and element > maxim2:
            maxim2 = element
    
    for element in lista:
        if element == maxim1:
            print(maxim2)
        else:
            print(maxim1)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

import math




def main():
    n = int(input())
    lista = []
    for i in range(0, n):
        lista.append(int(input()))
    print(lista)
    maxim1 = -999999
    maxim2 = -9999999
    for element in lista:
        if element > maxim1:
            maxim2 = maxim1
            maxim1 = element
        elif element < maxim1 and element > maxim2:
            maxim2 = element
    
    for element in lista:
        if element == maxim1:
            print(maxim1)
        else:
            print(maxim2)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def func():
    input_num = int(input(''))
    a_i = [int(input('')) for i in range(input_num) ]
    frag, count = True, 0
    for i in range(input_num):
        if a_i[0] == a_i[i]:
            count += 1
    if count == input_num:
         frag = False
    if frag == True:
        value = [[a_i[i] if a_i[i] != a_i[j] else 0 for i in range(input_num )] for j in range(input_num)]
    else:
        value = [[a_i[i]for i in range(input_num )] for j in range(input_num)]
    for i in range(input_num):
        print(max(value[i]))
if __name__ == '__main__':
    func()

Submission status: Wrong Answer

Solution code:
def func():
    input_num = int(input(''))
    a_i = [0]*input_num
    for i in range(input_num):
        a_i[i] = int(input(''))
    frag, count = True, 0
    for i in range(input_num):
        if a_i[0] == a_i[i]:
            count += 1
    if count == input_num:
         frag = False
    if frag == True:
        value = [[a_i[i] if a_i[i] != a_i[j] else 0 for i in range(input_num )] for j in range(input_num)]
    else:
        value = [[a_i[i]for i in range(input_num )] for j in range(input_num)]
    for i in range(input_num):
        print(max(value[i]))
if __name__ == '__main__':
    func()

Submission status: Wrong Answer

Solution code:
#134

N = int(input())
A_max = 0
A_max_s = 0
flag = 0
A = []

for i in range(N):
    a = int(input())
    A.append(a)
    if a > A_max:
        A_max_s = A_max
        A_max = a
        ind_max = i
    elif A_max_s < a < A_max:
        A_max_s = a
    elif a == A_max:
        flag += 1
        
if flag >= 1:
    for i in range(N):
        print(A_max)
elif flag == 0:
    for i in range(N):
        if i != ind_max:
            print(A_max)
        else:
            print(A_max_s)

Submission status: Wrong Answer

Solution code:
#134

N = int(input())
A_max = 0
A_max_s = 0
flag = 0
A = []

for i in range(N):
    a = int(input())
    A.append(a)
    if a > A_max:
        A_max = a
        ind_max = i
    elif A_max_s < a < A_max:
        A_max_s = a
    elif a == A_max:
        flag += 1
        
if flag >= 1:
    for i in range(N):
        print(A_max)
elif flag == 0:
    for i in range(N):
        if i != ind_max:
            print(A_max)
        else:
            print(A_max_s)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf8 -*-

n = int(input())
l = [int(input()) for _ in range(n)]
m = sorted(l)[-1]
for i in range(n):
    if l[i] != m:
        print(m)
    else:
        print(max(l[:i] + l[:i+1]))

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
A = [int(input()) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
A_copy = copy.deepcopy(A)
A_copy.sort(reverse=True)
Max = max(A)
if len(set_A) == 1:
    for i in range(len(set_A)):
        print(Max)
    exit()
for i in range(N):
    if A[i] == Max:
        print(A_copy[1])
    else:
        print(Max)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
Max = max(A)
if len(set_A) == 1:
    for i in range(len(set_A)):
        print(Max)
    exit()
for i in range(N):
    if A[i] == Max:
        print(set_A[1])
    else:
        print(Max)

Submission status: Wrong Answer

Solution code:
N = raw_input()
counter = 0
num_array = []
while counter < int(N):
  num_array.append(int(raw_input()))
  counter += 1
counter = 0  
while counter < int(N):
  idx_0 = (counter + (int(N) - 1)) % int(N)
  idx_1 = (counter + 1) % int(N)
  print max(num_array[idx_0], num_array[idx_1])
  counter += 1

Submission status: Wrong Answer

Solution code:
x = int(input())
a = []
b= []
for i in range(x):
  a.append(int(input()))
  
for i in range(x):
  b=a
  b[i]=0
  print(max(b))

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = []
max_num = 0
sub_max = 0
all_max = False
for i in range(n):
    a = int(input())
    if sub_max < a:
        if max_num < a:
            sub_max = max_num
            max_num = a
            idx = i
        else:
            if max_num == a:
                max_num = a
                all_max = True
            else:
                sub_max = a
if all_max:
    for i in range(n):
        print(max_num)
else:
    for i in range(n):
        if i == idx:
            print(sub_max)
        else:
            print(max_num)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = []
max_num = 0
sub_max = 0
all_max = False
for i in range(n):
    a = int(input())
    a_list.append(a)
    if sub_max < a:
        if max_num < a:
            sub_max = max_num
            max_num = a
            idx = i
        else:
            sub_max = a
    elif max_num == a:
        max_num = a
        all_max = True
if all_max:
    for i in range(n):
        print(max_num)
else:
    for i in range(n):
        if i == idx:
            print(sub_max)
        else:
            print(max_num)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
s = max(a)
if a.count(s) >= 2:
  print(s)
else:
  for i in range(n):
    l = a.copy()
    l[i] = 0
    print(max(l))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = sorted({i: int(input()) for i in range(N)}.items(), key=lambda x: x[1])
    print(A)
    for index in range(N):
        if not A[-1][0] == index:
            print(A[-1][1])
        else:
            print(A[-2][1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
m1,m2 = sorted(A)[-2:]

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

Submission status: Wrong Answer

Solution code:
n=int(input())
lis=list(int(input()) for _ in range(n))
lis2=lis
lis2=sorted(lis2)
MAX=lis2[-1]
second=lis2[-2]
if lis.count(MAX) ==1:
    lis3=[MAX for _ in range(n)]
    lis3[lis.index(MAX)]=second
    print("YES")
    for i in range(n):
        print(lis3[i])
        
else:
    for _ in range(n):
        print(MAX)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
l, r = [1] * n, [1] * n
for i in range(1, n):
	l[i] = max(l[i - 1], a[i])
for i in range(n - 2, -1, -1):
	r[i] = max(r[i + 1], a[i])
l[0] = max(l[0], a[0])
r[-1] = max(r[-1], a[-1])
for i in range(n):
	if i == 0:
		print(r[i])
	elif i == n - 1:
		print(l[i])
	else:
		print(max(l[i - 1], r[i + 1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
l, r = [1] * n, [1] * n
for i in range(1, n):
	l[i] = max(l[i - 1], a[i])
for i in range(n - 2, -1, -1):
	r[i] = max(r[i + 1], a[i])
l[0] = max(l[0], a[0])
r[-1] = max(r[-1], a[-1])
print(r[1])
for i in range(1, n - 1):
	print(max(l[i - 1], r[i + 1]))
print(l[-2])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
l, r = [1] * n, [1] * n
for i in range(1, n):
	l[i] = max(l[i - 1], a[i])
for i in range(n - 2, -1, -1):
	r[i] = max(r[i + 1], a[i])
l[0] = max(l[0], a[0])
r[-1] = max(r[-1], a[-1])
print(r[0])
for i in range(1, n - 1):
	print(max(l[i - 1], r[i + 1]))
print(l[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
l, r = [1] * n, [1] * n
for i in range(1, n):
	l[i] = max(l[i - 1], a[i])
for i in range(n - 2, -1, -1):
	r[i] = max(r[i + 1], a[i])
l[0] = max(l[0], a[0])
r[-1] = max(r[-1], a[-1])
print(*l)
print(*r)
print(r[0])
for i in range(1, n - 1):
	print(max(l[i - 1], r[i + 1]))
print(l[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
l, r = [1] * n, [1] * n
for i in range(1, n):
	l[i] = max(l[i], a[i - 1])
for i in range(n - 2, -1, -1):
	r[i] = max(r[i], a[i + 1])
for i in range(n):
	print(max(l[i], r[i]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
l, r = [0] * n, [0] * n
for i in range(1, n):
	l[i] = max(l[i], a[i - 1])
for i in range(n - 2, -1, -1):
	r[i] = max(r[i], a[i + 1])
for i in range(n):
	print(max(l[i], r[i]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
res = [0] * n
for i in range(1, n):
	res[i] = max(res[i], a[i - 1])
for i in range(n - 2, -1, -1):
	res[i] = max(res[i], a[i + 1])
for i in range(n):
	print(res[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
ans_1 = max(A)
tmp = set(A)
if len(tmp) >= 2:
    tmp.discard(max(tmp))
ans_2 = max(tmp)

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

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
a2 = sorted(a)[-2:]
for i in range(n):
    if a[i]==a2[1]:
        print(a[0])
    else:
        print(a[1])

Submission status: Wrong Answer

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

for i in range(1, N):
  B[i] = max(B[i-1],A[i])
  print(B[i])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s=[''.join(input()) for i in range(n)]
s_sort=sorted(s,reverse=True)
for i in range(n):
    if s[i] == s_sort[0]:
        print(s_sort[1])
    else:
        print(s_sort[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
s=[''.join(input()) for i in range(n)]
s_sort=sorted(s,reverse=True)
for i in range(n):
    if s[i] == s_sort[0]:
        print(s_sort[1])
    else:
        print(s_sort[0])

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
# n = 3

arr = [0]*n

pq = []
for i in range(n):
	arr[i] = int(input())
	heapq.heappush(pq, (-arr[i], i))
heapq.heapify(pq)
lg = heapq.heappop(pq)
slg = heapq.heappop(pq)
print(lg, slg)
lg, slg = lg[1], slg[1]

for i in range(n):
	if i==lg:
		print(arr[slg])
	else:
		print(arr[lg])

Submission status: Wrong Answer

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

lg = 0

arr = [0]*n

for i in range(n):
	arr[i] = int(input())
	if i==0:
		lg = i 
	elif i==1:
		if arr[lg] > arr[i]:
			slg = lg
			lg = i 
		else:
			slg = i			
	elif arr[i] >= arr[lg]:
		slg = lg
		lg = i
	elif arr[i] >= arr[slg]:
		slg = i 


for i in range(n):
	if i==lg:
		print(arr[slg])
	else:
		print(arr[lg])

Submission status: Wrong Answer

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

lg, slg = 0, 0

arr = [0]*n

for i in range(n):
	arr[i] = int(input())
	if i==0:
		lg = i 
	elif arr[i] >= arr[lg]:
		slg = lg
		lg = i
	elif arr[i] >= arr[slg]:
		slg = i 


for i in range(n):
	if i==lg:
		print(arr[slg])
	else:
		print(arr[lg])

Submission status: Wrong Answer

Solution code:
#また長さが1の時を考慮していない
n=int(input())
a=[int(input()) for i in range(n)]
m=max(a)
if len(a)!=1:
    a2=sorted(a)[1]
else:
    a2=a[0]
for i in range(n):
    if m==a[i]:
        print(a2)
    else:
        print(m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

b = [ 0 if i == max(a) else i for i in a ]
if max(b) == 0:
    b = [ max(a) if i == max(a) else i for i in a ]

ans = [ max(b) if i == max(a) else max(a) for i in a ]
for j in ans:
    print(j)

Submission status: Wrong Answer

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

b = [ 0 if i == max(a) else i for i in a ]
if max(b) == 0:
    b = [ max(a) if i == max(a) else i for i in a ]

print([ max(b) if i == max(a) else max(a) for i in a ])

Submission status: Wrong Answer

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

b = [ 0 if i == max(a) else i for i in a ]

print([ max(b) if i == max(a) else max(a) for i in a ])

Submission status: Wrong Answer

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

for j in range(n):
  temp = a[j]
  a.remove(a[j])
  print(max(a))
  a.append(temp)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
li = list(int(stdin.readline().rstrip()) for _ in range(n))
one = max(li)
two = li[-2]
for i in range(n):
    if max(li) == li[i]:
        print(two)
    else:
        print(one)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(int(stdin.readline().rstrip()) for _ in range(n))

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

Submission status: Wrong Answer

Solution code:
N=int(input())
l=[]
for i in range(N):
  l.append(int(input()))
i=l.index(max(l))
if i==0:
  l1=l[1:]
  print(max(l1),max(l)*(N-1),sep='\n')
elif i==N:
  l1=l[:N]
  print(max(l)*(N-1),max(l1),sep='\n')
else:
  l1=l[:i]+l[i+1:]
  print(max(l)*(i),max(l1),max(l)*(N-i-1),sep=('\n'))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(input())
    
A_sorted = sorted(A)
A_max1 = A_sorted[-1]
A_max2 = A_sorted[-2]

if A_max1 == A_max2:
    for i in range(N):
        print(A_max1)
else:
    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 = sorted([(int(input()), i) for i in range(n)],
           key=lambda a: a[0])
for i in range(n):
    j = 0
    while A[j][1] == i:
        j += 1
    print(A[j][0])

Submission status: Wrong Answer

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

maxa = 0
maxa1 = 0
maxcnt = 0
for i in range(n):
    ai = int(input())
    a.append(ai)
    if maxa < ai:
        maxa1 = maxa
        maxa = ai
        maxcnt = 0
    elif maxa == ai:
        maxcnt += 1

for i in range(n):
    if a[i] == maxa:
        if maxcnt > 0:
            print(maxa)
        else:
            print(maxa1)
    else:
        print(maxa)

Submission status: Wrong Answer

Solution code:

N = int(input())

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

B = A.copy()

B = sorted(B)

max = B[-1]
n_max = B[-2]


for a in A:
    if a < max:
        print(max)
    else:
      print(n_max)

Submission status: Wrong Answer

Solution code:

N = int(input())

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

B = A.copy()

B = sorted(B)

max = B[-1]
n_max = B[-2]

for a in A:
    if a == max:
        print(n_max)
    else:
        print(max)

Submission status: Wrong Answer

Solution code:

N = int(input())

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

B = A.copy()

B = sorted(B)

max = B[-1]
n_max = B[-2]


for a in A:
    if a == max:
        print(n_max)
    else:
        print(max)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

m = max(A)
flag = 1
for n in range(N):
    if A[n] == m and flag == 1:
        print(A[n])
        flag = 0
    
    print(m)

Submission status: Wrong Answer

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

k = [i for i, x in enumerate(a) if x == m]

if len(k)>=2:
	for i in a:
		print(m)
else:
	b = []
	b += a
	mi = b.index(m)
	b.pop(mi) 
	print(a)
	m2 = max(b)
	for i in a:
		if i != m:
			print(m)
		else:
			print(m2)

Submission status: Wrong Answer

Solution code:
import copy

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

chinpo = max(A)
B = copy.copy(A)
B.remove(max(A))
chinchin = max(B)

for i in range(A.index(max(A))-1):
    print(chinpo)
print(chinchin)
for i in range(A.index(max(A)),N):
    print(chinpo)

Submission status: Wrong Answer

Solution code:
import copy

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

chinpo = max(A)
B = copy.copy(A)
B.remove(max(A))
chinchin = max(B)

for i in range(A.index(max(A))-1):
    print(chinpo)
print(chinchin)
for i in range(A.index(max(A))+1,N):
    print(chinpo)

Submission status: Wrong Answer

Solution code:
import time
import numpy as np
t1 = time.time()
n = int(input())
a = [int(input()) for i in range(n)]

t2 = time.time()
b = np.array([max(set(a[:x]+a[x+1:])) for x in range(len(a))])

c = b.reshape(n,1)

print(c)

t3 = time.time()
'''
s = str()
for i in b:
	s += str(i)+'\n'
	
print(s)
'''
#t4 = time.time()
'''
print(t2-t1)
print(t3-t2)
print(t4-t3)
'''

Submission status: Wrong Answer

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

max = max(a)
tmp = sorted(set(a))
if len(tmp) > 1:
    max2 = tmp[-2]
else:
    max2 = max

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

Submission status: Wrong Answer

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

max = max(a)
tmp = sorted(set(a))
if len(tmp) > 1:
    max2 = a[-2]
else:
    max2 = max

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

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = []
for i in range(N):
    lst.append(int(input()))
lst = sorted(lst)

for i in range(N):
    ans = lst[:i] + lst[i+1:]
    print(ans[-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
a_max = max(a)
a_max_index = [i for i,x in enumerate(a) if x == a_max] 

if len(set(a)) == 1:
    a_second = a[0]
else:
    a_second = sorted(set(a))[-2]
for i in range(n):
    if i in a_max_index:
        print(a_second)
    else:
        print(a_max)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
a_max_index = [i for i,x in enumerate(a) if x == max(a)] 

if len(set(a)) == 1:
    a_second = a[1]
else:
    a_second = sorted(set(a))[-2]
for i in range(n):
    if i in a_max_index:
        print(a_second)
    else:
        print(max(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
b = list(map(lambda x:max(set(a[:x]+a[x+1:])),a))
for i in b:
	print(i)

Submission status: Wrong Answer

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

for num in a:
  print(max(a))

Submission status: Wrong Answer

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

for num in a:
  if len(list(a_set))==1:
    print(max(a))
  elif num==list(a_set)[-1]:
    print(list(a_set)[-2])
  else:
    print(max(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
a_lst = [0]*n
max = sec_max = 0
a_lst[0] = int(input())

for i in range(1, n):
    a_lst[i] = int(input())
    if a_lst[i] > a_lst[max]:
        max = i
    elif a_lst[i] > a_lst[sec_max]:
            sec_max = i

for i in range(n):
    if i == max:
        print(a_lst[sec_max])
    else:
        print(a_lst[max])

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
a = list(map(int,[input() for i in range(n)]))
a_sorted =copy.copy(a)
a_sorted.sort()
if len(set(a))!=1:
  sec_big=list(set(a))[-2]
else:
  sec_big=list(set(a))[-1]

for num in a:
  if num == max(a):
    print(sec_big)
  else:
    print(max(a))

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.deepcopy(a)
  del b[i]
  sorted(b)
  print(b[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(input()) for i in range(N)]
for i in range(N-1):
  b = a
  del b[i]
  sorted(b)
  print(b[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
max_A = max(A)
max_num = 0
for i in range(N):
    if A[i] == max_A:
        # 最大値が複数ある場合の計算削減
        max_num += 1
        if max_num > 1:
            print(max_num)
        else:
            print(max(A[:i] + A[i + 1:]))
    else:
        print(max_A)

Submission status: Wrong Answer

Solution code:
import math


def solve():
    n = int(input())
    al = [int(input()) for _ in range(n)]
    l = list(set(al))
    l.sort()
    if len(l) == 1:
        f, s = l[0], l[0]
    else:
        f, s = l[-1], l[-2]
    for a in al:
        if a == f:
            print(s)
        else:
            print(f)

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

max_1,max_2 = sorted(Alist)[-2:]
for A in Alist:
    if A==max_1:
        print(max_2)
    else:
        print(max_1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
tmp = 0
for i in range(N):
    if A[i] > A[tmp]:
        tmp = i
B = sorted(A)
k = A[tmp]
answer = [k]*N
A[tmp] = B[0]
C = sorted(A)
answer[tmp] = A[-1]

print(*answer, sep="\n")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
tmp = 0
for i in range(N):
    if A[i] > A[tmp]:
        tmp = i
B = sorted(A)
answer = [A[tmp]]*N
A[tmp] = B[0]
C = sorted(A)
answer[tmp] = A[-1]

print(*answer, sep="\n")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
M=max(a)
indexes=[j for j,x in enumerate(a) if x==M]
for k in range(n):
  if a[k]==M and len(indexes)==1:
    if k==0:
      print(max(a[1:]))
    if k==n-1:
      print(max(a[:n-1]))
    else:
      print(max(a[:k]+a[k+1:]))
  else:
    print(M)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
tmp = sorted(a)
mx = max(a)
cnt = a.count(mx)

for t in a:
    if t == mx and cnt < len(a):
        print(tmp[-cnt-1])
    else:
        print(mx)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
tmp = sorted(a)
mx = max(a)
cnt = a.count(mx)

for t in a:
    if t == mx and -cnt-1 > len(a):
        print(tmp[-cnt-1])
    else:
        print(mx)

Submission status: Wrong Answer

Solution code:
import sys
import copy
def input():
	return sys.stdin.readline().rstrip()
def main():
	N = int(input())
	A = [int(input()) for _ in range(N)]
	B = list(set(A))
	if (len(B) == 1) or (A.count(B[-1]) > 1):
		for i in range(N):
			print(B[0])
	else :
		for i in range(N):
			if A[i] == B[-1]:
				print(B[-2])
			else:
				print(B[-1])
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys
import copy
def input():
	return sys.stdin.readline().rstrip()
def main():
	N = int(input())
	A = [int(input()) for _ in range(N)]
	B = list(set(A))
	print(A.count(B[-1]))
	if (len(B) == 1) or (A.count(B[-1]) > 1):
		for i in range(N):
			print(B[0])
	else :
		for i in range(N):
			if A[i] == B[-1]:
				print(B[-2])
			else:
				print(B[-1])
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys
import copy
def input():
	return sys.stdin.readline().rstrip()
def main():
	N = int(input())
	A = [int(input()) for _ in range(N)]
	B = list(set(A))
	if len(B) == 1 or A.count(B[-1]) > 1:
		for i in range(N):
			print(B[0])
	else :
		for i in range(N):
			if A[i] == B[-1]:
				print(B[-2])
			else:
				print(B[-1])
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys
import copy
def input():
	return sys.stdin.readline().rstrip()
def main():
	N = int(input())
	A = [int(input()) for _ in range(N)]
	B = list(set(A))
	if len(B) == 1:
		for i in range(N):
			print(B[0])
	elif len(B) > 1:
		for i in range(N):
			if A[i] == B[-1]:
				print(B[-2])
			else:
				print(B[-1])
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys
import copy
def input():
	return sys.stdin.readline().rstrip()
def main():
	N = int(input())
	A = [int(input()) for _ in range(N)]
	B = list(set(A))
	if len(B) == 1:
		for i in range(N):
			print(B[0])
	else :
		for i in range(N):
			if A[i] == B[-1]:
				print(B[-2])
			else:
				print(B[-1])
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

A=max(sequence)
max_index_list=[]
while A in sequence:
    b=sequence.index(A)
    max_index_list.append(b)
    sequence.pop(b)
C=len(max_index_list)

answer=[A]*N
if C!=N:
    for i in range (0,C):
        answer[max_index_list[i]]=max(sequence)
for i in range (0,N):
    print(answer[i])

Submission status: Wrong Answer

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

A=max(sequence)
max_index_list=[]
while A in sequence:
    b=sequence.index(A)
    max_index_list.append(b)
    sequence[b]=0
print(sequence)
C=len(max_index_list)

Sequence=tuple(sequence)
for i in range(0,N):
    sequence2=list(Sequence)
    sequence2.pop(i)
    if i in max_index_list and C==1:
        print(max(sequence2))
    else:
        print(A)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import glob
import numpy as np
import collections


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\134\\C'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'


class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class C(Common):

    def resolve(self):

        seq_len = int(self.input_data())
        seq = np.zeros(seq_len, dtype=np.int)
        for i in range(seq_len):
            seq[i] = int(self.input_data())

        max_num = np.max(seq)
        times = collections.Counter(seq)[max_num]

        print(collections.Counter(seq))

        if times >= 2:
            for i in range(seq_len):
                print(str(max_num))
        else:
            for i in range(seq_len):
                if seq[i] != max_num:
                    print(str(max_num))
                else:
                    print(np.max(np.hstack((seq[0:i], seq[i+1:seq_len]))))


solver = C(REL_PATH)
solver.exec_resolve()