Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

max_val = max(a)

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

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

a_sort = sorted(set(a))

max_val_1 = a_sort[-1]
max_total_1 = a.count(max_val_1)

if len(a_sort) >= 2:
    max_val_2 = a_sort[-2]

#print("max val:{}".format(max_val_1))
#print("max total:{}".format(max_total_1))

for i in range(n):
    if max_total_1 >=2:
        print(max_val_1)
    
    elif a[i] < max_val_1:
        print(max_val_1)

    elif a[i] == max_val_1 and max_total_1 == 1:
        print(max_val_2)
    else:
        print("err")

Buggy python submission (verdict: Runtime Error):
array = list(map(int, input().strip().split()))
n = array[0]
max = 0
t = len(array)
t = t-1
backup = 0

for i in range(n):
    backup = array[i+1]
    array[i+1] = 0

    for j in range(t):
        if(array[j+1] > max):
            max = array[j+1]      

    print(array)
    print(max)
    max = 0
    array[i+1] = backup


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

a_sort = sorted(set(a))

max_val_1 = a_sort[-1]
max_total_1 = a.count(max_val_1)

if len(a_sort) >= 2:
    max_val_2 = a_sort[-2]

#print("max val:{}".format(max_val_1))
#print("max total:{}".format(max_total_1))

for i in range(n):
    if max_total_1 >=2:
        print(max_val_1)
    
    elif a[i] < max_val_1:
        print(max_val_1)

    elif a[i] == max_val_1 and max_total_1 == 1:
        print(max_val_2)
    else:
        print("err")

Buggy python submission (verdict: Runtime Error):
array = list(map(int, input().strip().split()))
n = array[0]
max = 0
t = len(array)
t = t-1
backup = 0
for i in range(n):
    backup = array[i+1]
    array[i+1] = 0
    for j in range(t):
        if(array[j+1] > max):
            max = array[j+1]      
    print(array)
    print(max)
    max = 0
    array[i+1] = backup

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

a_sort = sorted(set(a))

max_val_1 = a_sort[-1]
max_total_1 = a.count(max_val_1)

if len(a_sort) >= 2:
    max_val_2 = a_sort[-2]

#print("max val:{}".format(max_val_1))
#print("max total:{}".format(max_total_1))

for i in range(n):
    if max_total_1 >=2:
        print(max_val_1)
    
    elif a[i] < max_val_1:
        print(max_val_1)

    elif a[i] == max_val_1 and max_total_1 == 1:
        print(max_val_2)
    else:
        print("err")

Buggy python submission (verdict: Runtime Error):
array = list(map(int, input().strip().split()))
n = array[0]
backup = 0
for i in range(n):
    backup = array[i+1]
    array[i+1] = 0
    print(max(array))
    array[i+1] = backup

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

a_sort = sorted(set(a))

max_val_1 = a_sort[-1]
max_total_1 = a.count(max_val_1)

if len(a_sort) >= 2:
    max_val_2 = a_sort[-2]

#print("max val:{}".format(max_val_1))
#print("max total:{}".format(max_total_1))

for i in range(n):
    if max_total_1 >=2:
        print(max_val_1)
    
    elif a[i] < max_val_1:
        print(max_val_1)

    elif a[i] == max_val_1 and max_total_1 == 1:
        print(max_val_2)
    else:
        print("err")

Buggy python submission (verdict: Runtime Error):
array = list(map(int, input().strip().split()))
n = array[0]
backup = 0
for i in range(n):
    backup = array[i]
    array[i] = 0
    print(max(array))
    array[i] = backup

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

a_sort = sorted(set(a))

max_val_1 = a_sort[-1]
max_total_1 = a.count(max_val_1)

if len(a_sort) >= 2:
    max_val_2 = a_sort[-2]

#print("max val:{}".format(max_val_1))
#print("max total:{}".format(max_total_1))

for i in range(n):
    if max_total_1 >=2:
        print(max_val_1)
    
    elif a[i] < max_val_1:
        print(max_val_1)

    elif a[i] == max_val_1 and max_total_1 == 1:
        print(max_val_2)
    else:
        print("err")