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

N = int(input())


def is_prime(n):
    for i in range(1, n):
        if i != 1 and n % i == 0:
            return False
    return True


def prime_numbers():
    num = 5
    while True:
        is_num_prime = is_prime(num)
        if is_num_prime and num % 5 == 1:
            yield num
        num += 1


prime_gene = prime_numbers()
ans = [next(prime_gene) for _ in range(N)]
print(*ans)


Error: TypeError: unsupported operand type(s) for %: 'generator' and 'int'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03362/Python/s462787302.py", line 25, in <module>
    if prime_gene % 5 == 1:
TypeError: unsupported operand type(s) for %: 'generator' and 'int'


Fixed submission:

N = int(input())


def is_prime(n):
    for i in range(1, n):
        if i != 1 and n % i == 0:
            return False
    return True


def prime_numbers():
    num = 2
    while True:
        is_num_prime = is_prime(num)
        if is_num_prime:
            yield num
        num += 1


prime_gene = prime_numbers()
ans = []

while len(ans) < 5:
    prime = next(prime_gene)
    if prime_gene % 5 == 1:
        ans.append(prime)
print(ans)
Problem p03363 (Python) — buggy submission, verdict: Time Limit Exceeded

import heapq

N = int(input())
A = [int(_) for _ in input().split()]
cumsum = [0]
for a in A:
    cumsum += [cumsum[-1] + a]
heapq.heapify(cumsum)
before = 10**10
count = 0
ans = 0
while cumsum:
    now = heapq.heappop(cumsum)
    count += before == now
    if not (before == now and cumsum):
        ans += count * (count + 1) // 2
        count = 0
    before = now
print(ans)


Error: TLE

Fixed submission:

N = int(input())
A = [int(_) for _ in input().split()]
cumsum = [0]
for a in A:
    cumsum += [cumsum[-1] + a]
ans = 0
for i in range(N):
    for j in range(i + 1, N + 1):
        ans += cumsum[j] - cumsum[i] == 0
print(ans)
Problem p03363 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter

N = int(input())
inputs = [int(i) for i in input().split()]

ans = 0
ruisekiwa = [0] * (N + 1)

for i in range(N):
    ruisekiwa[i + 1] = ruisekiwa[i] + inputs[i]

ruisekiwa = ruisekiwa[1:]
ruisekiwa.sort()
counter_ruiseki = Counter(ruisekiwa)

for key, value in counter_ruiseki.items():
    if key == 0 and value == 1:
        ans += value
        continue
    elif key == 0 and value > 1:
        ans += value
    if value > 1:
        ans += sum(list(range(value)))

print(ans)


Error: TLE

Fixed submission:

N = int(input())
inputs = [int(i) for i in input().split()]

ans = 0

for i in range(N):
    total = 0
    for item in inputs[i:]:
        total += item
        if total == 0:
            ans += 1

print(ans)
Problem p03363 (Python) — buggy submission, verdict: Time Limit Exceeded

from itertools import accumulate
from collections import Counter

N = int(input())
num_list = list(map(int, input().split()))
cumulative_sum_list = list(accumulate(num_list))
cumulative_sum_list.append(0)

c = Counter(cumulative_sum_list)
s = 0
for i in c.values():
    s += i * (i - 1) // 2
print(s)


Error: TLE

Fixed submission:

N = int(input())
num_list = list(map(int, input().split()))
cumulative_sum_list = [0]
c_s = 0
for i in num_list:
    c_s += i
    cumulative_sum_list.append(c_s)
cumulative_sum_list.sort()
cumulative_sum_set = set(cumulative_sum_list)
s = 0
for i in cumulative_sum_set:
    c = cumulative_sum_list.count(i)
    s += c * (c - 1) // 2
print(s)
Problem p03363 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter

N = int(input())
A = list(map(int, input().split()))

S = [0]

for i, a in enumerate(A):
    S.append(S[i] + a)

S = sorted(S)
a = Counter(S).most_common()
cnt = 0

for i in range(len(a)):
    cnt += ((a[i][1] - 1) * a[i][1]) // 2

print(cnt)


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))

cnt = 0

for i in range(0, N):
    for j in range(i + 1, N + 1):
        if sum(A[i:j]) == 0:
            cnt += 1

print(cnt)
Problem p03363 (Python) — buggy submission, verdict: Runtime Error

