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

import sys

sys.setrecursionlimit(100000)

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append((v, w))
    G[v].append((u, w))

C = [-1 for _ in range(N)]


def dfs(pos, color):
    C[pos] = color
    for e in G[pos]:
        if C[e[0]] != -1:
            continue
        # odd
        if e[1] & 1:
            c = 1 - color
            dfs(e[0], c)
        # even
        else:
            c = color
            dfs(e[0], c)


dfs(0, 0)
for i in range(N):
    print(C[i])


Error: 0

Fixed submission:

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append((v, w))
    G[v].append((u, w))

C = [-1 for _ in range(N)]


def dfs(pos, color):
    for e in G[pos]:
        if C[e[0]] != -1:
            continue
        # odd
        if e[1] & 1:
            c = 1 - color
            C[e[0]] = c
            dfs(e[0], c)
        # even
        else:
            c = color
            C[e[0]] = c
            dfs(e[0], c)


C[0] = 0
dfs(0, 0)
for i in range(N):
    print(C[i])
Problem p03044 (Python) — buggy submission, verdict: Runtime Error

import sys

sys.setrecursionlimit(10**9)


def dfs(v, p, dist):
    for u, w in tree[v]:
        if u == p:
            continue
        else:
            dist[u] = dist[v] + w
            dfs(u, v, dist)


n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    tree[u - 1].append((v - 1, w))
    tree[v - 1].append((u - 1, w))

dist = [0 for _ in range(n)]
dfs(0, -1, dist)

for i in dist:
    if i % 2 == 0:
        print(0)
    else:
        print(1)


Error: 0

Fixed submission:

def dfs(v, p, c):
    for u, w in tree[v]:
        res[v] = c
        if u == p:
            continue
        else:
            if w % 2 == 0:
                dfs(u, v, c)
            else:
                dfs(u, v, c + 1)


n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    tree[u - 1].append([v - 1, w])
    tree[v - 1].append([u - 1, w])

res = [0 for _ in range(n)]
dfs(0, -1, 0)

for i in res:
    print(i)
Problem p03044 (Python) — buggy submission, verdict: Runtime Error

import sys
from collections import defaultdict

sys.setrecursionlimit(100000)
input = sys.stdin.readline

N = int(input())
G = defaultdict(list)
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    G[u - 1].append((v - 1, w))
    G[v - 1].append((u - 1, w))
res = [None] * N


def dfs(v, c):
    res[v] = c
    for u, w in G[v]:
        if res[u] is not None:
            continue
        if w % 2 == 0:
            dfs(u, c)
        else:
            dfs(u, 1 - c)


dfs(0, 0)
for x in res:
    print(x)


Error: 0

Fixed submission:

import sys
from collections import defaultdict

input = sys.stdin.readline

N = int(input())
G = defaultdict(list)
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    G[u - 1].append((v - 1, w))
    G[v - 1].append((u - 1, w))
res = [None] * N


def dfs(v, c):
    res[v] = c
    for u, w in G[v]:
        if res[u] is not None:
            continue
        if w % 2 == 0:
            dfs(u, c)
        else:
            dfs(u, 1 - c)


dfs(0, 0)
for x in res:
    print(x)
Problem p03044 (Python) — buggy submission, verdict: Runtime Error

import sys

sys.setrecursionlimit(200000)

N = int(input())

neighbors = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    neighbors[u].append((v, w))
    neighbors[v].append((u, w))

ans = [None for _ in range(N)]


def dfs(v, p, c):
    ans[v - 1] = c
    for next_v, distance in neighbors[v]:
        if next_v == p:
            continue
        next_c = c if distance % 2 == 0 else 1 - c
        dfs(next_v, v, next_c)


dfs(1, -1, 0)
for e in ans:
    print(e)


Error: 0

Fixed submission:

N = int(input())

neighbors = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    neighbors[u].append((v, w))
    neighbors[v].append((u, w))

ans = [None for _ in range(N)]


