alexjercan/bugnet huggingface dataset:
Problem p02608 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())

ans = [0] * (n + 1)
for x in range(1, n + 1):
    if x**2 + x >= n:
        break
    for y in range(1, n + 1):
        if x**2 + y**2 + x * y + x + y >= n:
            break
        for z in range(1, n + 1):
            w = x**2 + y**2 + z**2 + x * y + y * z + z * x
            if w > n:
                break
            else:
                ans[w] += 1

for i in range(1, n + 1):
    print(ans[i])


Error: TLE

Fixed submission:

n = int(input())

for i in range(1, n + 1):
    ans = 0
    for x in range(1, n + 1):
        if x**2 + x >= i:
            continue
        for y in range(1, n + 1):
            if x**2 + y**2 + x * y >= i:
                continue
            for z in range(1, n + 1):
                if z**2 >= i:
                    continue

                if x**2 + y**2 + z**2 + x * y + y * z + z * x == i:
                    ans += 1

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

n = int(input())
ans = [0 for _ in range(10001)]
for i in range(1, 100):
    for j in range(1, 100):
        for k in range(1, 100):
            summ = i**2 + j**2 + k**2 + i * j + j * k + k * i
            if summ < 10001:
                ans[summ] += 1

for i in range(1, n + 1):
    print(ans[i])
# print(ans[20])


Error: WA

Fixed submission:

n = int(input())
ans = [0 for _ in range(1001)]
for i in range(1, 40):
    for j in range(1, 40):
        for k in range(1, 40):
            summ = i**2 + j**2 + k**2 + i * j + j * k + k * i
            if summ < 1001:
                ans[summ] += 1

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

n = int(input())

table = [0] * 10001

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            k = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x)
            if k < 10001:
                table[k] += 1

for i in range(1, n + 1):
    print(table[i])


Error: 0

Fixed submission:

n = int(input())

table = [0] * 1001

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            k = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x)
            if k < 1001:
                table[k] += 1

for i in range(1, n + 1):
    print(table[i])
Problem p02608 (Python) — buggy submission, verdict: Time Limit Exceeded

def main_v2():
    N = int(input())
    f_list = [0 for _ in range(N)]

    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                ans = x * x + y * y + z * z + x * y + y * z + z * x
                if ans <= N:
                    f_list[ans - 1] += 1

    for i in range(N):
        print(f_list[i])


if __name__ == "__main__":
    main_v2()


Error: TLE

Fixed submission:

import math


def main():
    N = int(input())

    for n in range(1, N + 1):
        count = 0

        for x in range(1, int(math.sqrt(2 * n)) + 1):
            for y in range(1, int(math.sqrt(2 * n)) + 1):
                for z in range(1, int(math.sqrt(2 * n)) + 1):
                    if (x + y) ** 2 + (y + z) ** 2 + (z + x) ** 2 == 2 * n:
                        count += 1
                        break

        print(count)


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

from collections import Counter

N = int(input())

counter = [0] * 10001
for x in range(1, N + 1):
    n1 = x * x
    if n1 >= N:
        continue
    for y in range(x, N + 1):
        n2 = n1 + y * y + x * y
        if n2 >= N:
            continue
        for z in range(y, N + 1):
            n = n2 + z * z + y * z + z * x
            if 1 <= n <= 10000:
                s = len(Counter([x, y, z]))
                if s == 1:
                    counter[n] += 1
                elif s == 2:
                    counter[n] += 3
                elif s == 3:
                    counter[n] += 6
for i in range(1, N + 1):
    print(counter[i])


Error: TLE

Fixed submission:

N = int(input())

for n in range(1, N + 1):
    max_xyz = 1
    for k in range(1, N + 1):
        if k * k > n:
            break
        max_xyz = k
    c = 0
    for x in range(1, k + 1):
        for y in range(1, k - x + 1):
            for z in range(1, k - x - y + 1):
                p = x * x + y * y + z * z + x * y + y * z + z * x
                if p == n:
                    c += 1
    print(c)