a = int(input())
c = list(map(int, input().split()))
d = {0: 1}
e = 0
for i in range(len(c)):
    e += c[i]
    if e not in d:
        d[e] = 1
    else:
        d[e] += 1
ans = 0
for v in d.values():
    if v >= 2:
        ans += v * (v - 1) // 2
print(ans)


Error: ValueError: not enough values to unpack (expected 2, got 1)
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03363/Python/s063469917.py", line 1, in <module>
    a, b = map(int, input().split())
ValueError: not enough values to unpack (expected 2, got 1)


Fixed submission:

a, b = map(int, input().split())
c = list(map(int, input().split()))
Problem p03363 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = map(int, input().split())

S = [0]

for a in A:
    S.append(S[len(S) - 1] + a)

S = sorted(S) + [None]
ret = 0
cnt = 1
for i in range(1, N + 2):
    if S[i] != S[i - 1]:
        ret += cnt * (cnt - 1) // 2
        cnt = 1
    else:
        cnt += 1

print(ret)


Error: TLE

Fixed submission:

N = int(input())
A = map(int, input().split())

S = [0]

for a in A:
    S.append(S[len(S) - 1] + a)

S = sorted(S)

ret = 0
for s in set(S):
    cnt = S.count(s)
    ret += cnt * (cnt - 1) / 2
print(int(ret))
Problem p03363 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter

N = int(input())
A = list(map(int, input().split(" ")))
S = [
    0,
]
now = 0
for n in A:
    now += n
    S.append(now)
Scounter = Counter(S)
ans = 0
for c, n in Scounter.most_common():
    if n >= 2:
        ans += n * (n - 1) // 2
    else:
        break
print(ans)


Error: TLE

Fixed submission:

import bisect

n = int(input())
nums = list(map(int, input().split(" ")))
sigma = []
temp = 0
for num in nums:
    temp += num
    sigma.append(temp)

ans = 0
for i, s in enumerate(sigma):
    if s == 0:
        ans += 1
    beforeSums = sorted(sigma[:i])
    li = bisect.bisect_left(beforeSums, s)
    if li >= i:
        continue
    while beforeSums[li] == s:
        ans += 1
        li += 1
        if li >= i:
            break
print(ans)
Problem p03364 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
S_list = [input() for _ in range(N)]
cnt = 0


def count_symmetry(S_symmetry):
    for i in range(N):
        for j in range(i + 1, N):
            if S_symmetry[i][j] != S_symmetry[j][i]:
                return False
    return True


for k in range(N):
    S_symmetry = S_list[k:] + S_list[:k]
    if count_symmetry(S_symmetry):
        cnt += 1

print(cnt * N)


Error: TLE

Fixed submission:

N = int(input())

cnt = 0
S_list = [input() for _ in range(N)]


def count_symmetry(S_symmetry):
    for i in range(N):
        for j in range(N):
            if S_symmetry[i][j] != S_symmetry[j][i]:
                return False
    return True


for k in range(N):
    S_symmetry = S_list[k:] + S_list[:k]
    if count_symmetry(S_symmetry):
        cnt += 1

print(cnt * N)
Problem p03370 (Python) — buggy submission, verdict: Time Limit Exceeded

N, X = map(int, input().split())
ans = N
m_list = []

for i in range(N):
    m = int(input())
    m_list.append(m)

m_list.sort()
X -= sum(m_list)

ans += X // m_list[0]

print(ans)


Error: TLE

Fixed submission:

N, X = map(int, input().split())
m = [int(i) for i in range(N)]
m.sort()
ans = 3

X -= sum(m)


while X >= m[0]:
    X -= m[0]
    ans += 1

print(ans)
Problem p03370 (Python) — buggy submission, verdict: Runtime Error

N, X = map(int, input().split())
M = [int(input()) for _ in range(N)]
ans = 0
for m in M:
    X -= m
    ans += 1
ans += X // min(M)
print(ans)


Error: TypeError: 'list' object cannot be interpreted as an integer
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03370/Python/s961847795.py", line 4, in <module>
    for m in range(M):
TypeError: 'list' object cannot be interpreted as an integer


Fixed submission:

N, X = map(int, input().split())
M = [int(input()) for _ in range(N)]
ans = 0
for m in range(M):
    X -= m
    ans += 1
ans += X // min(M)
print(ans)
Problem p03371 (Python) — buggy submission, verdict: Runtime Error

A, B, C, X, Y = map(int, input().split())
sum = 0

