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

import itertools
from collections import defaultdict
from sys import exit

N = int(input())
balls = sorted([tuple(map(int, input().split())) for _ in range(N)])

if N == 1:
    print(1)
    exit()

d = defaultdict(int)
for i, j in itertools.combinations(range(N), 2):
    d[(balls[j][0] - balls[i][0], balls[j][1] - balls[i][1])] += 1
print(N - max(d.values()))


Error: 0

Fixed submission:

import itertools
from collections import defaultdict

N = int(input())
balls = sorted([tuple(map(int, input().split())) for _ in range(N)])

d = defaultdict(int)
for i, j in itertools.combinations(range(N), 2):
    d[(balls[j][0] - balls[i][0], balls[j][1] - balls[i][1])] += 1
print(N - max(d.values()))
Problem p03006 (Python) — buggy submission, verdict: Runtime Error

from collections import defaultdict
from operator import itemgetter

N = int(input())
p = []
for _ in range(N):
    p.append(tuple(map(int, input().split())))
p.sort(key=itemgetter(0), reverse=True)

if N == 1:
    print(1)
else:
    d = defaultdict(int)
    for i, pp1 in enumerate(p):
        for j in range(i + 1, N):
            pp2 = p[j]
            d[(pp1[0] - pp2[0], pp1[1] - pp2[1])] += 1
        # print(d)

    cnt = 0
    keys = tuple(d.keys())
    for k in keys:
        x, y = k
        cnt = max(cnt, d[k] + d[(-x, -y)])

    print(N - cnt)


Error: 0

Fixed submission:

from collections import Counter
from operator import itemgetter

N = int(input())
p = []
for _ in range(N):
    p.append(tuple(map(int, input().split())))
p.sort(key=itemgetter(0), reverse=True)

d = []
for i, pp1 in enumerate(p):
    for j in range(i + 1, N):
        pp2 = p[j]
        d.append((pp1[0] - pp2[0], pp1[1] - pp2[1]))

c = Counter(d)

print(N - c.most_common()[0][1])
Problem p03006 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter

N = int(input())

p = []
for _ in range(N):
    p.append(tuple(map(int, input().split())))

if N == 1:
    print(1)
    exit()

d = []
for i, p1 in enumerate(p):
    for j, p2 in enumerate(p):
        if i == j:
            continue
        x = p1[0] - p2[0]
        y = p1[1] - p2[1]
        d.append((x, y))

c = Counter(d)
# print(c)
print(N - c.most_common()[0][1])


Error: 0

Fixed submission:

from collections import Counter

N = int(input())

p = []
for _ in range(N):
    p.append(tuple(map(int, input().split())))

d = []
for i, p1 in enumerate(p):
    for j, p2 in enumerate(p):
        if i == j:
            continue
        x = p1[0] - p2[0]
        y = p1[1] - p2[1]
        d.append((x, y))

c = Counter(d)
# print(c)
print(N - c.most_common()[0][1])
Problem p03006 (Python) — buggy submission, verdict: Runtime Error

import collections

N = int(input())

if N == 1:
    print(1)
    exit()

x_y = []
for _ in range(N):
    x_y.append(list(map(int, input().split())))

x_y.sort(key=lambda x: (x[0], x[1]))
pq_cand = []
for i in range(N):
    for j in range(i + 1, N):
        pq_cand.append((x_y[j][0] - x_y[i][0], x_y[j][1] - x_y[i][1]))

pqc = collections.Counter(pq_cand)
_, x = max(pqc.items(), key=lambda x: x[1])
print(N - 1 - x + 1)


Error: 0

Fixed submission:

import collections

N = int(input())
x_y = []
for _ in range(N):
    x_y.append(list(map(int, input().split())))

x_y.sort(key=lambda x: (x[0], x[1]))
pq_cand = []
for i in range(N):
    for j in range(i + 1, N):
        pq_cand.append((x_y[j][0] - x_y[i][0], x_y[j][1] - x_y[i][1]))

pqc = collections.Counter(pq_cand)
_, x = max(pqc.items(), key=lambda x: x[1])
print(N - 1 - x + 1)
Problem p03006 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter

N = int(input())

xys = []
for _ in range(N):
    xys.append(tuple(map(int, input().split())))

