Buggy python submission (verdict: Runtime Error):
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)))

Fixed submission:

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)

Buggy python submission (verdict: Runtime Error):
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)))

Fixed submission:

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)

Buggy python submission (verdict: Runtime Error):
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_1 < a:
        max_2 = max_1
        max_i = [i]
        max_1 = a
    elif max_2 < a:
        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)))

Fixed submission:

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)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

n = int(input())
a_list = []
out_list = []

for i in range(n):
    a_list.append(int(input()))

is_max = False
#print(a_list)    
for i in range(n):
    if not is_max:
        a_copy = copy.copy(a_list)
        a_copy.pop(i)
        #print(a_copy)
        a_max = max(a_copy)
        #print(a_max)
        out_list.append(a_max)
        if a_list[i] == a_max:
            is_max = True
            out_list += [a_max for i in range(n-i-1)]
#print(out_list)        
print("\n".join(map(str, out_list)))

Fixed submission:

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)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

n = int(input())
a_list = []
out_list = []

for i in range(n):
    a_list.append(int(input()))

is_max = False
#print(a_list)    
for i in range(n):
    if not is_max:
        a_copy = copy.copy(a_list)
        a_copy.pop(i)
        #print(a_copy)
        a_max = max(a_copy)
        #print(a_max)
        out_list.append(a_max)
        if a_list[i] == a_max:
            is_max = True
    else:
        out_list.append(a_max)
        
print("\n".join(map(str, out_list)))

Fixed submission:

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)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

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

for i in range(n):
    a_list.append(int(input()))

is_max = False
#print(a_list)    
for i in range(n):
    if not is_max:
        a_copy = copy.copy(a_list)
        a_copy.pop(i)
        #print(a_copy)
        a_max = max(a_copy)
        print(a_max)
        if a_list[i] == a_max:
            is_max = True
    else:
        print(a_max)

Fixed submission:

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)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

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

for i in range(n):
    a_list.append(int(input()))
    
#print(a_list)    
for i in range(n):
    a_copy = copy.copy(a_list)
    a_copy.pop(i)
    #print(a_copy)
    print(max(a_copy))

Fixed submission:

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)