while X > 0 or Y > 0:
    if X > 0 and Y > 0:
        if A + B > 2 * C:
            sum += 2 * C
            X -= 1
            Y -= 1
        else:
            sum += A + B
            X -= 1
            Y -= 1
    else:
        if X > 0:
            if A > 2 * C:
                sum += 2 * C
                X -= 1
                Y -= 1
            else:
                sum += A
                X -= 1
        else:
            if B > 2 * C:
                sum += 2 * C
                X -= 1
                Y -= 1
            else:
                sum += B
                Y -= 1

print(sum)


Error: TypeError: unsupported operand type(s) for +=: 'builtin_function_or_method' and 'int'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03371/Python/s190876666.py", line 5, in <module>
    sum += C
TypeError: unsupported operand type(s) for +=: 'builtin_function_or_method' and 'int'


Fixed submission:

A, B, C, X, Y = map(int, input().split())

while X > 0 or Y > 0:
    if A + B > C:
        sum += C
        X -= 1
        Y -= 1
    else:
        sum += A + B
        X -= 1
        Y -= 1
    if X > 0 and Y > 0:
        continue
    if X > 0:
        if A > C:
            sum += C
            X -= 1
            Y -= 1
        else:
            sum += A
            X -= 1
    else:
        if B > C:
            sum += C
            X -= 1
            Y -= 1
        else:
            sum += B
            Y -= 1

print(sum)
Problem p03371 (Python) — buggy submission, verdict: Runtime Error

A, B, C, X, Y = list(map(int, input().split()))

# A 1枚、B 1枚を2C円で買うと捉え直す。
# ピザは、最大でも10**5枚（A, Bそれぞれに対して）
# A, Bのセットを、1~10**セットまで動かして一番安い組を考える

cheapest = float("inf")

for i in range(max(X, Y) + 1):

    price = 2 * C * i + A * max(0, X - i) + B * max(0, Y - i)

    cheapest = min(cheapest, price)

print(cheapest)


Error: TypeError: 'int' object is not iterable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03371/Python/s831575287.py", line 11, in <module>
    price = 2 * C * i + A * max(0, X - i) + B * max(Y - i)
TypeError: 'int' object is not iterable


Fixed submission:

A, B, C, X, Y = list(map(int, input().split()))

# A 1枚、B 1枚を2C円で買うと捉え直す。
# ピザは、最大でも10**5枚（A, Bそれぞれに対して）
# A, Bのセットを、1~10**セットまで動かして一番安い組を考える

cheapest = float("inf")

for i in range(max(X, Y) + 1):

    price = 2 * C * i + A * max(0, X - i) + B * max(Y - i)

    cheapest = min(cheapest, price)

print(cheapest)
Problem p03371 (Python) — buggy submission, verdict: Runtime Error

A, B, C, X, Y = map(int, input().split())
if A + B <= 2 * C:
    ans = A * X + B * Y
elif A + B > 2 * C:
    nokori = abs(X - Y)
    if X >= Y and A >= 2 * C:
        ans = C * 2 * X
    if Y >= X and B >= 2 * C:
        ans = C * 2 * Y
    if X >= Y and A <= 2 * C:
        ans = C * 2 * Y + nokori * A
    if Y >= X and B <= 2 * C:
        ans = C * 2 * X + nokori * B
print(ans)


Error: 0

Fixed submission:

A, B, C, X, Y = map(int, input().split())
if A + B < 2 * C:
    ans = A * X + B * Y
elif A + B >= 2 * C:
    nokori = abs(X - Y)
    if X >= Y and A >= 2 * C:
        ans = C * 2 * X
    if Y >= X and B >= 2 * C:
        ans = C * 2 * Y
    if X > Y and A < 2 * C:
        ans = C * 2 * Y + nokori * A
    if Y > X and B < 2 * C:
        ans = C * 2 * X + nokori * B
print(ans)
Problem p03371 (Python) — buggy submission, verdict: Runtime Error

#!/usr/bin/env python
# coding: utf-8
"""
purpose
"""


def main() -> None:
    """
    main function
    """
    (A, B, C, X, Y) = map(int, input().split())

    if 2 * C <= A + B:
        ans = C * min(X, Y) * 2 + min(
            max((X - Y) * A, (Y - X) * B), max(X - Y, Y - X) * C * 2
        )
    else:
        ans = A * X + B * Y

    print(ans)


if __name__ == "__main__":
    main()


Error: WA

Fixed submission:

#!/usr/bin/env python
# coding: utf-8
"""
purpose
"""