sub = []
for x1, y1 in xys:
    for x2, y2 in xys:
        if x1 != x2 or y1 != y2:
            sub.append((x1 - x2, y1 - y2))

if not sub:
    print(1)
    exit(0)

c = Counter(sub)
m = max(c.values())

print(N - m)


Error: 0

Fixed submission:

from collections import Counter

N = int(input())

xys = []
for _ in range(N):
    xys.append(tuple(map(int, input().split())))

sub = []
for x1, y1 in xys:
    for x2, y2 in xys:
        if x1 != x2 or y1 != y2:
            sub.append((x1 - x2, y1 - y2))

c = Counter(sub)
m = max(c.values())

print(N - m)
Problem p03006 (Python) — buggy submission, verdict: Runtime Error

import sys
import itertools

n = int(input())
xy_list = [list(map(int, input().split())) for _ in range(n)]
if n == 1:
    print(1)
    sys.exit()

counts = dict()
for (x1, y1), (x2, y2) in itertools.combinations(xy_list, 2):
    for pq in ((x2 - x1, y2 - y1), (x1 - x2, y1 - y2)):
        counts.setdefault(pq, 0)
        counts[pq] += 1
max_count = max(counts.values())
print(n - max_count)


Error: 0

Fixed submission:

import itertools

n = int(input())
xy_list = [list(map(int, input().split())) for _ in range(n)]
counts = dict()
for (x1, y1), (x2, y2) in itertools.combinations(xy_list, 2):
    for pq in ((x2 - x1, y2 - y1), (x1 - x2, y1 - y2)):
        counts.setdefault(pq, 0)
        counts[pq] += 1
max_count = max(counts.values())
print(n - max_count)
Problem p03006 (Python) — buggy submission, verdict: Runtime Error

from collections import defaultdict

n = int(input())
z = [list(map(int, input().split())) for _ in range(n)]
if n == 1:
    ans = 1
else:
    d = defaultdict(int)
    for i in range(n):
        xi, yi = z[i]
        for j in range(n):
            if i == j:
                continue
            xj, yj = z[j]
            d[(xi - xj, yi - yj)] += 1
    ans = n - max(d.values())
print(ans)


Error: 0

Fixed submission:

from collections import defaultdict

n = int(input())
z = [list(map(int, input().split())) for _ in range(n)]
d = defaultdict(int)
for i in range(n):
    xi, yi = z[i]
    for j in range(n):
        if i == j:
            continue
        xj, yj = z[j]
        d[(xi - xj, yi - yj)] += 1
print(n - max(d.values()))
Problem p03006 (Python) — buggy submission, verdict: Runtime Error

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

ans = 1
rates = {0: 0}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        vector = (inputs[i][0] - inputs[j][0], inputs[i][1] - inputs[j][1])
        rates[vector] = rates.get(vector, 0) + 1

print(N - max(rates.values()))


Error: 0

Fixed submission:

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

ans = 1
rates = {}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        vector = (inputs[i][0] - inputs[j][0], inputs[i][1] - inputs[j][1])
        rates[vector] = rates.get(vector, 0) + 1

print(N - max(rates.values()))
Problem p03006 (Python) — buggy submission, verdict: Runtime Error

import itertools
from collections import defaultdict


def main():
    N = int(input())
    if N == 1:
        print(1)

    else:
        XY = [list(map(int, input().split())) for _ in range(N)]

        dd = defaultdict(int)

        for xy1, xy2 in itertools.combinations(XY, 2):
            a = (xy2[0] - xy1[0], xy2[1] - xy1[1])
            b = (-a[0], -a[1])
            dd[a] += 1
            dd[b] += 1

        print(N - max(dd.values()))


main()


Error: 0

Fixed submission:

from collections import defaultdict


def main():
    N = int(input())
    XY = [list(map(int, input().split())) for _ in range(N)]

    dd = defaultdict(int)
    for i in range(N - 1):
        for j in range(i + 1, N):
            a = (XY[j][0] - XY[i][0], XY[j][1] - XY[i][1])
            dd[a] += 1

    pq = max(dd, key=dd.get)

    cnt = 0
    for x, y in XY:
        if [x + pq[0], y + pq[1]] in XY:
            cnt += 1

    print(N - cnt)


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

