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

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [int(input()) for _ in range(m)]
for i in a:
    c = 0
    for j, k in zip(i, b):
        c += j * k
    print(c)


Error: ValueError: too many values to unpack (expected 2)
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02410/Python/s783362048.py", line 6, in <module>
    for j, k in i, b:
ValueError: too many values to unpack (expected 2)


Fixed submission:

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [int(input()) for _ in range(m)]
for i in a:
    c = 0
    for j, k in i, b:
        c += j * k
    print(c)
Problem p02410 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())
a = [None] * n
b = [None] * m
for i in range(n):
    a[i] = list(map(int, input().split()))
for i in range(m):
    b[i] = int(input())
for i in range(n):
    c = 0
    for j in range(m):
        c += a[i][j] * b[j]
    print(c)


Error: IndexError: list assignment index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02410/Python/s486424590.py", line 5, in <module>
    a[i] = list(map(int, input().split()))
IndexError: list assignment index out of range


Fixed submission:

n, m = map(int, input().split())
a = [[None] * n]
b = [None] * m
for i in range(n):
    a[i] = list(map(int, input().split()))
for i in range(m):
    b[i] = int(input())
for i in range(n):
    c = 0
    for j in range(m):
        c += a[i][j] * b[j]
    print(c)
Problem p02410 (Python) — buggy submission, verdict: Runtime Error

from sys import stdin

n, m = [int(x) for x in stdin.readline().rstrip().split()]
a = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(n)]
b = [[int(stdin.readline().rstrip())] for _ in range(m)]
c = [[0] for _ in range(n)]
for i in range(n):
    for j in range(m):
        c[i][0] += a[i][j] * b[j][0]

for i in range(n):
    print(*c[i])


Error: TLE

Fixed submission:

from sys import stdin
import numpy as np

n, m = [int(x) for x in stdin.readline().rstrip().split()]
a = np.asarray([[int(x) for x in stdin.readline().rstrip().split()] for _ in range(n)])
b = np.asarray([[int(stdin.readline().rstrip())] for _ in range(m)])
c = a.dot(b)
for i in range(n):
    print(*c[i])
Problem p02410 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())
List1 = [[0 for i in range(m)] for i in range(n)]
for x in range(n):
    List1[x] = list(map(int, input().split()))
List2 = [int(input()) for i in range(m)]
sum = [0 for i in range(n)]
for x in range(n):
    for y in range(m):
        sum[x] += List1[x][y] * List2[y]
for x in range(n):
    print(sum[x])


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02410/Python/s586106678.py", line 9, in <module>
    sum[x] += List1[x][y] * List2[y]
IndexError: list index out of range


Fixed submission:

n, m = map(int, input().split())
List1 = [[0 for i in range(m)] for i in range(n)]
for x in range(n):
    List1[x] = list(map(int, input().split()))
List2 = [int(input()) for _ in range(n)]
sum = [0 for i in range(n)]
for x in range(n):
    for y in range(m):
        sum[x] += List1[x][y] * List2[y]
for x in range(n):
    print(sum[x])
Problem p02413 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    a += [list(map(int, input().split()))]
    a[i] += [sum(a[i])]
for i in range(m + 1):
    b += [sum(x[i] for x in a)]
a += [b]
for i in range(n + 1):
    print(*a[i])


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


Fixed submission:

n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    a = [list(map(int, input().split()))]
    a[i] += [sum(a[i])]
for i in range(m):
    b += [a[:][i]]
    a += [b]
for i in range(n):
    print(*a[i])
Problem p02415 (Python) — buggy submission, verdict: Runtime Error

s = input()

for c in s:
    if c.islower():
        print(c.upper(), end="")
    else:
        print(c.lower(), end="")
print()


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02415/Python/s623323382.py", line 3, in <module>
    s = input()
EOFError: EOF when reading a line


Fixed submission:

print(input().swapcase())

s = input()

for c in s:
    if c.islower():
        print(c.upper(), end="")
    else:
        print(c.lower(), end="")
print()
Problem p02417 (Python) — buggy submission, verdict: Runtime Error

import sys

s = sys.stdin.read().lower()
count = [0 for i in range(26)]
for j in s:
    num = ord(j) - ord("a")
    if num >= 0 and num <= 25:
        count[num] += 1
