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 math

def main():
    N = int(input())
    A = []
    ma1 = 0
    ma2 = 0
    for i in range(N):
        a = int(input())
        A.append(a)
        if i == 1:
            ma2 = min(a, ma1)
        if A[ma2] <=  a:
            if A[ma1] <= a:
                ma2 = ma1
                ma1 = i
            else:
                ma2 = i
    # print(ma, ma2)
    for i in range(N):
        if ma1 == i:
            print(A[ma2])
        else:
            print(A[ma1])
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a =int(input())
b=int(input())
if a==b:
    if N==2:
        max1= a
        max2 = a
    else:
        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)                                                              
for i in list:
    if i == max1:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

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

sorted_list = sorted(arr)
max = sorted_list[N-1]
sub_max = sorted_list[N-2]
max_count = arr.count(max)
print(max,sub_max,max_count)

if max_count == 1:
    max_index = arr.index(max)
    for i in range(N):
        if i == max_index:
            print(sub_max)
        else:
            print(max)
else:
    for _ in range(N):
        print(max)

Submission status: Wrong Answer

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

FIRST = max(A)
A_ = [a for a in A if a != FIRST]
if A_:
    SECOND = max([a for a in A if a != FIRST])
    for a in A:
        if a == FIRST:
            print(SECOND)
        else:
            print(FIRST)
else:
    for i in range(N):
        print(FIRST)

Submission status: Wrong Answer

Solution code:
first = 1
second = 1
s = 0
n=int(input())
x = []
for i in range(0,n):
    s = int(input())
    if first <= s:
        second = first
        first = s
    if second <= s:
        second = s
    x.append(s)

for i in range(0,n):
    if x[i] == first:
        print(second)
    else:
        print(first)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ret = []
seta = set(a)
maxa1 = max(seta)
if len(seta) != 1:
    seta.remove(maxa1)
    maxa2 = max(seta)
else:
    maxa2 = maxa1

for i in range(n):
    if a[i] == maxa1:
        print(maxa2)
    else:
        print(maxa1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
    
maxa = 0
for i in range(n):
    if n == 0:
        maxa = a[1:]
        print(maxa)
    else:
        if maxa > a[i]:
            print(maxa)
        else:
            if i < n-1: 
                maxa = max(a[:i-1]+a[i+1:])
            else:
                maxa = max(a[:n-1])
            print(maxa)

Submission status: Wrong Answer

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

sort_A = sorted(A)
max = sort_A[N - 1]
sec = sort_A[N - 2]

count = A.count(max)

if count == 1:
  p = A.index(max)
  
  for i in range(p):
    print(max)
  
  print(sec)
  
  for j in range(p,N - 1):
    print(max)

else:
  for k in range(N):
    print(max)

Submission status: Wrong Answer

Solution code:
import sys
from heapq import heappop,heappush,heapify

input=sys.stdin.readline

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

que=list(set(a))
heapify(que)


for i in range(n):
    v=heappop(que)
    if a[i]==v and que:
        v2=heappop(que)
        print(-v2)
        heappush(que,v2)
    else:
        print(-v)
    heappush(que,v)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
max1 = 0
max2 = 0
for j in a:
    if j >= max1:
        max2 = max1
        max1 = j

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 _ in range(n)]

for i in range(n):
  temp = a
  temp[i] = 0
  print(max(temp))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:

N = int(input())
A_lst = []
max_num = -1
max_index_lst = []
next_num = -1

for i in range(N):
    Ai = int(input())
    A_lst.append(Ai)
    if max_num == -1:
        max_num = Ai
        max_index_lst.append(i)
    elif next_num == -1:
        if max_num > Ai:
            next_num = Ai
        else:
            next_num = max_num
            max_num = Ai

    elif max_num <= Ai:
        if max_num == Ai:
            max_index_lst.append(i)
        else:
            max_index_lst = [i]
        next_num = max_num
        max_num = Ai

    
    elif next_num < Ai:
        next_num = Ai
#print()
ans_lst = [max_num]*N

if len(max_index_lst) == 1:
    ans_lst[max_index_lst[0]] = next_num

for i in ans_lst:
    print(i)

Submission status: Wrong Answer

Solution code:
import copy
n=input()
n=int(n)
A=[]
for i in range(n):
  A.append(input())
a=[int(j) for j in A]
a_copy=copy.deepcopy(a)
answer=[]
for i in range(n):
  a.pop(i)
  answer.append(max(a))
  a=copy.deepcopy(a_copy)
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