def dfs(v, p, c):
    ans[v - 1] = c
    for next_v, distance in neighbors[v]:
        if next_v == p:
            continue
        next_c = c if distance % 2 == 0 else 1 - c
        dfs(next_v, v, next_c)


dfs(1, -1, 0)
for e in ans:
    print(e)
Problem p03044 (Python) — buggy submission, verdict: Time Limit Exceeded

import networkx as nx

N = int(input())
UVW = [list(map(int, input().split())) for _ in range(N - 1)]

G = nx.Graph()

color = [0 for _ in range(N)]

for u, v, w in UVW:
    G.add_edge(u - 1, v - 1, weight=w)

color[0] = -1

pred, dist = nx.dijkstra_predecessor_and_distance(G, 0)

c = [dist[i] for i in range(N)]
ans = [1 if i % 2 == 0 else 0 for i in c]
print(*ans)


Error: TLE

Fixed submission:

import networkx as nx

N = int(input())

UVW = [list(map(int, input().split())) for _ in range(N - 1)]

G = nx.Graph()

color = [0 for _ in range(N)]  # 0: tbd，1: white, 2: black

for u, v, w in UVW:
    G.add_edge(u - 1, v - 1, weight=w)

color[0] = -1

for i in range(N - 1):
    if color[i] == 0 or i == 0:
        for j in range(i + 1, N):
            if color[j] == 0:
                d = nx.shortest_path_length(G, source=i, target=j, weight="weight")
                if int(d + 0.5) % 2 == 0:
                    color[j] = color[i]
                else:
                    color[j] = color[i] * -1

ans = [1 if i == -1 else 0 for i in color]
print(*ans)
Problem p03044 (Python) — buggy submission, verdict: Runtime Error

from sys import setrecursionlimit

setrecursionlimit(10**8)


def dfs(i, d):
    # print(i, d)
    for j, w in node_array[i]:
        if color_array[j] == -1:
            color_array[j] = (d + w) % 2
            dfs(j, d + w)


N = int(input())
node_array = [[] for i in range(N)]
color_array = [-1] * N

for _ in range(N - 1):
    i, j, w = map(int, input().split())
    node_array[i - 1].append((j - 1, w))
    node_array[j - 1].append((i - 1, w))

color_array[0] = 0
dfs(0, 0)

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


Error: 0

Fixed submission:

def dfs(i, d):
    # print(i, d)
    for j, w in node_array[i]:
        if color_array[j] == -1:
            color_array[j] = (d + w) % 2
            dfs(j, d + w)


N = int(input())
node_array = [[] for i in range(N)]
color_array = [-1] * N

for _ in range(N - 1):
    i, j, w = map(int, input().split())
    node_array[i - 1].append((j - 1, w))
    node_array[j - 1].append((i - 1, w))

color_array[0] = 0
dfs(0, 0)

for i in range(N):
    print(color_array[i])
Problem p03044 (Python) — buggy submission, verdict: Runtime Error

from collections import deque

N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u, v = u - 1, v - 1
    graph[u].append([v, w])
    graph[v].append([u, w])

colors = [-1 for _ in range(N)]
stack = deque()
stack.append(0)
colors[0] = 0

while stack:
    n = stack.popleft()
    for _next, w in graph[n]:
        if colors[_next] != -1:
            continue
        colors[_next] = (colors[n] + w) % 2
        stack.append(_next)

for c in colors:
    print(c)


Error: TypeError: list indices must be integers or slices, not list
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03044/Python/s113709906.py", line 18, in <module>
    for _next, w in graph[n]:
TypeError: list indices must be integers or slices, not list


Fixed submission:

from collections import deque

N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u, v, w = u - 1, v - 1, w % 2
    graph[u].append([v, w])
    graph[v].append([u, w])

colors = [-1 for _ in range(N)]
stack = deque()
stack.append(0)
colors[0] = 0