for k in range(26):
    print(chr(k + 97) + " : " + str(count[k]))


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02417/Python/s778377943.py", line 4, in <module>
    sentence = input()
EOFError: EOF when reading a line


Fixed submission:

count = [0 for i in range(26)]
alpha = "abcdefghijklmnopqrstuvwxyz"
while True:
    sentence = input()
    if sentence == "":
        break
    for letter in sentence:
        letter.lower()
        num = 0
        for j in alpha:
            if letter == j:
                count[num] += 1
            else:
                num += 1
num = 0
for k in alpha:
    print(k + " : " + str(count[num]))
    num += 1
Problem p02419 (Python) — buggy submission, verdict: Runtime Error

W = input().upper()
T = []
while True:
    t = input()
    if t == "END_OF_TEXT":
        break
    T += [x.upper() for x in t.split()]
print(T.count(W))


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02419/Python/s097940891.py", line 4, in <module>
    t = input().lower()
EOFError: EOF when reading a line


Fixed submission:

W = input().lower()
T = ""
while True:
    t = input().lower()
    if t == "END_OF_TEXT":
        break
    T += t
print(T.count(W))
Problem p02472 (Python) — buggy submission, verdict: Runtime Error

print(sum(map(int, input().split())))


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


Fixed submission:

a = int(input())
b = int(input())
print(a + b)
Problem p02536 (Python) — buggy submission, verdict: Runtime Error

import sys

sys.setrecursionlimit(10**6)


def dfs(idx):
    for x in arr[idx]:
        if not vis[x]:
            vis[x] = True
            dfs(x)


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

arr = [[] * (n + 1) for _ in range(n + 1)]
vis = [False] * (n + 1)

for _ in range(m):
    a, b = map(int, sys.stdin.readline().split())
    arr[a].append(b)
    arr[b].append(a)

ans = 0

if m == 0:
    print(n - 1)
    sys.exit()

dfs(1)
for i in range(2, n + 1):
    if not vis[i]:
        vis[i] = True
        dfs(i)
        ans += 1

print(ans)


Error: 0

Fixed submission:

import sys


def dfs(idx):
    for x in arr[idx]:
        if not vis[x]:
            vis[x] = True
            dfs(x)


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

arr = [[] * (n + 1) for _ in range(n + 1)]
vis = [False] * (n + 1)

for _ in range(m):
    a, b = map(int, sys.stdin.readline().split())
    arr[a].append(b)
    arr[b].append(a)

ans = 0

dfs(1)
for i in range(2, n + 1):
    if not vis[i]:
        vis[i] = True
        dfs(i)
        ans += 1
for i in range(1, n + 1):
    if not vis[i]:
        ans += 1
print(ans)
Problem p02537 (Python) — buggy submission, verdict: Runtime Error

class SegmentTree:
    def __init__(self, n, op, e):
        self.n = 1 << (n - 1).bit_length()
        self.op = op
        self.e = e
        self.data = [e] * (2 * self.n)

    def update(self, k, v):
        k += self.n
        self.data[k] = v
        while k > 0:
            k >>= 1
            self.data[k] = self.op(self.data[2 * k], self.data[2 * k + 1])

    def query(self, left, right):
        left += self.n
        right += self.n
        l_res = self.e
        r_res = self.e
        while left < right:
            if left & 1:
                l_res = self.op(l_res, self.data[left])
                left += 1
            left >>= 1
            if right & 1:
                right -= 1
                r_res = self.op(self.data[right], r_res)
            right >>= 1
        return self.op(l_res, r_res)


N, K, *A = map(int, open(0).read().split())
t = SegmentTree(650_000, max, 0)
ans = 0
for a in A:
    t.update(a, 1 + t.query(max(0, a - K), min(a + K, 300_000) + 1))
print(t.query(0, 300_001))


Error: 0

Fixed submission:

class SegmentTree:
    def __init__(self, n, op, e):
        self.n = 1 << (n - 1).bit_length()
        self.op = op
        self.e = e
        self.data = [e] * (2 * self.n)

    def update(self, k, v):
        k += self.n
        self.data[k] = v
        while k > 0:
            k >>= 1
            self.data[k] = self.op(self.data[2 * k], self.data[2 * k + 1])

    def query(self, left, right):
        left += self.n
        right += self.n
        l_res = self.e
        r_res = self.e
        while left < right:
            if left & 1:
                l_res = self.op(l_res, self.data[left])
                left += 1
            left >>= 1
            if right & 1:
                right -= 1
                r_res = self.op(self.data[right], r_res)
            right >>= 1
        return self.op(l_res, r_res)