def main() -> None:
    """
    main function
    """
    (A, B, C, X, Y) = map(int, input().strip().split())

    if 2 * C <= B and 2 * C <= A:
        ans = (max(X, Y) * 2) * C
    elif 2 * C > A:
        ans = Y * 2 * C + max(X - Y, 0) * B
    elif 2 * C > B:
        ans = X * 2 * C + max(Y - X, 0) * A
    else:
        raise ValueError(f"{A}, {B}, {C}")

    print(ans)


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

N, C = map(int, input().split())

# x = 0 に v = 0 の寿司があると考える
X = [0]
V = [0]

for _ in range(N):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v)

# 0, v_1, v_1+v_2, v_1+v_2+v_3, ...
cumsum1 = [0]
for i in range(1, N + 1):
    cumsum1.append(cumsum1[-1] + V[i])

# 0, v_N, v_N+v_N-1, v_N+v_N-1+v_N-2, ...
cumsum2 = [0]
for i in range(N, 0, -1):
    cumsum2.append(cumsum2[-1] + V[i])

# 歩く範囲を弧ABと考える(A<=B)
# x_A = 0, x_1, x_2, ..., x_N
# x_B = x_A, ..., x_N

# 0, v_1-x_1, v_1+v_2-x_2, v_1+v_2+v_3-x_3, ...
f1 = [0]
# 0, v_1-2*x_1, v_1+v_2-2*x_2, v_1+v_2+v_3-2*x_3, ...
f2 = [0]
for i in range(1, N + 1):
    f1.append(cumsum1[i] - X[i])
    f2.append(cumsum1[i] - 2 * X[i])

f1_max = [0]
for i in range(1, N + 1):
    f1_max.append(max(f1_max[-1], f1[i]))
f2_max = [0]
for i in range(1, N + 1):
    f2_max.append(max(f2_max[-1], f2[i]))

ans = 0
# Bを全探索（固定する）
for i in range(N + 1):
    if i == 0:
        continue
    else:
        # 0 -> B(反時計回り、反転なし)
        ans = max(ans, cumsum1[i] - X[i])
        # 0 -> B(時計回り、反転なし)
        ans = max(ans, cumsum2[N + 1 - i] - (C - X[i]))
        # 0 -> A -> B(反転)
        ans = max(ans, f2_max[i - 1] + cumsum2[N + 1 - i] - (C - X[i]))
        # 0 -> B -> A(反転)
        ans = max(ans, f1_max[i - 1] + cumsum2[N + 1 - i] - 2 * (C - X[i]))

print(ans)


Error: TLE

Fixed submission:

N, C = map(int, input().split())

# x = 0 に v = 0 の寿司があると考える
X = [0]
V = [0]

for _ in range(N):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v)
# print(X)
# print(V)

# 0, v_1, v_1+v_2, v_1+v_2+v_3, ...
cumsum1 = [0]
for i in range(1, N + 1):
    cumsum1.append(cumsum1[-1] + V[i])

# 0, v_N, v_N+v_N-1, v_N+v_N-1+v_N-2, ...
cumsum2 = [0]
for i in range(N, 0, -1):
    cumsum2.append(cumsum2[-1] + V[i])

# print(cumsum1)
# print(cumsum2)

# 歩く範囲を弧ABと考える(A<=B)
# x_A = 0, x_1, x_2, ..., x_N
# x_B = x_A, ..., x_N
ans = 0

for i in range(N + 1):
    for j in range(i + 1, N + 1):
        # print(i, j)
        a = X[i]
        b = X[j]
        if i == 0:
            # 反時計回り(反転しない)
            ans = max(ans, cumsum1[j] - b)
            # 時計回り(反転しない)
            ans = max(ans, cumsum2[N + 1 - j] - (C - b))
        else:
            # O -> A -> B(反転)
            ans = max(ans, cumsum1[i] + cumsum2[N + 1 - j] - 2 * a - (C - b))
            # O -> B -> A(反転)
            ans = max(ans, cumsum1[i] + cumsum2[N + 1 - j] - 2 * (C - b) - a)

print(ans)
Problem p03373 (Python) — buggy submission, verdict: Runtime Error

A, B, C, X, Y = map(int, input().split())

ans = A * X + B * Y
if X >= 1 and Y >= 1:

    z = min(X, Y)
    ans = min(ans, A * (X - z) + B * (Y - z) + C * (z * 2))

    z = max(X, Y)
    ans = min(ans, A * max(0, (X - z)) + B * max(0, (Y - z)) + C * (z * 2))

