alexjercan/bugnet huggingface dataset:
Problem p02970 (Python) — buggy submission, verdict: Runtime Error

#!/usr/bin/env python3
# https://atcoder.jp/contests/abc134/tasks/abc134_b

import math

n, d = [int(x) for x in input().split()]
print(math.ceil(n / (d * 2 + 1)))


Error: ValueError: invalid literal for int() with base 10: '6 2'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02970/Python/s267140007.py", line 3, in <module>
    n = int(input())
ValueError: invalid literal for int() with base 10: '6 2'


Fixed submission:

#!/usr/bin/env python3

n = int(input())
print(int((n - 1) / 2) if n % 2 == 1 else int(n / 2) - 1)
Problem p02970 (Python) — buggy submission, verdict: Runtime Error

n, d = map(int, input().split())
print(-(-n // (1 + d * 2)))


Error: ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02970/Python/s626799708.py", line 1, in <module>
    n, d = map(int, input())
ValueError: invalid literal for int() with base 10: ' '


Fixed submission:

n, d = map(int, input())
print(-(-n // (1 + d * 2)))
Problem p02970 (Python) — buggy submission, verdict: Runtime Error

n, d = [int(x) for x in input().split()]

for i in range(n + 1):
    if (2 * d + 1) * i >= n:
        ans = i
        break

print(ans)


Error: 0

Fixed submission:

n, d = [int(x) for x in input().split()]

for i in range(n):
    if (2 * d + 1) * i >= n:
        ans = i
        break
print(ans)
Problem p02970 (Python) — buggy submission, verdict: Runtime Error

import math

inputted = list(map(int, input().split()))
N = inputted[0]
D = inputted[1]

monitor = D * 2 + 1
answer = math.ceil(N / monitor)

print(answer)


Error: ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02970/Python/s590297145.py", line 3, in <module>
    inputted = list(map(int, input()))
ValueError: invalid literal for int() with base 10: ' '


Fixed submission:

import math

inputted = list(map(int, input()))
N = inputted[0]
D = inputted[1]

monitor = (D + 1) * 2
answer = math.ceil(N / monitor)

print(answer)
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

# -*- coding: utf-8 -*-

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

max_a = max(a)
b = a[:]
b.remove(max_a)
max_b = max(b)

if max_a == max_b:
    for i in range(n):
        print(max_a)
else:
    idx = a.index(max_a)
    for i in range(n):
        if idx == i:
            print(max_b)
        else:
            print(max_a)


Error: TLE

Fixed submission:

# -*- coding: utf-8 -*-

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

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


ans = ["" for _ in range(n)]
for i in range(n):
    a_test = a[:]
    del a_test[i]
    ans[i] = max(a_test)


for i in range(n):
    print(ans[i])
Problem p02971 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
a = []
b = []
a_max = 0
a_second = 0

for i in range(N):
    a.append(int(input()))

b = a[:]
a.sort(reverse=True)

a_max = a[0]
a_second = a[1]

for i in range(N):
    if b[i] == a_max:
        print(a_second)
    else:
        print(a_max)


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02971/Python/s053988240.py", line 8, in <module>
    b = a[i]
IndexError: list index out of range


Fixed submission:

N = int(input())
a = []
b = 0
a.append(int(input()))
# for i in range(N):

for i in range(N):
    b = a[i]
    a[i] = 0
    print(max(a))
    a[i] = b
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
s = list(int(input()) for _ in range(n))
i = 0
sort_s = sorted(s)

for i in s:
    if i == sort_s[-1]:
        print(sort_s[-2])
    else:
        print(sort_s[-1])


Error: TLE

Fixed submission:

import sys
import numpy as np

input = sys.stdin.readline
n = int(input())
s = list(int(input()) for _ in range(n))
i = 0
maxn = 0
s2 = []
for i in range(n):
    s2 = s.copy()
    del s2[i]
    print(np.max(np.array(s2)))
    i += 1
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

def main(n: int, a: list):
    a_max, a_second = sorted(a, reverse=True)[:2]

    for i in range(n):
        if a[i] != a_max:
            print(a_max)
        else:
            print(a_second)


if __name__ == "__main__":
    n = int(input())
    a = [int(input()) for _ in range(n)]

    main(n, a)


Error: TLE

Fixed submission:

def main(n: int, a: list):
    for i in range(n):
        t = a.copy()
        t[i] = 0

        print(max(t))


if __name__ == "__main__":
    n = int(input())
    a = [int(input()) for _ in range(n)]

    main(n, a)
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = [int(input()) for _ in range(n)]
b, c = sorted(a)[-2:]
j = a.index(c)
for i in range(n):
    print((c, b)[i == j])


Error: TLE

Fixed submission:

n = int(input())
a = [int(input()) for _ in range(n)]
b, c = sorted(a)[-2:]
for i in range(n):
    print(b if a.index(c) == i else c)
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

import copy

n = int(input())
a = [int(input()) for _ in range(n)]
s = copy.copy(a)
s.sort(reverse=True)
first = s[0]
second = s[1]
mx = []
for i in range(n):
    if a[i] == first:
        mx.append(second)
    else:
        mx.append(first)
for i in range(n):
    print(mx[i])


Error: TLE

Fixed submission:

n = int(input())
a = [int(input()) for _ in range(n)]
mx = []
for i in range(n):
    x = a.pop(i)
    mx.append(max(a))
    a.insert(i, x)
for i in range(n):
    print(mx[i])
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

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

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


Error: TLE

Fixed submission:

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

for i in range(N):
    print(max(L[:i] + L[i + 1 :]))
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a.copy(), reverse=True)
for i in range(n):
    if a[i] == b[0]:
        print(b[1])
    else:
        print(b[0])


Error: TLE

Fixed submission:

n = int(input())
a = [int(input()) for _ in range(n)]
b = []
for i in range(n):
    b = sorted(a.copy(), reverse=True)
    if a[i] == b[0]:
        print(b[1])
    else:
        print(b[0])
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
max_a = max(a)
max_cnt = a.count(max_a)
for i in range(n):

    if max_a > a[i]:
        print(max_a)
    else:
        if max_cnt > 1:
            print(a[i])
        else:
            print(b[-2])


Error: TLE

Fixed submission:

n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
for i in range(n):

    if max(a) > a[i]:
        print(max(a))
    else:
        if a.count(a[i]) > 1:
            print(a[i])
        else:
            print(b[-2])
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = [int(input()) for _ in range(N)]
sorted_A = sorted(A[:])

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


Error: TLE

Fixed submission:

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

for i in range(N):
    A_copy = A[:]
    removed_A = A_copy.pop(i)
    print(max(A_copy))
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
maxindex = maxvalue = 0
a = []
for i in range(n):
    _a = int(input())
    if maxvalue <= _a:
        maxvalue = _a
        maxindex = i
    a.append(_a)

for i in range(n):
    if i != maxindex:
        print(maxvalue)
        continue
    t = a[:]
    t.pop(i)
    print(max(t))


Error: TLE

Fixed submission:

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

for i in range(n):
    t = a[:]
    t.pop(i)
    print(max(t))
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

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

sa = sorted(a)
mx = sa[-1]
for val in a:
    if val != mx:
        print(sa[-1])
    else:
        print(sa[-2])


Error: TLE

Fixed submission:

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

sa = sorted(a)
for i in range(n):
    val = a[i]
    idx = sa.index(val)
    sa.pop(idx)
    print(sa[-1])
    sa.insert(idx, val)
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
A = [int(input()) for i in range(n)]
tmp = sorted(A, reverse=True)
Max = tmp[0]
Second = tmp[1]
for i in range(n):
    if A[i] != Max:
        print(Max)
    else:
        print(Second)


Error: TLE

Fixed submission:

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

for i in range(n):
    tmp = A[:]
    del tmp[i]
    print(max(tmp))
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

# -*- coding: utf-8 -*-
n = int(input())
a = [int(input()) for _ in range(n)]
a_unique = list(sorted(set(a), reverse=True))
max_value = a_unique[0]
max_value_count = a.count(max_value)

if max_value_count == 1:
    for i in range(n):
        if a[i] == max_value:
            print(a_unique[1])
        else:
            print(max_value)
else:
    for i in range(n):
        print(max_value)


Error: TLE

Fixed submission:

# -*- coding: utf-8 -*-
n = int(input())
a = [int(input()) for _ in range(n)]
a_unique = list(sorted(set(a), reverse=True))
max_value = max(a_unique)
for i in range(n):
    current_value = a.pop(i)
    if max_value in a:
        print(max_value)
    else:
        print(a_unique[1])
    a.insert(i, current_value)
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

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

L = A[:]
m1 = max(A)
m1i = A.index(m1)
A.pop(m1i)
m2 = max(A)
m2i = A.index(m2)
A.pop(m2i)

for i in range(N):
    if L[i] == m1:
        print(m2)
    else:
        print(m1)


Error: TLE

Fixed submission:

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

for i in range(N):
    L = A[:]
    A.pop(i)
    m = max(A)
    print(m)
    A = L[:]
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
inputs = [int(input()) for _ in range(N)]

sorted_inputs = sorted(inputs, reverse=True)
for i in range(N):
    if sorted_inputs[0] == inputs[i]:
        print(sorted_inputs[1])
    else:
        print(sorted_inputs[0])


Error: TLE

Fixed submission:

N = int(input())
inputs = [int(input()) for _ in range(N)]

for i in range(N):
    sorted_inputs = sorted(inputs, reverse=True)
    if sorted_inputs[0] == inputs[i]:
        print(sorted_inputs[1])
    else:
        print(sorted_inputs[0])
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)

for A in a:
    if A == b[n - 1]:
        print(b[n - 2])
    else:
        print(b[n - 1])


Error: TLE

Fixed submission:

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

for i in range(n):
    b = a[:]
    del b[i]
    print(max(b))
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    n = int(input())
    a = []
    for _ in range(n):
        a.append(int(input()))
    b = sorted(a)
    for i in range(len(a)):
        if a[i] == b[-1]:
            print(b[-2])
        else:
            print(b[-1])


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

import copy


def main():
    n = int(input())
    a = []
    for _ in range(n):
        a.append(int(input()))
    for i in range(len(a)):
        b = copy.deepcopy(a)
        b.pop(i)
        print(max(b))


if __name__ == "__main__":
    main()
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)[::-1]
mx = b[0]
mx2 = b[1]

for i in a:
    if i == mx:
        print(mx2)
    else:
        print(mx)


Error: TLE

Fixed submission:

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

for i in range(N):
    A_num = A.pop(i)
    print(max(A))
    A.insert(i, A_num)
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

import copy

n = int(input())

a = [0] * n

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

a_sort = sorted(a, reverse=True)

for i in range(n):
    if a[i] == a_sort[0]:
        print(a_sort[1])
    else:
        print(a_sort[0])


Error: TLE

Fixed submission:

import copy

n = int(input())

a = [0] * n

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

# a_s = set(a)

for i in range(n):
    tmp = copy.deepcopy(a)
    # tmp.discard(a[i])
    del tmp[i]
    print(max(tmp))
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = list(int(input()) for _ in range(N))
m = max(A)

A_sorted = sorted(A)

for i in range(N):
    v = A[i]
    if v < m:
        print(m)
    else:
        print(A_sorted[-2])


Error: TLE

Fixed submission:

N = int(input())
A = list(int(input()) for _ in range(N))

A_sort = sorted(A)

for i in range(N):
    v = A[i]
    if v < max(A):
        print(max(A))
    else:
        print(A_sort[-2])
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

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

No1 = 0
No2 = 0
for i in range(N):
    if A[i] > No1:
        No2 = No1
        No1 = A[i]
    elif A[i] > No2:
        No2 = A[i]

for i in range(N):
    if A[i] == No1:
        print(No2)
    else:
        print(No1)


Error: TLE

Fixed submission:

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

for i in range(N):
    max = 0
    for j in range(N):
        if i != j and A[j] > max:
            max = A[j]
    print(max)
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A_LIST = []

for _ in range(N):
    A = int(input())
    A_LIST.append(A)

sorted_A_LIST = sorted(A_LIST)
largest = sorted_A_LIST[-1]
second_largest = sorted_A_LIST[-2]

for i in range(N):
    if A_LIST[i] < largest:
        print(largest)
    else:
        print(second_largest)


Error: TLE

Fixed submission:

N = int(input())
A_LIST = []

for _ in range(N):
    A = int(input())
    A_LIST.append(A)

for i in range(N):
    temp = A_LIST[i]
    A_LIST[i] = 0
    print(max(A_LIST))
    A_LIST[i] = temp
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

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

max1 = [A.index(max(A)), max(A)]
p = A.pop(A.index(max(A)))
max2 = max(A)
ans = [max2 if j == max1[0] else max1[1] for j in range(N)]
for k in range(N):
    print(ans[k])


Error: TLE

Fixed submission:

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

for j in range(N):
    p = A.pop(j)
    print(max(A))
    A.insert(j, p)
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
nums = [None] * n

for i in range(n):
    nums[i] = int(input())
sorted_nums = sorted(nums)

for i in range(n):
    max_val = sorted_nums[n - 1]
    if nums[i] == max_val:
        max_val = sorted_nums[n - 2]
    print(max_val)


Error: TLE

Fixed submission:

n = int(input())
nums = [None] * n

for i in range(n):
    nums[i] = int(input())
sorted_nums = sorted(nums)

for i in range(n):
    if sorted_nums.index(nums[i]) == n - 1:
        max_val = sorted_nums[n - 2]
    else:
        max_val = sorted_nums[n - 1]
    print(max_val)
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

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

aa = sorted(a)
first = aa[-1]
second = aa[-2]

for i in range(n):
    if a[i] != first:
        print(first)
    else:
        print(second)


Error: TLE

Fixed submission:

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

for i in range(n):
    temp = a[i]
    a[i] = 0
    print(max(a))
    a[i] = temp
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

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

t = sorted(a, reverse=True)

for i in range(n):
    if a[i] == t[0]:
        print(t[1])
    else:
        print(t[0])


Error: TLE

Fixed submission:

n = int(input())
m = 0
a = []
for _ in range(n):
    _a = int(input())
    m = max(m, _a)
    a.append(_a)

for i in range(n):
    if a[i] == m:
        t = a[:]
        t.pop(i)
        print(max(t))
    else:
        print(m)
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = [int(input()) for _ in range(n)]
s, f = sorted(a)[-2:]

for ai in a:
    print(f if ai != f else s)


Error: TLE

Fixed submission:

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

for i in range(n):
    ac = a.copy()
    del ac[i]
    print(max(ac))
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
a = []
for _ in range(N):
    a.append(int(input()))
a_sorted = sorted(a)
max_a = a_sorted.pop()
second_a = a_sorted.pop()
if max_a == second_a:
    for _ in range(N):
        print(max_a)
else:
    idx = 0
    while idx < N:
        if a[idx] == max_a:
            print(second_a)
        else:
            print(max_a)
        idx += 1


Error: TLE

Fixed submission:

N = int(input())
a = []
for _ in range(N):
    a.append(int(input()))
tmp = 0
idx = 0
while idx < N:
    tmp, a[idx] = a[idx], tmp
    print(max(a))
    tmp, a[idx] = a[idx], tmp
    idx += 1
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
aa = [int(input()) for _ in range(n)]
aho = sorted(aa)
for a in aa:
    print(aho[-1] if a < aho[-1] else aho[-2])


Error: TLE

Fixed submission:

n = int(input())
semi_max = 0
aa = []
for i in range(n):
    a = int(input())
    if i > 0:
        if a >= semi_max and a < max(aa):
            semi_max = a
        elif a == max(aa):
            semi_max = max(aa)
    aa.append(a)
    # print(semi_max)
for each in aa:
    print(max(aa) if each <= semi_max else semi_max)
Problem p02971 (Python) — buggy submission, verdict: Runtime Error

from heapq import heappush, heappop

N = int(input())
A = [int(input()) for i in range(N)]
hq = []
for i in range(N):
    heappush(hq, -A[i])
max1 = -heappop(hq)
max2 = -heappop(hq)
ans = [0] * N
for i in range(N):
    if A[i] == max1:
        ans[i] = max2
    else:
        ans[i] = max1
print(*ans, sep="\\n")


Error: 0

Fixed submission:

from heapq import heappush, heappop

N = int(input())
A = [int(input()) for i in range(N)]
hq = []
for i in range(N):
    heappush(hq, -A[i])
max1 = -heappop(hq)
while True:
    max2 = -heappop(hq)
    if max2 != max1:
        break
ans = [0] * N
for i in range(N):
    if A[i] == max1:
        ans[i] = max2
    else:
        ans[i] = max1
print(*ans, sep="\\n")
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

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

desc = sorted(list(set(a)), reverse=True)
max = desc[0]
large_2 = desc[1] if len(desc) > 1 else 0

if a.count(max) == 1:
    for val in a:
        if val == max:
            print(large_2)
        else:
            print(max)
else:
    for _ in range(n):
        print(max)


Error: TLE

Fixed submission:

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

for _ in range(n):
    val = a.pop(0)
    print(max(a))
    a.append(val)
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

A = [int(input()) for i in range(int(input()))]
first = max(A)
second = sorted(A)[-2]
for i in A:
    if i == first:
        print(second)
    else:
        print(first)


Error: TLE

Fixed submission:

A = [int(input()) for i in range(int(input()))]
max_A = max(A)
for i in A:
    if i == max_A:
        print(sorted(A)[-2])
    else:
        print(max_A)
Problem p02971 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
a = [int(input()) for i in range(n)]
maxi = max(a)
s = sorted(a, reverse=True)

for i in range(n):
    if a[i] != maxi:
        print(maxi)
    else:
        print(s[1])


Error: IndexError: pop index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02971/Python/s556962228.py", line 8, in <module>
    b = a.pop(a[i])
IndexError: pop index out of range


Fixed submission:

n = int(input())
a = [int(input()) for i in range(n)]
maxi = max(a)
for i in range(n):
    if a[i] != maxi:
        print(maxi)
    else:
        b = a.pop(a[i])
        print(max(a))
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())