N, K, *A = map(int, open(0).read().split())
t = SegmentTree(400_000, max, 0)
dp = [1] * N
ans = 0
for i in range(N):
    a = A[i]
    t.update(a, 1 + t.query(max(1, a - K), a + K + 1))
print(t.query(0, 400_000))
Problem p02540 (Python) — buggy submission, verdict: Time Limit Exceeded

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]


N = int(input())

uf = UnionFind(N)

xy = []
min_y = []
for i in range(N):
    x, y = map(int, input().split())
    xy.append((x, y, i))
    min_y.append(y)

xy.sort()

min_y = N + 1

for i in range(N - 1):
    x, y, a = xy[i]
    x1, y1, b = xy[i + 1]
    min_y = min(min_y, y)
    if min_y != N - i:
        uf.union(a, b)

for i in range(N):
    print(uf.get_size(i))


Error: TLE

Fixed submission:

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]


N = int(input())

uf = UnionFind(N)

xy = []
min_y = []
for i in range(N):
    x, y = map(int, input().split())
    xy.append((x, y, i))
    min_y.append(y)

xy.sort()

s = set()

for i in range(N):
    x, y, a = xy[i]
    s.add(i)

    remove = set()
    for j in s:
        if j == i:
            continue

        x2, y2, b = xy[j]

        if y2 < y:
            uf.union(b, a)
            root = uf.find(b)
            if min_y[root] > y:
                min_y[root] = y
                remove.add(j)
            else:
                remove.add(i)
    s -= remove

for i in range(N):
    print(uf.get_size(i))
Problem p02542 (Python) — buggy submission, verdict: Runtime Error

import networkx as nx

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

S = [list(input()) for _ in range(n)]
G = nx.DiGraph()

start = (n, m)
cnt = 0
goal = (n, m + 1)

for i in range(n):
    for j in range(m):
        if S[i][j] != "#":
            if S[i][j] == "o":
                cnt += 1
                G.add_edge(start, (i, j), capacity=1)
            if i + 1 < n:
                if S[i + 1][j] != "#":
                    G.add_edge((i, j), (i + 1, j), weight=-1)
            if j + 1 < m:
                if S[i][j + 1] != "#":
                    G.add_edge((i, j), (i, j + 1), weight=-1)
            G.add_edge((i, j), goal, capacity=1)
# G.add_node(start, demand=cnt)
# G.add_node(goal, demand=-cnt)
mincostflow = nx.max_flow_min_cost(G, start, goal)
ans = nx.cost_of_flow(G, mincostflow)
print(abs(ans))


Error: 0

Fixed submission:

import networkx as nx

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

S = [list(input()) for _ in range(n)]
G = nx.DiGraph()

start = (n, m)
cnt = 0
goal = (n, m + 1)

for i in range(n):
    for j in range(n):
        if S[i][j] != "#":
            if S[i][j] == "o":
                cnt += 1
                G.add_edge(start, (i, j), capacity=1)
            if i + 1 < n:
                if S[i + 1][j] != "#":
                    G.add_edge((i, j), (i + 1, j), weight=-1)
            if j + 1 < m:
                if S[i][j + 1] != "#":
                    G.add_edge((i, j), (i, j + 1), weight=-1)
            G.add_edge((i, j), goal, capacity=1)
# G.add_node(start, demand=cnt)
# G.add_node(goal, demand=-cnt)
mincostflow = nx.max_flow_min_cost(G, start, goal)
ans = nx.cost_of_flow(G, mincostflow)
print(abs(ans))
Problem p02546 (Python) — buggy submission, verdict: Runtime Error

N = input()

if N[len(N) - 1] == "s":
    N += "es"
else:
    N += "s"
print(N)


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02546/Python/s030233294.py", line 8, in <module>
    N = input()
EOFError: EOF when reading a line


Fixed submission:

N = input()

if N[len(N) - 1] == "s":
    N += "es"
else:
    N += "s"
print(N)
N = input()

if N[len(N) - 1] == "s":
    N += "es"
else:
    N += "s"