print(ans)


Error: 0

Fixed submission:

A, B, C, X, Y = map(int, input().split())

if X >= 2 and Y >= 2:
    ans = A * X + B * Y
    if C * 2 < A + B:
        z = min(X // 2, Y // 2)
        ans = A * (X - z * 2) + B * (Y - z * 2) + C * (z * 4)

        z = max(X // 2, Y // 2)
        ans = min(ans, A * max(0, (X - z * 2)) + B * max(0, (Y - z * 2)) + C * (z * 4))

print(ans)
Problem p03377 (Python) — buggy submission, verdict: Runtime Error

a, b, x = map(int, input().split())

if a <= x <= a + b:
    print("YES")
else:
    print("NO")


Error: ValueError: invalid literal for int() with base 10: '3 5 4'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03377/Python/s414661619.py", line 1, in <module>
    a = int(input())
ValueError: invalid literal for int() with base 10: '3 5 4'


Fixed submission:

a = int(input())
b = int(input())
x = int(input())

if a <= x <= a + b:
    print("YES")
else:
    print("NO")
Problem p03379 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
X = list(map(int, input().split()))

Y = sorted(X)

l = Y[N // 2 - 1]
r = Y[N // 2]

for x in X:
    if l >= x:
        print(r)
    else:
        print(l)


Error: TLE

Fixed submission:

import numpy as np

N = int(input())
X = list(map(int, input().split()))

for i in range(N):
    B = X.copy()
    B.pop(i)
    print(int(np.median(B)))
Problem p03379 (Python) — buggy submission, verdict: Time Limit Exceeded

import statistics

n = int(input())
x = list(map(int, input().split()))
xmd = statistics.median(x)
xs = sorted(x)
for i in x:
    if i < xmd:
        print(xs[n // 2])
    else:
        print(xs[n // 2 - 1])


Error: TLE

Fixed submission:

import statistics
import copy

n = int(input())
a = list(map(int, input().split()))
ao = copy.copy(a)
for i in range(n):
    a.pop(i)
    print(statistics.median(a))
    a = copy.copy(ao)
Problem p03379 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
X = list(map(int, input().split()))

Xs = sorted(X)
median1 = Xs[int(N / 2) - 1]
median2 = Xs[int(N / 2)]

for i in range(N):
    if X[i] >= median2:
        print(median1)
    else:
        print(median2)


Error: TLE

Fixed submission:

from statistics import median

N = int(input())
X = list(map(int, input().split()))

for i in range(N):
    Xx = [X[k] for k in range(N) if k != i]
    print(median(Xx))
Problem p03379 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
X = list(map(int, input().split()))

M_small = sorted(X)[N // 2 - 1]
M_large = sorted(X)[N // 2]

for xi in X:
    if xi <= M_small:
        print(M_large)
    else:
        print(M_small)


Error: TLE

Fixed submission:

from copy import copy

N = int(input())
X = list(map(int, input().split()))

for xi in X:
    Y = copy(X)
    Y.remove(xi)
    print(sorted(Y)[N // 2 - 1])
Problem p03379 (Python) — buggy submission, verdict: Time Limit Exceeded

import copy

input = open(0).read

N, *X = map(int, input().split())


def main():
    a = copy.copy(X)
    l, r = sorted(a)[N // 2 - 1 : N // 2 + 1]

    print("\\n".join([str(r) if x < r else str(l) for x in X]))
    return


main()


Error: TLE

Fixed submission:

import copy

input = open(0).read

N, *X = map(int, input().split())


def main():
    a = copy.copy(X)
    a.sort()

    for i in range(N):
        print(a[N // 2] if a.index(X[i]) < N // 2 else a[N // 2 - 1])

    return


main()
Problem p03379 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
x = list(map(int, input().split()))
x1 = []
for i, xi in enumerate(x):
    x1.append([i, xi])

x_sort = sorted(x1, key=lambda x: x[1])
t = int(n / 2)
lxt = []
for i in range(n):
    if i < t:
        x[x_sort[i][0]] = x_sort[t][1]
    else:
        x[x_sort[i][0]] = x_sort[t - 1][1]

for i in range(n):
    print(x[i])


Error: TLE

Fixed submission:

n = int(input())
x = list(map(int, input().split()))
x1 = []
for i, xi in enumerate(x):
    x1.append([i, xi])

x_sort = sorted(x1, key=lambda x: x[1])
t = int(n / 2)
lxt = []
for i in range(n):
    if i < t:
        lxt.append(x_sort[i][0])
    else:
        break

for i in range(n):
    if i in lxt:
        print(x_sort[t][1])
    else:
        print(x_sort[t - 1][1])
Problem p03379 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
X = list(map(int, input().split()))

argsort = [[x, i] for i, x in enumerate(X)]
argsort.sort()

indices = {(i + 1): x for i, (x, _) in enumerate(argsort)}

argsort = [[i, j] for j, [_, i], in enumerate(argsort)]
argsort.sort()

ranks = [j + 1 for _, j in argsort]

median = N // 2
for i in range(0, N):
    r = ranks[i]
    if r <= median:
        print(indices[median + 1])
    else:
        print(indices[median])


Error: TLE

Fixed submission:

N = int(input())
X = list(map(int, input().split()))

argsort = [[x, i] for i, x in enumerate(X)]
argsort.sort()
argsort = [[i, j] for j, [_, i], in enumerate(argsort)]
argsort.sort()
ranks = [j + 1 for _, j in argsort]

indices = [[x, i] for i, x in enumerate(X)]
indices.sort()
indices = {(i + 1): x for i, (x, _) in enumerate(indices)}


median = N // 2
for i in range(0, N):
    r = ranks[i]
    if r <= median:
        print(indices[median + 1])
    else:
        print(indices[median])
Problem p03379 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
array = list(map(int, input().split()))
test = list(array)
test.sort()
wow = test[int(N / 2) - 1 : int(N / 2) + 1]
for i in range(0, N):
    if array[i] > wow[0]:
        print(wow[0])
    else:
        print(wow[1])


Error: TLE

Fixed submission:

N = int(input())
array = list(map(int, input().split()))
for i in range(0, N):
    konichiwa = list(array)
    konichiwa.pop(i)
    konichiwa.sort()
    print(konichiwa[int(N / 2) - 1])
Problem p03379 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
X = [int(i) for i in input().split()]
x = sorted(X)
n = N // 2
for i in range(N):
    if X[i] < x[n]:
        print(x[n])
    else:
        print(x[n - 1])


Error: TLE

Fixed submission:

N = int(input())
X = [int(i) for i in input().split()]
for i in range(N):
    x = [int(X[j]) for j in range(N) if i != j]
    x.sort()
    print(x[(N - 1) // 2])
Problem p03379 (Python) — buggy submission, verdict: Time Limit Exceeded

import statistics

N = int(input())
x = list(map(int, input().split()))
sx = sorted(x)
tmp = statistics.median(sx)

for i in range(N):
    if x[i] <= tmp:
        print(sx[((N - 1) // 2) + 1])
    else:
        print(sx[(N - 1) // 2])


Error: TLE

Fixed submission:

N = int(input())
x = list(map(int, input().split()))

for i in range(N):
    tmp = x.pop(i)
    tmplst = sorted(x)
    print(tmplst[(N - 1) // 2])
    x.insert(i, tmp)
Problem p03379 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
x = list(map(int, input().split()))

x2 = x.copy()
x2.sort()
c1 = x2[n // 2 - 1]
c2 = x2[n // 2]
for i in x:
    if c1 >= i:
        print(c2)
    else:
        print(c1)


Error: TLE

Fixed submission:

n = int(input())
x = list(map(int, input().split()))

c = (n - 1) // 2

for i in range(len(x)):
    x2 = x.copy()
    x2.pop(i)
    x2.sort()
    print(x2[c])
Problem p03379 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
x = list(map(int, input().split()))

sorted_x = sorted(x)

median_1 = sorted_x[n // 2 - 1]
median_2 = sorted_x[n // 2]

for i in range(n):
    if x[i] <= median_1:
        print(median_2)
    else:
        print(median_1)


Error: TLE

Fixed submission:

import numpy as np

n = int(input())
x = np.array(list(map(int, input().split(" "))))

sorted_x = sorted(x)
sorted_ind = list(np.argsort(x))
half_n = int(n / 2)

# print(x)
# print(half_n)
# print(sorted_ind)
# print(sorted_x)

for i in range(n):
    # print("==========")
    ind = sorted_ind.index(i)
    # print("ind: {}".format(ind))
    if ind <= half_n - 1:
        print(sorted_x[half_n - 1 + 1])
    else:
        print(sorted_x[half_n - 1])