Problem p02608 (Python) — buggy submission, verdict: Time Limit Exceeded

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


def main():
    N = int(input())
    ans = [0] * (6 * 10**4 + 10)

    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                ans[x**2 + y**2 + z**2 + x * y + y * z + x * z - 1] += 1

    for i in range(N):
        print(ans[i])


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

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


def xyz(x, y, z):
    return x**2 + y**2 + z**2 + x * y + y * z + z * x


def main():
    N = int(input())
    # print(N)

    for i in range(1, N + 1):
        ans = 0
        for x in range(1, i):
            if x**2 > i:
                break
            for y in range(1, i):
                if y**2 > i:
                    break
                for z in range(1, i):
                    if z**2 > i:
                        break
                    if i == xyz(x, y, z):
                        ans += 1
        print(ans)


if __name__ == "__main__":
    main()
Problem p02609 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
X = input()

cnt = X.count("1")
res0 = 0
res1 = 0
for i in range(N):
    if X[i] == "1":
        res0 = (res0 + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)

        if cnt - 1 > 0:
            res1 = (res1 + pow(2, N - i - 1, cnt - 1)) % (cnt - 1)

for i in range(N):
    ans = 0
    if X[i] == "0":
        div = cnt + 1
        tmp = (res0 + pow(2, N - i - 1, div)) % div
        ans += 1
    else:
        if cnt - 1 > 0:
            div = cnt - 1
            tmp = (res1 + div - pow(2, N - i - 1, div)) % div
            ans += 1
        else:
            tmp = 0

    while tmp > 0:
        ans += 1
        div = bin(tmp).count("1")
        tmp %= div

    print(ans)


Error: 0

Fixed submission:

N = int(input())
X = input()

cnt = X.count("1")
div = [0] * (cnt + 10)
for i in range(1, cnt + 10):
    for n in range(20):
        div[i] += i >> n & 1

memo = [-1] * (cnt + 10)
memo[0] = 0
for i in range(1, cnt + 10):
    memo[i] = memo[i % div[i]] + 1

res0 = 0
res1 = 0
for i in range(N):
    if X[i] == "1":
        res0 = (res0 + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)
        res1 = (res1 + pow(2, N - i - 1, cnt - 1)) % (cnt - 1)

for i in range(N):
    if X[i] == "0":
        div = cnt + 1
        tmp = (res0 + pow(2, N - i - 1, div)) % div
    else:
        div = cnt - 1
        tmp = (res1 + div - pow(2, N - i - 1, div)) % div
    print(memo[tmp] + 1)
Problem p02609 (Python) — buggy submission, verdict: Runtime Error

#!/usr/bin/env python3
n = int(input())
x = input()
c = x.count("1")
m = 0
m2 = 0
for i in range(n):
    if x[i] == "1":
        m += pow(2, (n - i - 1), c + 1)
        m %= c + 1
m2 = 0
if c != 1:
    for i in range(n):
        if x[i] == "1":
            m2 += pow(2, (n - i - 1), c - 1)
            m2 %= c - 1

for i in range(n):
    if x[i] == "1":
        if c != 1:
            t = m2 - pow(2, (n - i - 1), c - 1)
            t %= c - 1
            count = 1
        else:
            t = 0
            count = 0
    else:
        t = m + pow(2, (n - i - 1), c + 1)
        t %= c + 1
        count = 1
    while t > 0:
        t %= bin(t).count("1")
        count += 1
    print(count)


Error: 0

Fixed submission:

#!/usr/bin/env python3
n = int(input())
x = input()
c = x.count("1")
m = 0
for i in range(n):
    if x[i] == "1":
        m += pow(2, (n - i - 1), c + 1)
m %= c + 1
m2 = 0
for i in range(n):
    if x[i] == "1":
        m2 += pow(2, (n - i - 1), c - 1)
m2 %= c - 1