while stack:
    n = stack.pop()
    for _next, w in graph[n]:
        if colors[_next] != -1:
            continue
        colors[_next] = (colors[n] + w) % 2
        stack.append([_next])

for c in colors:
    print(c)
Problem p03045 (Python) — buggy submission, verdict: Time Limit Exceeded

import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import connected_components

N, M = map(int, input().split())
edge = np.array([input().split() for _ in range(M)], dtype=np.int64).T

matr = csr_matrix(([1 for _ in range(M)], (edge[:2] - 1)), (N, N))
print(connected_components(matr, return_labels=False))


Error: TLE

Fixed submission:

from scipy.sparse import lil_matrix
from scipy.sparse.csgraph import connected_components

N, M = map(int, input().split())
matr = lil_matrix((N, N))

for _ in range(M):
    x, y, z = map(int, input().split())
    matr[x - 1, y - 1] = matr[y - 1, x - 1] = 1

matr = matr.tocsr()
print(connected_components(matr, return_labels=False))
Problem p03045 (Python) — buggy submission, verdict: Time Limit Exceeded

n, m = map(int, input().split())

xy = [i for i in range(n + 1)]


def root(x):
    i = x
    while i != xy[i]:
        i = xy[i]
    xy[x] = i
    return i


for _ in range(m):
    x, y, z = map(int, input().split())
    rx = root(x)
    ry = root(y)
    if rx != ry:
        xy[ry] = rx

ans = -1
for i, v in enumerate(xy):
    if i == v:
        ans += 1

print(ans)


Error: TLE

Fixed submission:

n, m = map(int, input().split())

xy = [0 for _ in range(n + 1)]


def root(x):
    i = x
    while xy[i] != 0:
        i = xy[i]
    return i


for _ in range(m):
    x, y, z = map(int, input().split())
    rx = root(x)
    ry = root(y)
    if rx != ry:
        xy[ry] = rx

ans = 0
for i in xy[1:]:
    if i == 0:
        ans += 1

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

n, m = map(int, input().split())

p = list(range(n))


def find(x):
    if p[x] != x:
        p[x] = find(p[x])
    return p[x]


def union(x, y):
    x, y = find(x), find(y)
    p[x] = p[y] = min(x, y)


for _ in range(m):
    x, y, z = [int(i) - 1 for i in input().split()]
    if find(x) != find(y):
        union(x, y)

ans = set()
for i in range(n):
    find(i)
print(len(set(p)))


Error: 0

Fixed submission:

n, m = map(int, input().split())

p = list(range(n))


def find(x):
    if p[x] != x:
        p[x] = find(p[x])
    return p[x]


def union(x, y):
    x, y = find(x), find(y)
    p[y] = x


for _ in range(m):
    x, y, z = [int(i) - 1 for i in input().split()]
    if find(x) != find(y):
        union(x, y)

ans = set()
for i in range(n):
    find(i)
print(len(set(p)))
Problem p03047 (Python) — buggy submission, verdict: Runtime Error

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

print(N - K + 1)


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


Fixed submission:

N, K = map(int, input())

print(N - K + 1)
Problem p03047 (Python) — buggy submission, verdict: Runtime Error

N, K = map(int, input().split())
print(N - (K - 1))


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


Fixed submission:

N, K = map(int, input())
print(N - (K - 1))
Problem p03047 (Python) — buggy submission, verdict: Runtime Error

nk = list(map(int, input().split()))

print(nk[0] - nk[1] + 1)


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


Fixed submission:

n, k = list(map(int, input()))

print(n - k + 1)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
# input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
a, b, c, n = map(int, input().split())
ans = 0
for i in range(3001):
    for j in range(3001):
        if n >= i * a + j * b and (n - i * a - j * b) % c == 0:
            ans += 1
print(ans)


Error: TLE

Fixed submission:

#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
# input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
a, b, c, n = map(int, input().split())
ans = 0
for i in range(3001):
    for j in range(3001):
        if n <= i * a + j * b and (n - i * a - j * b) % c == 0:
            ans += 1