temp = sorted(arr)

max_element = temp[-1]

second_max = max_element

i = n - 2
while i >= 0 and second_max == max_element:
	second_max = temp[i]
	i -= 1

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

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

Submission status: Wrong Answer

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


for d in range(s):
  list_2=list
  x = list_2[0]
  list_2.remove(x)
  print(list_2)
  print(max(list_2))
  list_2.append(x)

Submission status: Wrong Answer

Solution code:

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

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

for i in range(N):
    if A[i] == MAXS:
        count = S.count(A[i])

        if count > 1:
            print(S[-1])
        else:
            print(S[-2])
    else:
        print(S[-1])

Submission status: Wrong Answer

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

sortA = sorted(A, reverse=True)

if sortA[0] == sortA[1]:
    for i in range(N):
        print(A[0])
else:
    nextP = A.index(sortA[0])
    for i in range(nextP):
        print(sortA[0])
    print(sortA[1])
    for i in range(nextP+1, N):
        print(sortA[0])

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 max1 < a[i]:
        max1= a[i]
        max1_ind = i
        max2 = max1
        max2_ind = max1_ind
    
for j in range(n):
    if j == max1_ind:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[input() for _ in range(N)]
B=sorted(A)
maximum=A.index(max(A))
for i in range(N):
    if i==maximum:
        print(B[-2])
    else:
        print(B[-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()))

    for i in range(N):
        b = [current_max] + A[i+1:]
        maxb = max(b)
        print(maxb)
        if maxb > current_max:
            current_max = maxb

Submission status: Wrong Answer

Solution code:
N=int(input())
max1=0
max2=0
for i in range(N):
    A=int(input())
    if A > max1:
        if i == 0:
          max2 = A
        max1 = A
        maxi = i
    if max1 > A > max2 :
        max2 = A

if 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=[0]*n
for i in range(n):
    a[i]=input()
b=sorted(a)
for i in range(n):
    if a[i]!=b[n-1]:
        print (b[n-1])
    else:
        print(b[n-2])

Submission status: Wrong Answer

Solution code:
import math

def main():
    N = int(input())
    A = []
    ma1 = 0
    ma2 = 0
    for i in range(N):
        a = int(input())
        A.append(a)
        if A[ma2] <=  a:
            if A[ma1] <= a:
                ma2 = ma1
                ma1 = i
            else:
                ma2 = i
    # print(ma, ma2)
    for i in range(N):
        if ma1 == i:
            print(A[ma2])
        else:
            print(A[ma1])
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())
  a = [int(input()) for _ in range(n)]
  ls = []
  ap = ls.append
  for i in range(n):
    t = a[:i] + a[i+1:]
    ap(max(t))
  [print(x) for x in ls]

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [0]*n
s = []
f_max,s_max = 0,0
for i in range(n):
    a = int(input())
    l[i] = a
    
    if a not in s:
        s.append(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(set(l))==1:
    for i in range(n):
        print(f_max)
    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])

Submission status: Wrong Answer

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

for i in range(n):
  for j in range(n):
    b = [0] * n
    if j != i:
      continue
    b[j] = a[j]
  print(max(b))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [input() for _ in range(N)]
B = A.copy()
B.sort(reverse=True)
a = A.index(B[0])
for i in range(N):
    if i == a:
        print(B[1])
    else:
        print(B[0])

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

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

for i in range(N):
  numbers_minus1 = numbers_full.copy()
  del numbers_minus1[i]
  print(numbers_full, numbers_minus1, str(max(numbers_minus1)))

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) != 1:
    print(arg_sorted[1])
  else:
    print(arg_sorted[0])

Submission status: Wrong Answer

Solution code:
n = int(input())

a = [int(input()) for i in range(0, n)]
l = []

for j in range(0, n):
    temp = a[j]
    a[j] = 0
    l.append(max(a))
    a[j] = temp

print(l)

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

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

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())
  a = [int(input()) for _ in range(n)]
  for i in range(n):
    t = a[:i] + a[i+1:]
    print(max(t))

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 = -99999999

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

if second_max == -99999999:
	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())
A = [int(input()) for i in range(N)]
Max_f = []
Max_r = []
tmp_f = 0
tmp_r = 0

for i in range(N-1):
    Max_f.append(max(tmp_f, A[i]))
    Max_r.append(max(tmp_r, A[-i-1]))
    tmp_f = A[i]
    tmp_r = A[-i-1]