for i in range(n):
    if x[i] == "1":
        t = m2 - pow(2, (n - i - 1), c - 1)
        t %= c - 1
    else:
        t = m + pow(2, (n - i - 1), c + 1)
        t %= c + 1
    count = 1
    while t > 0:
        t %= bin(t).count("1")
        count += 1
    print(count)
Problem p02609 (Python) — buggy submission, verdict: Runtime Error

import sys


def popcount(x: int):
    return bin(x).count("1")


def main():
    N = int(sys.stdin.readline().rstrip())
    X = sys.stdin.readline().rstrip()

    Xdec = int(X, 2)

    # 1回目の演算用
    md = popcount(Xdec)
    md_p, md_m = md + 1, md - 1

    tmp_p = Xdec % md_p
    if md_m > 0:
        tmp_m = Xdec % md_m

    for i in range(0, N, 1):
        if X[i] == "1":  # 1->0
            if md_m == 0:
                print(0)
                continue
            x_m = pow(2, (N - 1 - i), md_m)
            tmp = (tmp_m - x_m) % md_m

        if X[i] == "0":  # 0->1
            x_p = pow(2, (N - 1 - i), md_p)
            tmp = (tmp_p + x_p) % md_p

        cnt = 1
        while tmp:

            tmp = tmp % popcount(tmp)
            cnt += 1

        print(cnt)


main()


Error: UnboundLocalError: local variable 'tmp_m' referenced before assignment
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02609/Python/s102394639.py", line 47, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02609/Python/s102394639.py", line 32, in main
    tmp = (tmp_m - x_m) % md_m
UnboundLocalError: local variable 'tmp_m' referenced before assignment


Fixed submission:

import sys


def popcount(x: int):
    return bin(x).count("1")


def main():
    N = int(sys.stdin.readline().rstrip())
    X = sys.stdin.readline().rstrip()

    Xdec = int(X, 2)

    # X がゼロなら終了
    if Xdec == 0:
        print(0)
        return

    # 1回目の演算用
    md = popcount(Xdec)
    md_p, md_m = md + 1, md - 1

    tmp_p = Xdec % md_p
    if md_m == 0:
        tmp_m = Xdec % md_m

    for i in range(0, N, 1):
        if X[i] == "1":  # 1->0
            if md_m == 0:
                print(0)
            x_m = pow(2, (N - 1 - i), md_m)
            tmp = (tmp_m - x_m) % md_m

        if X[i] == "0":  # 0->1
            x_p = pow(2, (N - 1 - i), md_p)
            tmp = (tmp_p + x_p) % md_p

        cnt = 1
        while tmp:

            tmp = tmp % popcount(tmp)
            cnt += 1

        print(cnt)


main()
Problem p02609 (Python) — buggy submission, verdict: Runtime Error

def pop_count(n):
    return bin(n).count("1")


def f(n):
    if n == 0:
        return 0
    return f(n % pop_count(n)) + 1


N = int(input())
X = list(map(int, input()))
X_m = 0
X_p = 0
pop_X = X.count(1)
for i in range(N):
    if X[i] == 0:
        continue
    X_p += pow(2, N - i - 1, pop_X + 1)
    X_p %= pop_X + 1
    if pop_X > 1:
        X_m += pow(2, N - i - 1, pop_X - 1)
        X_m %= pop_X - 1

for i in range(N):
    ans = 1
    if X[i] == 0:
        ans += f((X_p + pow(2, N - i - 1, pop_X + 1)) % (pop_X + 1))
    elif pop_X > 1:
        ans += f((X_m - pow(2, N - i - 1, pop_X - 1)) % (pop_X - 1))
    else:
        ans = 0
    print(ans)


Error: 0

Fixed submission:

def pop_count(n):
    return bin(n).count("1")


N = int(input())
X = list(map(int, input()))
X_m = 0
X_p = 0
pop_X = 0
if 1 in X:
    pop_X += X.count(1)
    for i in range(N):
        if X[N - i - 1]:
            X_m += pow(2, i, pop_X - 1)
            X_m %= pop_X - 1
            X_p += pow(2, i, pop_X + 1)
            X_p %= pop_X + 1