import sys
from collections import defaultdict
from itertools import combinations

input = sys.stdin.readline


def main():
    N = int(input())
    x = [0] * N
    y = [0] * N
    for i in range(N):
        x[i], y[i] = map(int, input().split())

    if N == 1:
        print(1)
        sys.exit()

    vector = defaultdict(int)
    for a, b in combinations(range(N), 2):
        dx = x[a] - x[b]
        dy = y[a] - y[b]
        if dx == 0:
            vector[(0, abs(dy))] += 1
        elif dx > 0:
            vector[(dx, dy)] += 1
        else:
            vector[(-dx, -dy)] += 1

    ans = N - max(vector.values())
    print(ans)


if __name__ == "__main__":
    main()


Error: 0

Fixed submission:

import sys
from collections import defaultdict
from itertools import combinations

input = sys.stdin.readline


def main():
    N = int(input())
    x = [0] * N
    y = [0] * N
    for i in range(N):
        x[i], y[i] = map(int, input().split())

    vector = defaultdict(int)
    for a, b in combinations(range(N), 2):
        dx = x[a] - x[b]
        dy = y[a] - y[b]
        if dx == 0:
            vector[(0, abs(dy))] += 1
        elif dx > 0:
            vector[(dx, dy)] += 1
        else:
            vector[(-dx, -dy)] += 1

    ans = N - max(vector.values())
    print(ans)


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

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


def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    if A[0] >= 0:
        printAllPlus(A)
    elif A[-1] <= 0:
        printAllMinus(A)
    else:
        printMixed(A)


def printMixed(nums):
    i = -1
    for k, n in enumerate(nums):
        if n >= 0:
            i = k
            break
    plus = nums[i:]
    minus = nums[:i]
    print(sum(plus) - sum(minus))
    while len(plus) > 1:
        p = plus.pop()
        m = minus.pop()
        print(m, p)
        minus.append(m - p)
    p0 = plus.pop()
    for m in minus:
        print(p0, m)
        p0 -= m


def printAllPlus(nums):
    ans = sum(nums) - 2 * nums[0]
    print(ans)
    tmp = nums[0]
    for n in nums[1:-1]:
        print(tmp, n)
        tmp -= n
    print(nums[-1], tmp)


def printAllMinus(nums):
    nums.reverse()
    ans = -sum(nums) + 2 * nums[0]
    print(ans)
    tmp = nums[0]
    for n in nums[1:]:
        print(tmp, n)
        tmp -= n


if __name__ == "__main__":
    main()


Error: WA

Fixed submission:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys


def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    if A[0] > 0:
        printAllPlus(A)
        sys.exit()
    elif A[N - 1] < 0:
        printAllMinus(A)
        sys.exit()

    i = -1
    for k, n in enumerate(A):
        if n >= 0:
            i = k
            break
    plus = A[i:]
    minus = A[:i]
    print(sum(plus) - sum(minus))
    while len(plus) > 1:
        p = plus.pop()
        m = minus.pop()
        print(m, p)
        minus.append(m - p)
    p0 = plus.pop()
    for m in minus:
        print(p0, m)
        p0 -= m


def printAllPlus(nums):
    ans = sum(nums) - 2 * nums[0]
    print(ans)
    tmp = nums[0]
    for n in nums[1:-1]:
        print(tmp, n)
        tmp -= n
    print(nums[-1], tmp)


def printAllMinus(nums):
    nums.reverse()
    ans = -sum(nums) + 2 * nums[0]
    print(ans)
    tmp = nums[0]
    for n in nums[1:]:
        print(tmp, n)
        tmp -= n


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

N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]


def count(n, a, b):
    a0, a1, a2 = a
    b0, b1, b2 = b
    dp = [0] * (n + 1)
    for i in range(n + 1):
        c0 = dp[i - a0] + b0 if i - a0 >= 0 else 0
        c1 = dp[i - a1] + b1 if i - a1 >= 0 else 0
        c2 = dp[i - a2] + b2 if i - a2 >= 0 else 0
        dp[i] = max(i, c0, c1, c2)
    return dp[n]


print(count(count(N, A, B), B, A))


Error: TLE