for i in range(N):
    if i == 0:
        print(Max_r[-1])
    elif i == N-1:
        print(Max_f[-1])
    else:
        print(max(Max_f[i-1], Max_r[N-i-2]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
first = 1
second = 1
s = 0
n=int(input())
x = []
for i in range(1,n):
    input(s)
    if first <= s:
        second = first
        first = s
    if second <= s:
        second = s
    x.append(s)

for i in range(0,n-1):
    if x[i] == first:
        print(second)
    else:
        print(first)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())
b=sorted(list(set(a)))
p=len(b)
for i in range(n):
    m = p - 1
    while a[i] == b[m] and m > 0:
        m -= 1
    print(b[m])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(input()) for _ in range(N)]
tmp=A.copy()
tmp.sort(reverse=True)

Afirst=max(A)
if len(set(tmp))==1:
    Asecond=Afirst
else:
    for a in tmp:
        if a!=Afirst:
            Asecond=a
            break
for a in A:
    if a==Afirst:
        print(Asecond)
    else:
        print(Afirst)

Submission status: Wrong Answer

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

A1 = 0
A2 = 0
index = -1
for i in range(N):
    if A1 == 0:
        A1 = max(A1,A[i])
    else:
        tmp = max(A2,A[i])
        if A1 <= A[i]:
            A2 = A1
            A1 = A[i]
            index = i
        elif A2 <= tmp:
            A2 = tmp

if A1 == A2:
    for i in range(N):
        print(A1)
else:
    for i in range(N):
        if i == index:
            print(A2)
        else:
            print(A1)

Submission status: Wrong Answer

Solution code:


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

tmp_a = sorted(list(set(a)), reverse=True)
no1 = tmp_a[0]
no2 = tmp_a[1] if len(tmp_a)>1 else tmp_a[0]

dup_flag = True if a.count(no1)>1 else False

for each in a:
  if each == no1 and dup_flag==False:
    print(no2)
  else:
    print(no1)

Submission status: Wrong Answer

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

A_max = max(A)
C = A.count(A_max)

if C>=2:
    for l in range(N):
        print(A_max)
else:
    p = A.index(A_max)
    A = sorted(A)
    for k in range(N):
        if k==p:
            print(A[1])
        else:
            print(A_max)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
m = max(A)
A_i = [i for i in A if i != m]
if A_i == []:
    for i in range(N):
        print(A[i])
else:
    m_i = max(A_i)
    for i in range(N):
        if A[i] == m:
            print(m_i)
        else:
            print(m)

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 = -9999999

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

if second_max == -1:
	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 = [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) != 1:
    print(arg_sorted[1])
  else:
    print(arg_sorted[0])

Submission status: Wrong Answer

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

biggest = max(sequence)
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:
import copy
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]

a_l = []
for i in range(n):
    a_l.append(a[i][0])
a1 = sorted(a_l)
m1 = a1[-1]
m2 = a1[-2] 
print(m1,m2)
for i in a_l:
    if i == m1:
        print(m2)
    else:
        print(m1)

Submission status: Wrong Answer

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

m=A[0]
for i,v in enumerate(A):
    if v==m:
        m=max(A[:i]+A[i+1:])
    print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(input()) for _ in range(n)]
A_set = set(A)

A_max = max(A_set)
A_set.remove(A_max)
if len(A_set) == 0:
    for i in A:
        print(A_max)
else:
    A_next = max(A_set)
    for i in A:
        if i == A_max:
            print(A_next)
        else:
            print(A_max)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if li[0][0]>li[0][1]:
        cnt1=li[0][0]
        cnt2=li[1][0]
        cnt3=li[0][1]
        k=1
elif li[0][0]<li[0][1]:
        cnt1=li[0][1]
        cnt2=li[1][1]
        cnt3=li[0][0]
        k=1
else:
        cnt1=li[0][1]
        cnt2=li[1][1]
        cnt3=li[0][0]
        k=2

for i in range(n-2):
        if cnt1==li[0][i+2]:
                k+=1
        elif cnt1<li[0][i+2]:
                k=1
                cnt3=cnt1
                cnt1=li[0][i+2]
                cnt2=li[1][i+2]

for i in range(n):
        if k!=1:
                print(cnt1)
        elif i!=cnt2:
                print(cnt1)
        else:
                print(cnt3)

Submission status: Wrong Answer

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

#remove duplicate
sorted_a = sorted(list(set(a_list)), reverse = True)