for i in range(N):
    ans = 1
    n = 0
    if X[i]:
        n += X_m
        n -= pow(2, N - i - 1, pop_X - 1)
        n %= pop_X - 1
    else:
        n += X_p
        n += pow(2, N - i - 1, pop_X + 1)
        n %= pop_X + 1
    while n:
        n %= pop_count(n)
        ans += 1
    print(ans)
Problem p02612 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
n = n % 1000
if 1000 - n == 1000:
    print(0)
else:
    print(1000 - n)


Error: 0

Fixed submission:

n = input()
n = int(n[1:])
if 1000 - n == 1000:
    print(0)
else:
    print(1000 - n)
Problem p02612 (Python) — buggy submission, verdict: Runtime Error

# input
N = int(input())
noguchi = [1000 * n for n in range(1, 11)]

# check
print(min([ngc - N for ngc in noguchi if (ngc - N) >= 0]))


Error: 0

Fixed submission:

# input
N = int(input())
noguchi = [1000 * n for n in range(1, 11)]

# check
print(min([ngc - N for ngc in noguchi if (ngc - N) > 0]))
Problem p02612 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
yen = 1000

if N % 1000 == 0:
    ans = 0
else:
    while N > 0:
        N = N - yen
    ans = abs(N)

print(ans)


Error: 0

Fixed submission:

N = int(input())

yen = 1000

if N % 1000 == 0:
    ans = 0
else:
    n = str(N)
    a = int(n[1:])
    ans = yen - a

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

n = int(input())
if n % 1000 == 0:
    print("0")