print(ans)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

r, g, b, n = map(int, input().split())

cnt = 0
for i in range(int(n // r) + 1):
    r_num = r * i
    for j in range(int((n - r_num) // g) + 1):
        g_num = g * j
        b_num = n - r_num - g_num
        if b_num >= 0 and b_num % b == 0:
            cnt += 1

print(cnt)


Error: TLE

Fixed submission:

r, g, b, n = map(int, input().split())

cnt = 0
for i in range(3001):
    for j in range(3001):
        x = n - (r * i + g * j)
        if x < 0:
            continue
        if x % b == 0:
            cnt += 1

print(cnt)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

R, G, B, n = map(int, input().split())
ans = 0
for r in range(n // R + 1):
    Rr = R * r
    for g in range((n - Rr) // G + 1):
        tmp = Rr + G * g
        if (n - tmp) % B == 0:
            ans += 1
print(ans)


Error: TLE

Fixed submission:

r, g, b, n = map(int, input().split())
arr = [r, g, b]
arr.sort()
ans = 0
for i in range(n // arr[2] + 1):
    if arr[2] * i > n:
        break
    for j in range(n // arr[1] + 1):
        tmp = arr[2] * i + arr[1] * j
        if tmp > n:
            break
        else:
            if tmp == n:
                ans += 1
                break
            elif n - tmp > 0 and (n - tmp) % arr[0] == 0:
                ans += 1

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

r, g, b, n = map(int, input().split())
c = sorted([r, g, b])[::-1]
ans = 0
for i in range(n // c[0] + 1):
    x = n - i * c[0]
    for j in range(x // c[1] + 1):
        y = x - j * c[1]
        if y < 0:
            break
        elif y % c[2] == 0:
            ans += 1
print(ans)


Error: TLE

Fixed submission:

r, g, b, n = map(int, input().split())
c = sorted([r, g, b])[::-1]
ans = 0
for i in range(n // c[0] + 1):
    for j in range((n - i * r) // c[1] + 1):
        x = n - i * c[0] - j * c[1]
        if x >= 0 and x % c[2] == 0:
            ans += 1
print(ans)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

r, g, b, n = map(int, input().split())

if r >= g and g >= b:
    pass
elif r >= b and b >= g:
    temp = g
    g = b
    b = temp
else:
    temp = r
    r = g
    g = temp

if (r == 1 and g == 1) or (r == 1 and b == 1) or (g == 1 and b == 1):
    rg = [i + 1 for i in range(n + 1)]
elif (
    (r == 1 and g == 2)
    or (r == 1 and b == 2)
    or (g == 1 and b == 2)
    or (r == 2 and g == 1)
    or (r == 2 and b == 1)
    or (g == 2 and b == 1)
):
    rg = [1 + i // 2 for i in range(n + 1)]
else:
    rg = [0 for _ in range(n + 1)]
    ri = 0
    while ri <= n:
        gi = 0
        while gi <= n - ri:
            rg[ri + gi] += 1
            gi += g
        ri += r

bi = 0
result = 0

while bi <= n:
    total = rg[n - bi]
    result += total
    bi += b

print(result)


Error: TLE

Fixed submission:

r, g, b, n = map(int, input().split())

if r >= g and g >= b:
    pass
elif r >= b and b >= g:
    temp = g
    g = b
    b = temp
else:
    temp = r
    r = g
    g = temp

rg = {}
ri = 0
while ri <= n:
    gi = 0
    while gi <= n - ri:
        if (n - ri - gi) % b == 0:
            total = rg.get(ri + gi, 0)
            rg[ri + gi] = total + 1
        else:
            pass
        gi += g
    ri += r

bi = 0
result = 0

while bi <= n:
    total = rg.get(n - bi, 0)
    result += total
    bi += b

print(result)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

R, G, B, N = map(int, input().split())
ans = 0
for r in range(N // R + 1):
    for g in range(N // G + 1):
        b = (N - R * r - G * g) / B
        if b == int(b) and b >= 0:
            ans += 1
print(ans)


Error: TLE

Fixed submission:

R, G, B, N = map(int, input().split())
ans = 0
for r in range(N + 1):
    for g in range(N + 1):
        b = (N - R * r - G * g) / B
        if b >= 0 and int(b) == b:
            ans += 1
print(ans)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

R, G, B, N = map(int, input().split())

res = 0

for i in range(N // R + 1):
    for j in range((N - R * i) // G + 1):
        b = N - R * i - G * j
        if b >= 0 and b % B == 0:
            res += 1

print(res)


Error: TLE

Fixed submission:

R, G, B, N = map(int, input().split())

res = 0

for i in range(N // R + 1):
    for j in range(N // G + 1):
        b = N - R * i - G * j
        if b >= 0 and b % B == 0:
            res += 1

print(res)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

R, G, B, N = map(int, input().split())

ans = 0
for r in range(N // R + 1):
    for g in range((N - R * r) // G + 1):
        tmp = N - r * R - g * G
        if tmp % B == 0:
            ans += 1

print(ans)


Error: TLE

Fixed submission:

R, G, B, N = map(int, input().split())

ans = 0
for r in range(N // R + 1):
    if N - r * R < 0:
        break
    for g in range((N - R * r) // G + 1):
        tmp = N - r * R - g * G
        if tmp < 0:
            break
        if tmp % B == 0 and tmp // B >= 0:
            ans += 1

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

r, g, b, n = map(int, input().split())
ans = 0
nr = n // r
ng = n // g
for i in range(nr + 1):
    for j in range(ng + 1):
        tmp = n - i * r - j * g
        if tmp >= 0 and tmp % b == 0:
            ans += 1
print(ans)


Error: TLE

Fixed submission:

r, g, b, n = map(int, input().split())
ans = 0
nr = n // r
ng = n // g
for i in range(nr + 1):
    for j in range(ng + 1):
        tmp = n - i * r - j * g
        if tmp % b == 0 and tmp >= 0:
            ans += 1
print(ans)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

def solve():
    R, G, B, N = map(int, input().split())
    LIM = 3001
    ans = 0
    for r in range(LIM):
        for g in range(LIM):
            if R * r + G * g > N:
                break
            Bb = N - R * r - G * g
            if Bb % B == 0:
                ans += 1
    return ans


print(solve())


Error: TLE

Fixed submission:

R, G, B, N = map(int, input().split())
LIM = 3003
ans = 0
for r in range(LIM):
    for g in range(LIM):
        if R * r + G * g > N:
            break
        Bb = N - R * r - G * g
        if Bb % B == 0:
            ans += 1
print(ans)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

R, G, B, N = map(int, input().split())
i = 0
for r in range(N // R + 1):
    Rr = r * R
    for g in range(N // G + 1):
        Gg = g * G
        Bb = N - Rr - Gg
        if Bb < 0:
            break
        if Bb % B == 0:
            i += 1
print(i)


Error: TLE

Fixed submission:

# import time
R, G, B, N = map(int, input().split())
# print(R, G, B)
i = 0
# r, g = 0, 0
# s = time.time()
for r in range(N // R + 1):
    for g in range(N // G + 1):
        if (N - r * R - g * G) >= 0:
            b = int((N - r * R - g * G) / B)
            if N - (r * R + g * G + b * B) == 0:
                # print(r, g, b)
                i += 1
print(i)
# print(time.time()-s)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

r, g, b, n = map(int, input().split())

count = 0
r, g, b = sorted([r, g, b], reverse=True)


for i in range(n // r + 1):
    rc = r * i
    for j in range((n - rc) // g + 1):
        gc = g * j
        if (n - rc - gc) % b == 0:
            count += 1
print(count)


Error: TLE

Fixed submission:

r, g, b, n = map(int, input().split())

count = 0
r, g, b = sorted([r, g, b])


for i in range(n // r + 1):
    total = r * i
    if total > n:
        continue
    for j in range((n - total) // g + 1):
        total = r * i + g * j
        if total > n:
            continue
        for k in range((n - total) // b + 1):
            total = r * i + g * j + b * k
            if total == n:
                count += 1

print(count)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

R, G, B, N = map(int, input().split())

ans = 0
for i in range(N // R + 1):
    for j in range((N - i * R) // G + 1):
        if (N - i * R - j * G) % B == 0:
            ans += 1
print(ans)


Error: TLE

Fixed submission:

R, G, B, N = map(int, input().split())

ans = 0
for i in range(N // R + 1):
    N_R = N - i * R
    for j in range(N_R // G + 1):
        N_RG = N_R - j * G
        for k in range(N_RG // B + 1):
            N_RGB = N_RG - k * B
            if N_RGB == 0:
                ans += 1
print(ans)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

R, G, B, N = map(int, input().split())

res = 0
for i in range(N // R + 1):
    for j in range((N - i * R) // G + 1):
        if (N - (i * R + j * G)) % B == 0:
            res += 1

print(res)


Error: TLE

Fixed submission:

R, G, B, N = map(int, input().split())

res = 0
for i in range(N // R + 1):
    for j in range(N // G + 1):
        b = N - (i * R + j * G)
        if b >= 0 and b % B == 0:
            res += 1
print(res)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

R, G, B, N = map(int, input().split())
ans = 0

for r in range(min(3000, 3000 // R) + 1):
    if R * r <= N:
        for g in range(min(3000, 3000 // G) + 1):
            v = R * r + G * g
            if N >= v and (N - v) % B == 0:
                ans += 1

print(ans)


Error: TLE

Fixed submission:

R, G, B, N = map(int, input().split())
ans = 0

for r in range(min(3000, 3000 // R) + 1):
    for g in range(min(3000, 3000 // G) + 1):
        v = R * r + G * g
        if N >= v and (N - v) % B == 0:
            ans += 1

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

R, G, B, N = map(int, input().split())
ans = 0
for r in range(N // R + 1):
    for g in range((N - R * r) // G + 1):
        if (N - (R * r + G * g)) % B == 0:
            ans += 1
print(ans)


Error: TLE

Fixed submission:

R, G, B, N = map(int, input().split())
ans = 0
for r in range(3001):
    if R * r > N:
        break
    for g in range(3001):
        if R * r + G * g > N:
            break
        elif (N - (R * r + G * g)) % B == 0:
            ans += 1
print(ans)
Problem p03048 (Python) — buggy submission, verdict: Time Limit Exceeded

r, g, b, n = map(int, input().split())
s_rgb = sorted([r, g, b], reverse=True)
count = 0
for i in range(int(n / s_rgb[0]) + 1)[::-1]:
    for j in range(int((n - s_rgb[0] * i) / s_rgb[1]) + 1)[::-1]:
        tmp = n - s_rgb[0] * i - s_rgb[1] * j
        if tmp >= 0 and tmp % s_rgb[2] == 0:
            count += 1
print(count)


Error: TLE

Fixed submission:

r, g, b, n = map(int, input().split())
s_rgb = sorted([r, g, b], reverse=True)
result = 0
for i in range(int(n / s_rgb[0]) + 1)[::-1]:
    for j in range(int((n - s_rgb[0] * i) / s_rgb[1]) + 1)[::-1]:
        if s_rgb[0] * i + s_rgb[1] * j > n:
            break
        for k in range(int((n - s_rgb[0] * i - s_rgb[1] * j) / s_rgb[2]) + 1)[::-1]:
            if s_rgb[0] * i + s_rgb[1] * j + s_rgb[2] * k > n:
                break
            if s_rgb[0] * i + s_rgb[1] * j + s_rgb[2] * k == n:
                result += 1
                break
print(result)