result = []
for a in a_list:
    if a == sorted_a[0]:
        if len(sorted_a) >= 2:
            result.append(sorted_a[1])
        else:
            result.append(a)
    else:
        result.append(sorted_a[0])

for r in result:
    print(r)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [0]*n
f_max,s_max = 0,0
for i in range(n):
    a = int(input())
    l[i] = a
    if f_max < a:
        s_max = f_max
        f_max = a
    elif s_max < a < f_max:
        s_max = a

if len(set(l))==1:
    for i in range(n):
        print(f_max)
    exit()

for i in range(n):
    if l[i]==f_max:
        print(s_max)
    else:
        print(f_max)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
max1=0
second_max=0
ind=[]
for i in range(N):
  t=int(input())
  if second_max <= t:
    if max1<t:
        max1=t
        ind.clear()
        ind.append(i)
    elif max1==t:
    	ind.append(i)
    else:
        second_max=t
if len(ind)==1:
    for i in range(N):
      if i in ind:
        print(second_max)
      else:
          print(max1)
else:
    for i in range(N):
          print(max1)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = []
max_num = 0

for i in range(n):
    a = int(input())
    lst.append(a)
    if a > max_num:
      max_num = a
      
for i in range(n):
  if lst[i] != max_num:
    print(max_num)
  else:
    lst[i] = 0
    print(max(lst))

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 = []
for _ in range(N):
    A.append(int(input()))

if A[0] > A[1]:
    max_1, max_2 = A[0],A[1]
else:
    max_1, max_2 = A[1],A[0]

dict = {}
for i, a in enumerate(A):
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1
    if i >= 2:
        if a > max_1:
            max_1 = a
            max_2 = max_1
        elif a > max_2:
            max_2 = a

for a in A:
    if a == max_1:
        if dict[a] >= 2:
            print(max_1)
        else:
            print(max_2)
    else:
        print(max_1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(a[:])
for i in range(n):
    k=a[i]
    t=-1
    while True:
        if abs(t) > n:
            print(aa[0])
            break
        elif aa[t] != k:
            print(aa[t])
            break
        else: t -= 1

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 = -1

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

if second_max == -1:
	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())
A_lst = []
max_num = -1
max_index_lst = []
next_num = -1

for i in range(N):
    Ai = int(input())
    A_lst.append(Ai)
    if max_num == -1:
        max_num = Ai
        next_num = Ai
        max_index_lst.append(i)

    elif max_num <= Ai:
        if max_num == Ai:
            max_index_lst.append(i)
        else:
            max_index_lst = [i]
        next_num = max_num
        max_num = Ai

    
    elif next_num < Ai:
        next_num = Ai
print()
for i in range(N):
    if i in max_index_lst:
        if len(max_index_lst) == 1:
            print(next_num)
        else:
            print(max_num)
    else:
        print(max_num)

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 MAX == a:
        MAX_index.append(i)
    elif MAX < a:
        MAX_index = [i]
        MAX = a
    elif MAX_sec < a:
        MAX_sec = a
    else:
        pass
    
#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:
import math

def main():
    N = int(input())
    A = []
    ma = 0
    ma2 = 0
    for i in range(N):
        a = int(input())
        A.append(a)
        if A[ma2] <=  a:
            if A[ma] <= a:
                ma2 = ma
                ma = i
            else:
                ma2 = i
    # print(ma, ma2)
    for i in range(N):
        if ma == i:
            print(A[ma2])
        else:
            print(A[ma])

    


    
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

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

forward = [0 for n in range(N)]
forward[0] = A[0]
backward = [0 for n in range(N)]
backward[N-1] = A[N-1]
for n in range(1,N):
    forward[n] = max(forward[n-1], A[n])
for n in range(N-1)[::-1]:
    backward[n] = max(backward[n+1], A[n])

# print(forward)
# print(backward)

print(backward[0])
for n in range(1,N-1):
    # print("====")
    # print(forward[n-1],backward[n+1])
    print(max(forward[n-1],backward[n+1]))