else:
    print(((n // 1000) + 1) * 1000 - n)


Error: 0

Fixed submission:

n = list(input())
if int("".join(n)) % 1000 == 0:
    print("0")
else:
    print((10 - int(n[-3])) * 100)
Problem p02612 (Python) — buggy submission, verdict: Runtime Error

def main():
    N = int(input())
    if N % 1000 == 0:
        print(0)
    else:
        print(1000 - (N % 1000))


if __name__ == "__main__":
    main()


Error: TypeError: not all arguments converted during string formatting
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02612/Python/s991643016.py", line 7, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02612/Python/s991643016.py", line 3, in main
    return N % 1000
TypeError: not all arguments converted during string formatting


Fixed submission:

def main():
    N = input()
    return N % 1000


if __name__ == "__main__":
    main()
Problem p02613 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
a = [input() for i in range(N)]
c0 = a.count("AC")
c1 = a.count("WA")
c2 = a.count("TLE")
c3 = a.count("RE")
print("AC x", c0)
print("WA x", c1)
print("TLE x", c2)
print("RE x", c3)


Error: TypeError: can only concatenate str (not "int") to str
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02613/Python/s511049207.py", line 7, in <module>
    print("AC × " + c0)
TypeError: can only concatenate str (not "int") to str


Fixed submission:

N = int(input())
a = [input() for i in range(N)]
c0 = a.count("AC")
c1 = a.count("WA")
c2 = a.count("TLE")
c3 = a.count("RE")
print("AC × " + c0)
print("WA × " + c1)
print("TLE × " + c2)
print("RE × " + c3)
Problem p02614 (Python) — buggy submission, verdict: Runtime Error

import itertools

import numpy as np


def _run(H, W, K, C):
    input = np.zeros([H, W], dtype=np.int8)
    for h in range(H):
        for w in range(W):
            if C[h][w] == "#":
                input[h, w] = 1

    count = 0
    for r in itertools.product(*[[0, 1] for _ in range(H + W)]):
        copy_input = input.copy()
        for h in range(H):
            if r[h] == 1:
                copy_input[h] = 0
        for w in range(W):
            if r[H + w] == 1:
                copy_input[:, w] = 0

        if np.sum(copy_input) == K:
            count += 1
    print(count)


def _main():
    H, W, K = map(int, input().split())
    C = [str(input()) for _ in range(H)]
    _run(H, W, K, C)


if __name__ == "__main__":
    _main()


Error: TLE

Fixed submission:

import itertools

import numpy as np


def _run(H, W, K, C):
    input = np.zeros([H, W], dtype=np.int8)
    for h in range(H):
        for w in range(W):
            if C[h][w] == "#":
                input[h, w] = 1

    count = 0
    for r in itertools.product(*[[0, 1] for _ in range(H + W)]):
        copy_input = input.copy()
        for h in range(H):
            if r[h] == 1:
                copy_input[h] = 0
        for w in range(W):
            if r[H + w] == 1:
                copy_input[:, w] = 0

        if np.sum(copy_input) == K:
            count += 1
    print(count)


def _main():
    H, W, K = map(int, input().split())
    C = []
    for _ in range(H):
        C.append(list(map(str, input().split())))
    _run(H, W, K, C)


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

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

maxval = a[0]
cc = {maxval: 1}

ans = 0
idx = 0

for i in range(1, n):
    if a[i] in cc:
        cc[a[i]] += 2
    else:
        cc[a[i]] = 2
    cc[maxval] -= 1
    ans += maxval
    if cc[maxval] == 0:
        while 1:
            idx += 1
            if maxval > a[idx]:
                maxval = a[idx]
                break

print(ans)


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
a_set = sorted(set(a), key=a.index)

maxval = a[0]
cc = {maxval: 1}

ans = 0
idx = 0

for i in range(1, n):
    if a[i] in cc:
        cc[a[i]] += 2
    else:
        cc[a[i]] = 2
    cc[maxval] -= 1
    ans += maxval
    if cc[maxval] == 0:
        idx += 1
        maxval = a_set[idx]
    # print(cc)

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

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]

if n % 3 == 0:
    if n % 2 == 0:
        print(a[0] + sum(a[1 : n // 2]) * 2)
    else:
        print(a[0] + sum(a[1 : n // 2]) * 2 + a[n // 2])
elif n % 3 == 2:
    if n % 2 == 0:
        print(a[0] + sum(a[1 : n // 2]) * 2)
    else:
        print(a[0] + sum(a[1 : n // 2]) * 2 + a[n // 2])
else:
    if n % 2 == 0:
        print(a[0] + sum(a[1 : n // 2]) * 2)
    else:
        print(a[0] + sum(a[1 : n // 2]) * 2 + a[n // 2])


Error: TLE

Fixed submission:

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]

cur = [a[0], a[1]]
now = a[0]
for i in a[2:]:
    loc = 0
    maxer = min(cur[0], cur[-1])
    for j in range(1, len(cur)):
        temp = min(cur[j - 1], cur[j])
        if temp > maxer:
            loc = j
            maxer = temp
    now += maxer
    cur = cur[:loc] + [i] + cur[loc:]

print(now)
Problem p02615 (Python) — buggy submission, verdict: Time Limit Exceeded

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

A.sort()
from collections import deque

pot = deque([A.pop()])
com = 0
while A:
    com += pot.pop()
    new = A.pop()
    pot.appendleft(new)
    pot.appendleft(new)

print(com)


Error: TLE

Fixed submission:

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

A.sort()

pot = [A.pop()]
com = 0
while A:
    com += pot.pop()
    new = A.pop()
    pot.append(new)
    pot.append(new)
    pot.sort()

print(com)
Problem p02615 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = A[0]
cur = 1
count = 1
while True:
    if count <= N - 3:
        ans += A[cur] * 2
        count += 2
        cur += 1
    elif count == N - 2:
        ans += A[cur]
        count += 1
    elif count == N - 1:
        break
print(ans)


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = A[0]
cur = 1
count = 1
while True:
    if count <= N - 3:
        ans += A[cur] * 2
        count += 2
        cur += 1
    else:
        ans += A[cur]
        count += 1
    if count == N - 1:
        break
print(ans)
Problem p02615 (Python) — buggy submission, verdict: Runtime Error

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

a.sort(reverse=True)
ans = a[0]
cnt = 1
for i in range(1, n):
    if cnt == n - 1:
        break
    ans += a[i]
    cnt += 1
    if cnt == n - 1:
        break
    ans += a[i]
    cnt += 1
print(ans)


Error: 0

Fixed submission:

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

a.sort(reverse=True)
ans = a[0]
i = 1
while True:
    ans += a[i]
    i += 1
    if i == n - 1:
        break
    ans += a[i]
    i += 1
    if i == n - 1:
        break
print(ans)
Problem p02615 (Python) — buggy submission, verdict: Time Limit Exceeded

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

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

a_sorted = sorted(A, key=lambda x: -x)

circle = [a_sorted[0]]
ans = 0
for idx, a in enumerate(a_sorted[1:]):
    ans += circle[idx]
    circle.extend([a, a])

print(ans)


Error: TLE

Fixed submission:

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

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

a_sorted = sorted(A, key=lambda x: -x)

circle = [a_sorted[0]]
ans = 0
for a in a_sorted:
    tmp = 0
    tmp_idx = -1
    for i in range(len(circle) - 1):
        cand = min(circle[i], circle[i + 1])
        if cand > tmp:
            tmp = cand
            tmp_idx = i
    ans += tmp
    circle.insert(tmp_idx + 1, a)

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

import sys
from collections import deque

read = sys.stdin.buffer.read

N, *A = map(int, read().split())
A.sort(reverse=True)

deq = deque([A[0]])
ans = 0

for x in A[1:]:
    ans += deq.popleft()
    deq.append(x)
    deq.append(x)

print(ans)


Error: WA

Fixed submission:

from collections import deque

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

A.sort(reverse=True)

deq = deque([A[0]])
ans = 0

for x in A[1:]:
    print(f"{deq=}, {x=}")
    ans += deq.popleft()
    deq.append(x)
    deq.append(x)

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

n = int(input())
a = sorted(map(int, input().split()))[::-1]

ans, que = 0, [a[0]]
for i, ai in enumerate(a[1:]):
    ans += que[i]
    que += [ai, ai]
print(ans)


Error: TypeError: list indices must be integers or slices, not tuple
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02615/Python/s177267284.py", line 6, in <module>
    ans += que[i]
TypeError: list indices must be integers or slices, not tuple


Fixed submission:

n = int(input())
a = sorted(map(int, input().split()), reverse=True)

ans, que = 0, [a[0]]
for i in enumerate(a[1:]):
    ans += que[i]
    que += [i, i]
print(ans)
Problem p02615 (Python) — buggy submission, verdict: Runtime Error

from collections import deque

n = int(input())
a = sorted(map(int, input().split()), reverse=True)

ans, cnt = 0, deque([a[0]])
for i in a[1:]:
    ans += cnt.popleft()
    cnt.append(i)
    cnt.append(i)
print(ans)


Error: 0

Fixed submission:

from collections import deque

n = int(input())
a = sorted(map(int, input().split()), reverse=True)

ans, cnt = 0, deque([a[0]])
for i in a[1:]:
    ans += cnt.popleft()
    cnt.append(a[i])
    cnt.append(a[i])
print(ans)
Problem p02615 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
sum_com = 0
distinct_a = sorted(list(set(a)), reverse=True)
comfort = {i: 0 for i in distinct_a}
comfort[a[0]] = 1
max_com = 0

for ai in a[1:]:
    sum_com += distinct_a[max_com]
    if distinct_a[max_com] == ai:
        comfort[distinct_a[max_com]] += 1
    else:
        comfort[distinct_a[max_com]] -= 1
        comfort[ai] += 2
        if comfort[distinct_a[max_com]] == 0:
            max_com += 1

print(sum_com)


Error: TLE

Fixed submission:

n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
sum_com = a[0]
comfort = [a[1], a[1]]

for ai in a[2:]:
    sum_com += comfort[0]
    if comfort[0] == ai:
        comfort.append(ai)
    else:
        comfort.pop(0)
        comfort += [ai, ai]

print(sum_com)