print(N)
Problem p02548 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
result = 0
for i in range(1, N + 1):
    s = int(N / i) + 1
    for j in range(s + 1, 0, -1):
        if N - i * j > 0:
            result = result + j
            break
print(result)


Error: TLE

Fixed submission:

N = int(input())
result = 0
for i in range(1, N + 1):
    s = int(N / i) + 1
    for j in range(1, s + 1):
        if N - i * j > 0:
            result = result + 1
        else:
            break
print(result)
Problem p02548 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())

result = 0
for A in range(1, N + 1):
    result += (N - 1) // A
print(result)


Error: TLE

Fixed submission:

N = int(input())

result = 0
for A in range(1, N + 1):
    for B in range(1, (N // A) + 1):
        C = N - A * B
        if C == 0:
            continue
        result += 1
print(result)
Problem p02548 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
ans = 0
for a in range(1, n):
    for b in range(1, n):
        if a * b >= n:
            break
        else:
            ans += 1
print(ans)


Error: TLE

Fixed submission:

n = int(input())

# 約数列挙O(√N)


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    return divisors


ans = 0
for c in range(1, n):
    ans += len(make_divisors(n - c))
print(ans)
Problem p02548 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
ans = 0
for a in range(1, N):
    ans += (N - 1) // a
print(ans)


Error: TLE

Fixed submission:

from collections import Counter

N = int(input())


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


count = 0
for c in range(1, N):
    d = Counter(prime_factorize(N - c))

    tmp = 1
    for x in d.values():
        tmp *= x + 1
    count += tmp

print(count)
Problem p02548 (Python) — buggy submission, verdict: Runtime Error

# coding:utf-8
n = int(input())
ans = 0

for a in range(1, n):
    ans += (n - 1) // a

print(ans)


Error: ZeroDivisionError: integer division or modulo by zero
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02548/Python/s983821669.py", line 6, in <module>
    ans += (n - 1) // a
ZeroDivisionError: integer division or modulo by zero


Fixed submission:

# coding:utf-8
n = int(input())
ans = 0

for a in range(n):
    ans += (n - 1) // a

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

p = 998244353
n, k = map(int, input().split())
LRs = [tuple(map(int, input().split())) for _ in range(k)]
A = [0] * (2 * n + 1)
for lj, rj in LRs:
    A[lj] += 1
    A[rj + 1] -= 1
s = 0
for i in range(1, n):
    s = (s + A[i]) % p
    for lj, rj in LRs:
        A[i + lj] += s
        A[i + rj + 1] -= s
print(s)


Error: 0

Fixed submission:

p = 998244353
n, k = map(int, input().split())
LRs = [tuple(map(int, input().split())) for _ in range(k)]
A = [0] * (2 * n)
for lj, rj in LRs:
    A[lj] += 1
    A[rj + 1] -= 1
s = 0
for i in range(1, n):
    s = (s + A[i]) % p
    for lj, rj in LRs:
        A[i + lj] += s
        A[i + rj + 1] -= s
print(s)
Problem p02549 (Python) — buggy submission, verdict: Time Limit Exceeded

N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]


mod = 998244353
dp = [0] * (N + 1)
dpsum = [0] * (N + 1)
dp[1] = 1
dpsum[1] = 1
for i in range(2, N + 1):
    for j in range(K):
        li = max(i - LR[j][1], 1)
        ri = i - LR[j][0]
        if ri < 0:
            continue
        dp[i] += dpsum[ri] - dpsum[li - 1]
        dp[i] %= mod
    dpsum[i] = dpsum[i - 1] + dp[i]

print(dp[N])


Error: TLE

Fixed submission:

N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]

dp = [0] * (N + 1)
dpsum = [0] * (N + 1)
dp[1] = 1
dpsum[1] = 1
for i in range(2, N + 1):
    for j in range(K):
        li = max(i - LR[j][1], 1)
        ri = i - LR[j][0]
        if ri < 0:
            continue
        dp[i] += dpsum[ri] - dpsum[li - 1]
    dpsum[i] = dpsum[i - 1] + dp[i]

print(dp[N] % 998244353)
Problem p02549 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(k)]
dp = [0 for _ in range(n + 1)]
dp[1] = 1
s = 0
mod = 998244353