Fixed submission:

N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]


def count(n, a, b):
    a0, a1, a2 = a
    b0, b1, b2 = b
    dp = [0] * (n + 1)
    for i in range(n + 1):
        c0 = dp[i - a0] + b0 if i - a0 >= 0 else 0
        c1 = dp[i - a1] + b1 if i - a1 >= 0 else 0
        c2 = dp[i - a2] + b2 if i - a2 >= 0 else 0
        dp[i] = max([i, c0, c1, c2])
    return dp[n]


print(count(count(N, A, B), B, A))
Problem p03008 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    N = int(input())
    ga, sa, ba = map(int, input().split())
    gb, sb, bb = map(int, input().split())

    # A : ドングリと金属に変える
    # B : 全部ドングリに変える
    # B : ドングリと金属に変える（無駄な操作でロスがないので、いったんドングリ化してよい）
    # A : ドングリに変える

    dp1 = list(range(N + 1))  # dp1[巣から持ってきたドングリ数] = 取引所 B で持てる最大ドングリ数
    dp1[0] = 0
    for i in range(N + 1):
        if i >= ga:
            dp1[i] = max(dp1[i], dp1[i - ga] + gb)
        if i >= sa:
            dp1[i] = max(dp1[i], dp1[i - sa] + sb)
        if i >= ba:
            dp1[i] = max(dp1[i], dp1[i - ba] + bb)

    N = dp1[N]
    dp2 = list(range(N + 1))  # dp2[取引所 B から持ってきたドングリ数] = 巣に持ち帰れる最大ドングリ数
    for i in range(N + 1):
        if i >= gb:
            dp2[i] = max(dp2[i], dp2[i - gb] + ga)
        if i >= sb:
            dp2[i] = max(dp2[i], dp2[i - sb] + sa)
        if i >= bb:
            dp2[i] = max(dp2[i], dp2[i - bb] + ba)
    print(dp2[N])


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

N = int(input())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))

# 1 周目 : dp[巣から持ってきたドングリ数] = 取引所 B で持てる最大ドングリ数
dp = list(range(N + 1))
mas = tuple(zip(a, b))
for i in range(N + 1):
    for to_metal, to_acorn in mas:
        if i >= to_metal:
            dp[i] = max(dp[i], dp[i - to_metal] + to_acorn)
N = dp[N]

# 2 周目 : dp[取引所 B から持ってきたドングリ数] = 巣に持ち帰れる最大ドングリ数
dp = list(range(N + 1))
mas = tuple(zip(b, a))
for i in range(N + 1):
    for to_metal, to_acorn in mas:
        if i >= to_metal:
            dp[i] = max(dp[i], dp[i - to_metal] + to_acorn)
print(dp[N])
Problem p03011 (Python) — buggy submission, verdict: Runtime Error

p, q, r = map(int, input().split())
sorted_list = sorted([p, q, r])
ans = sorted_list[0] + sorted_list[1]
print(ans)


Error: TypeError: 'types.GenericAlias' object is not iterable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03011/Python/s382927375.py", line 2, in <module>
    sorted_list = sorted(list[p, q, r])
TypeError: 'types.GenericAlias' object is not iterable


Fixed submission:

p, q, r = map(int, input().split())
sorted_list = sorted(list[p, q, r])
ans = sorted_list[0] + sorted_list[1]
print(ans)
Problem p03011 (Python) — buggy submission, verdict: Runtime Error

p, q, r = map(int, input().split())
time = [p, q, r]

print(sum(time) - max(time))


Error: TypeError: 'builtin_function_or_method' object is not subscriptable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03011/Python/s963953736.py", line 3, in <module>
    print(sum[p, q, r] - max[p, q, r])
TypeError: 'builtin_function_or_method' object is not subscriptable


Fixed submission:

p, q, r = map(int, input().split())

print(sum[p, q, r] - max[p, q, r])
Problem p03011 (Python) — buggy submission, verdict: Runtime Error

s = list(map(int, input().split()))
s.sort()
print(s[0] + s[1])


Error: AttributeError: 'map' object has no attribute 'sort'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03011/Python/s230336688.py", line 2, in <module>
    s.sort()
AttributeError: 'map' object has no attribute 'sort'


Fixed submission:

s = map(int, input().split())
s.sort()
print(s[0] + s[1])
Problem p03011 (Python) — buggy submission, verdict: Runtime Error

A = list(map(int, input().split()))
ans = sum(A) - max(A)
print(ans)


Error: ValueError: invalid literal for int() with base 10: '1 3 4'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03011/Python/s647136581.py", line 1, in <module>
    A = [int(input()) for i in range(3)]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03011/Python/s647136581.py", line 1, in <listcomp>
    A = [int(input()) for i in range(3)]
ValueError: invalid literal for int() with base 10: '1 3 4'


Fixed submission:

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

ans = sum(A) - max(A)
print(ans)
Problem p03011 (Python) — buggy submission, verdict: Runtime Error

p = list(map(int, input().split()))
print(p[0] + p[1] + p[2] - max(p))


Error: TypeError: unsupported operand type(s) for +: 'int' and 'list'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03011/Python/s411748384.py", line 2, in <module>
    print(p[0] + p[1] + [2] - max(p))
TypeError: unsupported operand type(s) for +: 'int' and 'list'


Fixed submission:

p = list(map(int, input().split()))
print(p[0] + p[1] + [2] - max(p))
Problem p03011 (Python) — buggy submission, verdict: Runtime Error

# coding: utf-8

p, q, r = [int(x) for x in input().rstrip().split(" ")]

s = [0, 0, 0]
s[0] = p + q
s[1] = q + r
s[2] = r + p

print(min(s))


Error: IndexError: list assignment index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03011/Python/s517518252.py", line 6, in <module>
    s[0] = p + q
IndexError: list assignment index out of range


Fixed submission:

# coding: utf-8

p, q, r = [int(x) for x in input().rstrip().split(" ")]

s = []
s[0] = p + q
s[1] = q + r
s[2] = r + p

print(min(s))
Problem p03012 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
W = list(map(int, input().split()))
print(min([abs(sum(W[:i]) - sum(W[i:])) for i in range(N)]))


Error: TypeError: 'str' object cannot be interpreted as an integer
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03012/Python/s648426101.py", line 3, in <module>
    print(min([abs(sum(W[:i]) - sum(W[i:])) for i in range(N)]))
TypeError: 'str' object cannot be interpreted as an integer


Fixed submission:

N = input()
W = list(map(int, input().split()))
print(min([abs(sum(W[:i]) - sum(W[i:])) for i in range(N)]))
Problem p03013 (Python) — buggy submission, verdict: Runtime Error

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

A = [False] * (N + 1)

for _ in range(M):
    A[int(input())] = True

step = [0] * (N + 1)

step[0] = 1

for s in range(1, N + 1):
    if A[s]:
        step[s] = 0
        continue
    if s == 1:
        step[s] = 1
        continue
    else:
        step[s] = step[s - 1] + step[s - 2]
        step[s] %= 1000000007

print(step[N])


Error: IndexError: list assignment index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03013/Python/s337394668.py", line 6, in <module>
    A[int(input())] = True
IndexError: list assignment index out of range


Fixed submission:

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

A = []

for _ in range(M):
    A[int(input())] = True

step = [0] * (N + 1)

step[0] = 1

for s in range(1, N + 1):
    if A[s]:
        step[s] = 0
        continue
    if s == 1:
        step[s] = 1
        continue
    else:
        step[s] = step[s - 1] + step[s - 2]
        step[s] %= 1000000007

print(step[N])
Problem p03013 (Python) — buggy submission, verdict: Time Limit Exceeded

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

a = set()
for i in range(m):
    a_tmp = int(input())
    a.add(a_tmp)

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

dp = [0] * (n + 1)
for i in range(n + 1):
    if i in a:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])


Error: TLE

Fixed submission:

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

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

dp = [0] * (n + 1)
for i in range(n + 1):
    if i in a:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])
Problem p03013 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
q = 1000000007

if N == 1:
    if M == 0:
        print(1)
    elif M == 1:
        print(0)
else:
    cost = [0 for _ in range(N + 1)]
    cost[0] = 1

    cnt = 0
    A.append([0])
    for i in range(1, N + 1):
        if i == A[cnt]:
            cost[i] = 0
            cnt += 1
        else:
            cost[i] = (cost[i - 1] + cost[i - 2]) % q

    print(cost[-1])