A = []

[A.append(int(input())) for x in range(N)]

max_num = max(A)
num = A.index(max(A))
A[num] = 0

st_max_num = max(A)

for i in range(num):
    print(max_num)
print(st_max_num)

for i in range(num + 1, N):
    print(max_num)


Error: TLE

Fixed submission:

N = int(input())

A = []

[A.append(int(input())) for x in range(N)]

max_num = 0

for i in range(N):
    for j in range(N):
        if j != i and max_num < A[j]:
            max_num = A[j]
    print(max_num)
    max_num = 0
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

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

m = max(a)
idxs = [i for i, v in enumerate(a) if v == m]

if len(idxs) > 1:
    for i in range(n):
        print(m)

if len(idxs) == 1:
    idx = idxs[0]
    for i in range(n):
        if idx == i:
            _a = a.copy()
            _a.pop(i)
            print(max(_a))
        else:
            print(m)


Error: TLE

Fixed submission:

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

for i in range(n):
    _a = a.copy()
    _a.pop(i)
    print(max(_a))
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

import copy

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

result = max(A)
ind = A.index(result)

for i in range(N):
    if i == ind:
        a = copy.deepcopy(A)
        a.remove(result)
        print(max(a))
    else:
        print(result)


Error: TLE

Fixed submission:

import copy

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

for i in range(N):
    a = copy.deepcopy(A)
    a.remove(A[i])
    print(max(a))
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

def solve():
    n = int(input())
    a = list(int(input()) for _ in range(n))
    ranking = sorted(a)[::-1]
    first = ranking[0]
    second = ranking[1]
    first_idx = a.index(first)
    for idx in range(n):
        if idx == first_idx:
            print(second)
        else:
            print(first)


if __name__ == "__main__":
    solve()


Error: TLE

Fixed submission:

def solve():
    n = int(input())
    a = list(int(input()) for _ in range(n))
    for idx in range(n):
        d = max([v for i, v in enumerate(a) if i != idx])
        print(d)


if __name__ == "__main__":
    solve()
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a_list = [int(input()) for i in range(n)]
a_list_sort = sorted(a_list)
a_list_max1 = max(a_list)
a_list_max2 = a_list_sort[-2]
for i in range(n):
    if a_list_max1 == a_list[i]:
        print(a_list_max2)
    else:
        print(a_list_max1)


Error: TLE

Fixed submission:

n = int(input())
a_list = [int(input()) for i in range(n)]
for i in range(n):
    dum = a_list[i]
    a_list[i] = 0
    print(max(a_list))
    a_list[i] = dum
Problem p02971 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
ind = []
m = 0
k = 0
for i in range(n):
    a = int(input())
    if m == a:
        ind = -1
    elif m < a:
        k, m = m, a
        ind = i
    elif k < a:
        k = a
if ind == -1:
    print("\\n".join(map(str, [m for i in range(n)])))
else:
    print("\\n".join(map(str, [k if i == ind else m for i in range(n)])))


Error: TLE

Fixed submission:

n = int(input())
ind = []
m = 0
k = 0
for i in range(n):
    a = int(input())
    if m == a:
        ind.append(i)
        k = a
    elif m < a:
        k, m = m, a
        ind = [i]
    elif k < a:
        k = a
print("\\n".join(map(str, [k if i in ind else m for i in range(n)])))