print(forward[N-1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
A = []
B = []
for i in range(N):
    A.append([int(input()), i])
A.sort(key=lambda x: x[0])
for i in range(N):
    if A[i][1] != N-1:
        print(A[N-1][0])
    else:
        print(A[N-2][0])

Submission status: Wrong Answer

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

suuretu_list = []
kari_list = []

for i in range(a):
    b = int(input())
    suuretu_list.append(b)
    kari_list.append(b)

c = max(suuretu_list)

d = suuretu_list.index(c)

for u in suuretu_list:
    if u != d:
        print(c)
    else:
        e = max(kari_list)
        f = kari_list.index(e)
        kari_list.pop(f)
        g = max(kari_list)
        print(g)
        kari_list.append(g)

Submission status: Wrong Answer

Solution code:
a=[int(input())for i in[0]*int(input())]
b=max(a)
if a.count(b)>1:print('\n'.join([str(b)]*len(a)))
else:
  c=[b for i in a]
  c[a.index(b)]=max(a[:a.index(b)]+a[a.index(b)+1:])

Submission status: Wrong Answer

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

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:
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 = []
for i in range(N):
    a.append(int(input()))
max_a = sorted(a,reverse=True)[:3]
if(max_a[0] > max_a[1]):
    for i in range(N):
        if(a[i] == max_a[0]):
            print(max_a[1])
        else:
            print(max_a[0])
else:
    print(max_a[0])

Submission status: Wrong Answer

Solution code:

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

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

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

Submission status: Wrong Answer

Solution code:

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

forward = [0 for n in range(N)]
forward[0] = A[0]
backward = [0 for n in range(N)]
backward[N-1] = A[N-1]
for n in range(1,N):
    forward[n] = max(forward[n-1], A[n])
for n in range(N-1)[::-1]:
    backward[n] = max(backward[n+1], A[n])

# print(forward)
# print(backward)

print(backward[1])
for n in range(1,N-1):
    # print("====")
    # print(forward[n-1],backward[n+1])
    print(max(forward[n-1],backward[n+1]))
print(forward[N-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
mx1 = 0
mx2 = 0
for i in range(1,n+1):
    a.append(int(input()))
    if mx1 <= a[-1]:
        mx2 = mx1
        mx1 = a[-1]

for j in range(1,n+1):
    if a[j-1] == mx1:
        print(mx2)
    else:
        print(mx1)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())

a = np.zeros((n))
for i in range(n):
    a_tmp = int(input())
    a[i] = a_tmp

f_min = np.zeros((n))
b_min = np.zeros((n))
for i in range(n):
    if i == 0:
        f_min[0] = a[0]
        b_min[n-1] = a[n-1]
    else:
        f_min[i] = max(f_min[i-1],a[i])
        b_min[n-1-i] = max(b_min[n-1-i+1],a[i])

#print(f_min)
#print(b_min)

for i in range(n):
    if i == 0:
        print(int(b_min[1]))
    elif i == (n-1):
        print(int(f_min[n-2]))
    else:
        print(int(max(b_min[i+1],f_min[i-1])))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def calc(N, A):
    Amax = [A[0], A[1]]
    for a in A:
        if (a > Amax[0]):
            Amax[1] = Amax[0]
            Amax[0] = a
        elif (a > Amax[1]):
            Amax[1] = a
    result = ''
    for a in A:
        if (a == Amax[0]):
            result += str(Amax[1]) + '\n'
        else:
            result += str(Amax[0]) + '\n'
    return result


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

Submission status: Wrong Answer

Solution code:
import sys
N=input()
A=[ sys.stdin.readline().strip() for _ in range(N) ]

L=[]
for i,a in enumerate(A):
	if i==0:
		L.append(a)
	else:
		L.append( max(L[-1], a) )

R=[]
for i,a in enumerate(A[::-1]):
	if i==0:
		R.append(a)
	else:
		R.append( max(R[-1], a) )

R=R[::-1]

for i in range(N):
	if i==0:
		print R[i+1]
	elif i==N-1:
		print L[i-1]
	else:
		print max( R[i+1], L[i-1])

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 = -1

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


def main():
	#N, D = [int(x) for x in input().split()]
	N = int(input())
	
	max_num = 0
	sub_max = 0
	index = 0
	for i in range(N):
		num = int(input())
		if num > max_num:
			index = i
			sub_max = max_num
			max_num = num
		elif num > sub_max:
			sub_max = num

	print("---")
	for i in range(N):
		if i == index:
			print(sub_max)
		else:
			print(max_num)

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Ai=np.argmax(A)
if Ai==0:
  A2max=max(A[Ai+1:])
elif Ai==N-1:
  A2max=max(A[:Ai])
else:
  A2max=max(A[:Ai],A[Ai+1:])[0]

for i in range(N):
  if i==Ai:
    print(A2max)
  else:
    print(Amax)