Error: TLE

Fixed submission:

import numpy as np

N, M = map(int, input().split())
A = np.array([int(input()) for _ in range(M)])
q = 1000000007

cost = np.zeros(N + 1, dtype=np.int64)
cost[0] = 1
cost[1] = 1
cost[A] = 0
cost[2] = cost[0] + cost[1]

for i in range(1, N + 1):
    cost[A] = 0
    cost[i] = (cost[i - 1] + cost[i - 2]) % q

print(cost[-1])
Problem p03013 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())
broken_step = [0] * (N + 1)
for _ in range(M):
    n = int(input())
    broken_step[n] = 1

dp = [1] * (N + 1)
dp[1] = 0 if broken_step[1] == 1 else dp[0]

for i in range(2, N + 1):
    if broken_step[i] == 1:
        dp[i] = 0
    else:
        dp[i] = dp[i - 1] + dp[i - 2]

print(dp[-1] % 1000000007)


Error: 0

Fixed submission:

N, M = map(int, input().split())
broken_step = [0] * N
for _ in range(M):
    n = int(input())
    broken_step[n - 1] = 1

dp = [0] * N

dp[0] = 0 if broken_step[0] == 1 else 1
dp[1] = 0 if broken_step[1] == 1 else (1 + dp[0])

for i in range(2, N):
    if broken_step[i] == 1:
        dp[i] = 0
    else:
        dp[i] = dp[i - 1] + dp[i - 2]

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

MOD = 10**9 + 7
N, M = list(map(int, input().split()))
B = [True] * (N + 1)
D = [1] + [0] * N
for _ in range(M):
    a = int(input())
    B[a] = False
for i in range(N):
    for j in range(i + 1, min(N, i + 2) + 1):
        if B[j]:
            D[j] = (D[j] + D[i]) % MOD
print(D[N])


Error: TLE

Fixed submission:

INF = 1_000_000_007


def comb(n, k):
    k = min(n - k, k)
    if n == 0 or k == 0:
        return 1
    a = n
    for i in range(n - 1, n - k, -1):
        a *= i
    b = 1
    for i in range(2, k + 1):
        b *= i
    return a // b


N, M = list(map(int, input().split()))
A = [-1] + [int(input()) for _ in range(M)] + [N + 1]
res = 1
for i in range(M + 1):
    t = A[i + 1] - A[i] - 2
    if t < 0:
        res = 0
    else:
        _t = 0
        for i in range(t // 2 + 1):
            _t += comb(t - i, i)
        res *= _t
print(res % INF)
Problem p03013 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M, *A = map(int, read().split())

MOD = 10**9 + 7

dp = [0] * (N + 10)
dp[0] = 1
is_broken = [False] * (N + 1)

for x in A:
    is_broken[x] = True

for n in range(1, N + 1):
    if is_broken[n]:
        continue
    x = dp[n - 1] + dp[n - 2]
    if x >= MOD:
        x -= MOD
    dp[n] = x

answer = dp[N]
print(answer)


Error: TLE

Fixed submission:

MOD = 1000000007

n, m = map(int, input().split())
a = [int(input()) for i in range(m)]

f = [0] * (n + 1)
f[0] = 1

if 1 not in a:
    f[1] = 1

for i in range(2, n + 1):
    if i in a:
        continue
    f[i] = f[i - 1] + f[i - 2]
    if f[i] >= MOD:
        f[i] -= MOD

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

div = 1000000007

n, m, *b = map(int, open(0).read().split())
a = set(b)

f = [0] * (n + 1)
f[0] = 1

if 1 not in a:
    f[1] = 1

for i in range(2, n + 1):
    if i in a:
        continue
    f[i] = (f[i - 1] + f[i - 2]) % div

print(f[-1])


Error: TLE

Fixed submission:

div = 1000000007

n, m = map(int, input().split())
a = [int(input()) for i in range(m)]

f = [0] * (n + 1)
f[0] = 1

if 1 not in a:
    f[1] = 1

for i in range(2, n + 1):
    if i in a:
        continue
    f[i] = (f[i - 1] + f[i - 2]) % div

print(f[-1])