for i in range(1, n + 1):
    s += dp[i]
    for l, r in LR:
        if i + l <= n:
            dp[i + l] = (dp[i + l] + s) % mod
            if i + r + 1 <= n:
                dp[i + r + 1] = (dp[i + r + 1] - s) % mod

print(dp[n])


Error: TLE

Fixed submission:

n, k = map(int, input().split())
mod = 998244353
s = list()
for _ in range(k):
    l, r = map(int, input().split())
    s += range(l, r + 1)
s.sort()
dp = [0 for _ in range(n)]
dp[0] = 1
for i in range(n):
    for x in s:
        if x + i > n - 1:
            break
        dp[i + x] = (dp[i + x] + dp[i]) % mod

print(dp[-1])
Problem p02549 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    n, k = map(int, input().split())
    lr = [list(map(int, input().split())) for _ in range(k)]
    dp = [0] * (n + 1)
    dp[1] = 1
    dpsum = [0] * (n + 1)
    dpsum[1] = 1
    mod = 998244353

    for i in range(2, n + 1):
        for j in range(k):
            li = i - lr[j][1]
            ri = i - lr[j][0]
            if ri < 0:
                continue
            dp[i] = (dp[i] + dpsum[ri] - dpsum[li - 1]) % mod
        dpsum[i] = dpsum[i - 1] + dp[i]

    print(dp[-1] % mod)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

def main():
    n, k = map(int, input().split())
    ds = set()
    for _ in range(k):
        l, r = map(int, input().split())
        ds = ds | {i for i in range(l, r + 1)}
    dp = [0] * (n + 1)
    dp[1] = 1

    for i in range(1, n + 1):
        for d in ds:
            if i + d <= n:
                dp[i + d] = (dp[i + d] + dp[i]) % 998244353

    print(dp[-1] % 998244353)


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

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

LR = [tuple(map(int, input().split())) for _ in range(K)]
LR.sort()

dpsum = [0] * (N + 1)
dpsum[1] = 1
dp = [0] * (N + 1)
dp[1] = 1

for i in range(2, N + 1):
    for L, R in LR:
        l = i - R
        r = i - L

        if r < 0:
            continue
        l = max(l, 0)

        dp[i] += dpsum[r] - dpsum[l - 1]
        dp[i] %= mod
    dpsum[i] = dpsum[i - 1] + dp[i]

print(dp[N])


Error: TLE

Fixed submission:

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

LR = [tuple(map(int, input().split())) for _ in range(K)]
LR.sort()

dp = [0] * (N + 1)
dp[1] = 1
for i in range(1, N):
    if dp[i] <= 0:
        continue
    for L, R in LR:
        for d in range(L, R + 1):
            if i + d < N + 1:
                dp[i + d] += dp[i]
                dp[i + d] %= mod

print(dp[N])
Problem p02555 (Python) — buggy submission, verdict: Runtime Error

S = int(input())
if S == 1:
    print(0)
    exit()
MOD = 10**9 + 7
A = [0] * (S + 1)
A[0] = 1
A[1] = 0
A[2] = 0

cumsum = 1
for i in range(3, len(A)):
    A[i] = cumsum
    cumsum += A[i - 2]
    cumsum %= MOD
print(A[-1])


Error: 0

Fixed submission:

S = int(input())
MOD = 10**9 + 7
A = [0] * (S + 1)
A[0] = 1
A[1] = 0
A[2] = 0

cumsum = 1
for i in range(3, len(A)):
    A[i] = cumsum
    cumsum += A[i - 2]
    cumsum %= MOD
print(A[-1])
Problem p02555 (Python) — buggy submission, verdict: Time Limit Exceeded

from functools import lru_cache
import sys

sys.setrecursionlimit(2000)

s = int(input())
mod = 10**9 + 7


@lru_cache(maxsize=None)
def dfs(n):
    if n <= 2:
        return 0
    elif n == 3:
        return 1
    else:
        count = 1
        for i in range(3, n + 1):
            count += dfs(n - i)
            count %= mod

        return count % mod


ans = dfs(s)
print(ans)


Error: TLE

Fixed submission:

s = int(input())


def dfs(n):
    if n <= 2:
        return 0
    elif n == 3:
        return 1
    else:
        count = 1
        for i in range(3, n + 1):
            count += dfs(n - i)

        return count


ans = dfs(s)
print(ans)