Problem: 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.

Submission attempts (in order):
#C
n = int(input())
max_1 = None
max_2 = None

for i in range(n):
    a = int(input())
    
    if max_2 is None:
        if max_1 is None:
            max_1 = a
            max_i = [i]
            
        elif a < max_1:
            max_2 = a

        elif max_1 == a:
            max_i.append(i)

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

n = int(input())
max_1 = None
max_2 = None

for i in range(n):
    a = int(input())
    
    if max_2 is None:
        if max_1 is None:
            max_1 = a
            max_i = [i]
            
        elif a < max_1:
            max_2 = a

        elif max_1 == a:
            max_i.append(i)

       
    else:    
        if max_2 < a:
            if max_1 < a:
                max_2 = max_1
                max_i = [i]
                max_1 = a
            else:
                max_2 = a
    
if len(max_i) >= 2:
    out_list = [max_1 for i in range(n)]
else:
    out_list = [max_1 for i in range(n)]
    out_list[max_i[0]] = max_2
    
#print("\n".join(map(str, out_list)))
for j in out_list:
    print(j)

n = int(input())
max_1 = None
max_2 = None

for i in range(n):
    a = int(input())
    
    if max_2 is None:
        if max_1 is None:
            max_1 = a
            max_i = [i]
            
        elif a < max_1:
            max_2 = a

        elif max_1 == a:
            max_i.append(i)

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

n = int(input())
max_1 = None
max_2 = None

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

#C

n = int(input())
a = []

for i in range(n):
    a.append(int(input()))
    
a_copy = list(a)
a.sort(reverse=True)

max_1 = a[0]
max_count = a.count(max_1)

for i in a:
    if i < max_1:
        max_2 = i
        
for a in a_copy:
    if a == max_1 and max_count == 1:
        print(max_2)
    else:
        print(max_1)

#C
n = int(input())
max_1 = None
max_2 = None

for i in range(n):
    a = int(input())
    
    if max_2 is None:
        if max_1 is None:
            max_1 = a
            max_i = [i]
            
        elif a < max_1:
            max_2 = a

        elif max_1 == a:
            max_i.append(i)

       
    else:    
        if max_2 < a:
            if max_1 < a:
                max_2 = max_1
                max_i = [i]
                max_1 = a
            else:
                max_2 = a
    
if len(max_i) >= 2:
    out_list = [max_1 for i in range(n)]
else:
    out_list = [max_1 for i in range(n)]
    out_list[max_i[0]] = max_2
    
#print("\n".join(map(str, out_list)))
for j in out_list:
    print(j)

n = int(input())
max_1 = None
max_2 = None

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

import copy

n = int(input())
max_1 = None
max_2 = None

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

n = int(input())
max_1 = None
max_2 = None

for i in range(n):
    a = int(input())
    
    if max_2 is None:
        if max_1 is None:
            max_1 = a
            max_i = [i]
            
        elif a < max_1:
            max_2 = a

        elif max_1 == a:
            max_i.append(i)

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


n = int(input())
a = []

for i in range(n):
    a.append(int(input()))
    
a_copy = list(a)
a.sort(reverse=True)

max_1 = a[0]
max_count = a.count(max_1)

for i in a:
    if i < max_1:
        max_2 = i
        break
        
for a in a_copy:
    if a == max_1 and max_count == 1:
        print(max_2)
    else:
        print(max_1)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Accepted