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

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

if x[0] >= 0:
    print(x[k - 1])
    exit()
elif x[n - 1] < 0:
    print(abs(x[n - k]))
    exit()
else:
    for i in range(n):
        if x[i] >= 0:
            ori = i
            break

f_inf = float("inf")
res = f_inf
for i in range(max(ori - k, 0), min(ori + k, n) - k + 1):
    time = min(
        abs(x[i + k - 1] - x[i]) + abs(x[i + k - 1]),
        abs(x[i]) + abs(x[i + k - 1] - x[i]),
    )
    res = min(res, time)

print(res)


Error: 0

Fixed submission:

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

for i in range(n):
    if x[i] >= 0:
        ori = i
        break

f_inf = float("inf")
res = f_inf
for i in range(max(ori - k, 0), min(ori + k, n) - k + 1):
    time = abs(0 - x[i]) + abs(x[i + k - 1] - x[i])
    res = min(res, time)

print(res)
Problem p03274 (Python) — buggy submission, verdict: Runtime Error

from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
if 0 in x:
    x.remove(0)
    k -= 1
    n -= 1

if n == 0:
    print(0)
else:
    si = bisect_left(x, 0)

    ans = (x[-1] - x[0]) * 2
    if si + k - 1 < len(x):
        ans = min(ans, x[si + k - 1])
    if si - k >= 0:
        ans = min(ans, abs(x[si - k]))

    for i in range(n):
        tmp_ans = 0
        if i < si and i + k - 1 < len(x):
            tmp_ans = abs(x[i]) * 2 + x[i + k - 1]
            ans = min(ans, tmp_ans)
        elif i >= si and i - k + 1 >= 0:
            tmp_ans = x[i] * 2 + abs(x[i - k + 1])
            ans = min(ans, tmp_ans)

    print(ans)


Error: 0

Fixed submission:

from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
# if 0 in x:
#     x.remove(0)
#     k -= 1
#     n -= 1
#
# if n == 0:
#     print(0)

si = bisect_left(x, 0)


ans = x[-1] - x[0]
if si + k - 1 < len(x):
    ans = min(ans, x[si + k - 1])
if si - k >= 0:
    ans = min(ans, abs(x[si - k]))

for i in range(n):
    tmp_ans = 0
    if i < si:
        tmp_ans = abs(x[i]) * 2 + x[i + k - 1]
        ans = min(ans, tmp_ans)
    elif i - k + 1 >= 0:
        tmp_ans = x[i] * 2 + abs(x[i - k + 1])
        ans = min(ans, tmp_ans)

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

import numpy as np

N, K = map(int, input().split())
X = np.array(list(map(int, input().split())))
idx = np.searchsorted(X, 0)
# print('idx', idx)
ans = 10**10
for i in range(N - K + 1):
    l = i
    r = i + K - 1
    d1 = np.abs(X[l]) + np.abs(X[r] - X[l])
    d2 = np.abs(X[r]) + np.abs(X[r] - X[l])
    d = min(d1, d2)
    ans = min(ans, d)
print(ans)


Error: WA

Fixed submission:

N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = ((N - 1) + (K - 1 - 1)) // (K - 1)
print(ans)
Problem p03280 (Python) — buggy submission, verdict: Runtime Error

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

ans = (a - 1) * (b - 1)
print(ans)


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


Fixed submission:

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

ans = (a - 1) * (b - 1)
print(ans)
Problem p03280 (Python) — buggy submission, verdict: Runtime Error

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

total = a * b - (a + b - 1)

print(total)


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


Fixed submission:

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

total = a * b - (a + b - 1)

print(total)
Problem p03281 (Python) — buggy submission, verdict: Runtime Error

number = int(input())

num_eight_divisors = 0

numbers = list(range(9, number + 1, 2))

for i in range(9, number + 1, 2):
    divisors = [1, i]

    for j in range(2, i):
        q, mod = divmod(i, j)

        if mod == 0:
            divisors.append(j)
            divisors.append(q)

    if len(set(divisors)) == 8:
        num_eight_divisors = num_eight_divisors + 1

print(num_eight_divisors)


Error: TypeError: list.append() takes exactly one argument (2 given)
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03281/Python/s888176624.py", line 14, in <module>
    divisors.append(j, q)
TypeError: list.append() takes exactly one argument (2 given)


Fixed submission:

number = int(input())

num_eight_divisors = 0

numbers = list(range(9, number + 1, 2))

for i in range(9, number + 1, 2):
    divisors = [1, i]

    for j in range(2, i):
        q, mod = divmod(i, j)

        if mod == 0:
            divisors.append(j, q)

    if len(set(divisors)):
        num_eight_divisors = num_eight_divisors + 1

print(num_eight_divisors)
Problem p03281 (Python) — buggy submission, verdict: Runtime Error

# -*- coding: utf-8 -*-
# 標準入力を取得
N = int(input())


def divisor_count(n: int) -> int:
    ans = 0
    i = 1
    while i * i <= n:
        if n % i == 0:
            ans += 1
            if i != n // i:
                ans += 1
        i += 1
    return ans


# 求解処理
ans = 0
for n in range(1, N + 1, 2):
    if divisor_count(n) == 8:
        ans += 1

# 結果出力
print(ans)


Error: 0

Fixed submission:

# -*- coding: utf-8 -*-
# モジュールのインポート
import sympy as sp

# 標準入力を取得
N = int(input())

# 求解処理
ans = 0
for n in range(1, N + 1, 2):
    if sp.divisor_count(n) == 8:
        ans += 1

# 結果出力
print(ans)
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

s = input()
k = int(input())

len1s = 0
for i in range(len(s)):
    if s[i] == "1":
        len1s += 1
        continue
    else:
        res = s[i]
        break
else:
    res = "1"

if k <= len1s:
    ans = "1"
else:
    ans = res

print(ans)


Error: 0

Fixed submission:

s = input()
k = int(input())

for i in range(len(s)):
    if s[i] == "1":
        continue
    else:
        ans = s[i]
        break
    ans = "1"

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

S = input()
K = int(input())
key = 0
i = 0
while True:
    if i >= K:
        break
    if i >= len(S):
        break
    if int(S[i]) != 1:
        print(S[i])
        key = 1
        break
    i += 1

if key == 0:
    print(S[0])


Error: 0

Fixed submission:

S = input()
K = int(input())
key = 1
i = 0
while True:
    if i > 100:
        break
    if int(S[i]) != 1:
        print(S[i])
        key = 1
        break
    i += 1

if key == 0:
    print(S[0])
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

list_s = list(str(input()))
k = int(input())
bord = 10**9
for i in range(len(list_s)):
    if list_s[i] != "1":
        bord = i
        break
if k <= bord:
    print(1)
else:
    print(list_s[i])


Error: 0

Fixed submission:

list_s = list(str(input()))
k = int(input())
for i in range(len(list_s)):
    if list_s[i] != "1":
        bord = i
        break
if k <= bord:
    print(1)
else:
    print(list_s[i])
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

S = input()
K = int(input())

are_all_one = True
for i in range(len(S)):
    if S[i] != "1":
        are_all_one = False
        break

nth = i + 1
if are_all_one or K < nth:
    print(1)
    exit()

answer = S[i]
print(answer)


Error: 0

Fixed submission:

S = input()
K = int(input())

answer = S[1]
print(answer)
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

S = input()
K = int(input())

count = 0
while count < len(S):
    if S[count] == "1":
        count += 1
    else:
        break
if K > count:
    print(S[count])
else:
    print(1)


Error: 0

Fixed submission:

S = input()
K = int(input())

count = 0
while True:
    if S[count] == "1":
        count += 1
    else:
        break

if K > count:
    print(S[count])
else:
    print(1)
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

s = input()
k = int(input())
onesum = 0
while s[0] == "1":
    onesum += 1
    if len(s) == 1:
        break
    s = s[1:]
if k <= onesum:
    print(1)
else:
    print(s[0])


Error: 0

Fixed submission:

s = input()
k = int(input())
onesum = 0
while s[0] == "1" and len(s) > 0:
    s = s[1:]
    onesum += 1
if k <= onesum:
    print(1)
else:
    print(s[0])
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

S = input()
K = int(input())

# S = "111111111"
# K = 6565

ans = 1
ones = -1

for i in range(len(S)):
    if int(S[i]) == 1:
        pass
    else:
        ans = int(S[i])
        ones = i
        break

if ones == -1:
    ones = len(S) + 1

if K <= ones:
    ans = 1

print(ans)


Error: 0

Fixed submission:

S = input()
K = int(input())

ans = 1

for i in range(len(S)):
    if int(S[i]) == 1:
        pass
    else:
        ans = int(S[i])
        ones = i
        break

if not ones:
    ones = len(S) + 1
elif K <= ones:
    ans = 1

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

import sys


S = [int(_) for _ in list(input())]
K = int(input())
t = 0
while t <= len(S) - 1:
    if S[t] == 1:
        t += 1
    else:
        break

if K <= t:
    print(1)
    sys.exit()
else:
    print(S[t])
    sys.exit()


Error: 0

Fixed submission:

import sys


S = [int(_) for _ in list(input())]
K = int(input())
t = 0
while t <= len(S):
    if S[t] == 1:
        t += 1
    else:
        break

if K <= t:
    print(1)
    sys.exit()
else:
    print(S[t])
    sys.exit()
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:54:06 2020

@author: shinba
"""

s = input()
k = int(input())

cnt = 0

while s[cnt] == "1":
    cnt += 1
    if cnt == len(s):
        break

if cnt >= k:
    print(1)
else:
    print(s[cnt])


Error: 0

Fixed submission:

# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:54:06 2020

@author: shinba
"""

s = input()
k = int(input())

cnt = 0

while s[cnt] == "1":
    cnt += 1

if cnt >= k:
    print(1)
else:
    print(s[cnt])
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

s = list(input())
k = int(input())
for i in range(min(len(s), k)):
    if s[i] != "1":
        print(s[i])
        exit()
print(1)


Error: 0

Fixed submission:

s = list(input())
k = int(input())
number = 0
count = 0
for i in range(k):
    if s[i] == "1":
        count += 1
        if count == k - 1:
            number = 1
    elif s[i] != "1" and number == 0:
        number = s[i]
print(number)
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

s = input()
k = int(input())

ans = s[0]
for i in range(min(k, len(s))):
    if s[i] != "1":
        ans = s[i]
        break

print(ans)


Error: 0

Fixed submission:

s = input()
k = int(input())

for i in range(min(k, len(s))):
    if s[i] != "1":
        ans = s[i]
        break

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

S = input()
K = int(input())
ret = "1"
for i in range(K):
    if len(S) < i - 1:
        break
    if S[i] != "1":
        ret = S[i]
        break
print(ret)


Error: TypeError: 'int' object is not iterable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03282/Python/s935785504.py", line 4, in <module>
    for i in K:
TypeError: 'int' object is not iterable


Fixed submission:

S = input()
K = int(input())
ret = "1"
for i in K:
    if len(S) <= K:
        break
    if S[i] != "1":
        ret = S[i]
        break
print(ret)
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

def searchInf(s, k):
    l = k if len(s) >= k else len(s)
    for i in range(l):
        if s[i] == "1":
            continue
        else:
            print(s[i])
            return 0
    print(1)
    return 0


S = list(input())
K = int(input())
searchInf(S, K)


Error: 0

Fixed submission:

S = list(input())
K = int(input())
if not S[0] == "1":
    print(S[0])
else:
    print(S[1])
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

S = str(input())
k = int(input())
for i in range(k):
    if S[i] != "1":
        print(S[i])
        exit()
print("1")


Error: 0

Fixed submission:

S = str(input())
k = int(input())
if len(S) == 1:
    print(S)
    exit()
for i in range(10):
    if S[i] == "1" and int(S[i]) == k:
        print("1")
        break
    elif S[i] != "1":
        print(S[i])
        break
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 0
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")


Error: 0

Fixed submission:

S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 1
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

S = input()
K = int(input())
if K == S[:K].count("1"):
    print(1)
else:
    for c in S:
        if c != "1":
            print(c)
            break


Error: WA

Fixed submission:

S = input()
K = int(input())
if S[0] == "1":
    print(list(set(S))[1])
else:
    print(S[0])
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

s = input()
k = int(input())
rep = s.replace("1", "")
if len(rep) == 0:
    print("1")
else:
    if s.index(rep[0]) < k:
        print(rep[0])
    else:
        print("1")


Error: 0

Fixed submission:

s = input()
if "1" == s[0]:
    print(s.replace("1", "")[0])
else:
    print(s[0])
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

S = str(input())
K = int(input())
for i in range(0, K):
    if S[i] != "1":
        print(S[i])
        exit()
print(1)


Error: TypeError: 'str' object is not callable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03282/Python/s709061193.py", line 3, in <module>
    if S.count("1") == S(len):
TypeError: 'str' object is not callable


Fixed submission:

S = str(input())
K = int(input())
if S.count("1") == S(len):
    print(1)
    exit(0)
for s in S:
    if s != "1":
        print(s)
        exit()
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

S = input()
S_list = list(map(int, list(S)))
K = int(input())

S_set_under_K = set(S[:K])

if len(S) == 1:
    print(S)
elif len(S_set_under_K) == 1 and S_list[0] == 1:
    print(1)
else:
    for c in S:
        if c != "1":
            print(c)
            exit()


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03282/Python/s272308200.py", line 10, in <module>
    print(S_list[1])
IndexError: list index out of range


Fixed submission:

S = input()
S_list = list(map(int, S.split()))
K = int(input())

S_set_under_K = set(S[:K])

if len(S_set_under_K) == 1 and S_list[0] == 1:
    print(1)
else:
    print(S_list[1])
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

def solve():
    s = input()
    k = int(input())
    head_ones = 0
    for c in s:
        if c != "1":
            break
        else:
            head_ones += 1

    return "1" if head_ones >= k else [c for c in s if c != "1"][0]


if __name__ == "__main__":
    print(solve())


Error: 0

Fixed submission:

def solve():
    s = input()
    return [c for c in s if c != "1"][0]


if __name__ == "__main__":
    print(solve())
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

S = list(input())
K = int(input())
if K == 1:
    print(S[0])
    quit()

for i in range(K):
    if S[i] != "1":
        print(S[i])
        quit()

print("1")


Error: 0

Fixed submission:

S = str(input())
K = int(input())

if K == 1:
    print(S[0])
elif K >= 2:
    if S[0] != "1":
        print(S[0])
        quit()
    elif S[0:K] == "1" * K:
        print(S[0])
        quit()
    else:
        i = 1
        while S[i] == "1" and len(S) - 2 >= i:
            i += 1
        print(S[i])
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

S = input()
K = int(input())
flag = True

for i in range(K):
    if S[i] != "1":
        print(S[i])
        flag = False
        break

if flag:
    print(1)


Error: WA

Fixed submission:

S = input()
K = int(input())
flag = True

for i in range(K):
    if S[i] != 1:
        print(S[i])
        flag = False

if flag:
    print(1)
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

import re

S = input()
K = int(input())

n1 = re.search("[2-9]", S)
if not n1:
    print("1")
    exit()

n1i = n1.start()
print(S[min(n1i, K - 1)])


Error: 0

Fixed submission:

import re

S = input()
K = int(input()[:4])

n1i = re.search("[2-9]", S).start()

print(S[min(n1i, K - 1)])
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

s = list(map(int, list(input())))
k = int(input())
ans = 1

if len(s) <= k:
    for i in s:
        if i != 1:
            ans = i
            break
else:
    for i in range(0, k):
        if s[i] != 1:
            ans = s[i]
            break

print(ans)


Error: 0

Fixed submission:

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

if s[0] == 1:
    print(s[1])
else:
    print(s[0])
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

s = input()
k = int(input())

c = 0
a = 1
for si in s:
    if si == "1":
        c += 1
    else:
        a = si
        break

print("1" if k - c <= 0 else a)


Error: 0

Fixed submission:

s = input()
k = int(input())

c = 0
for si in s:
    if si == "1":
        c += 0
    else:
        a = si
        break

print("1" if k - c <= 0 else a)
Problem p03282 (Python) — buggy submission, verdict: Runtime Error

S = input()
K = int(input())
counter = 0
num = 1
log = 0
for i in S:
    if int(i) != 1:
        log = counter
        num = int(i)
        break
    counter += 1

if K <= log:
    print(1)
else:
    print(num)


Error: 0

Fixed submission:

S = input()
K = int(input())
counter = 0
num = 0
log = 0
for i in range(101):
    if int(S[i]) != 1:
        log = counter
        num = int(S[i])
        break
    counter += 1

if K <= log:
    print(1)
else:
    print(num)
Problem p03283 (Python) — buggy submission, verdict: Time Limit Exceeded

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

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

for i in range(N + 1):
    for j in range(N):
        t[i][j + 1] += t[i][j]

result = []
for _ in range(Q):
    p, q = map(int, input().split())
    result.append(sum(t[i][q] - t[i][i - 1] for i in range(p, q + 1)))
print("\\n".join(str(v) for v in result))


Error: TLE

Fixed submission:

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

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

for i in range(N + 1):
    for j in range(N):
        t[i][j + 1] += t[i][j]

for _ in range(Q):
    p, q = map(int, input().split())
    print(sum(t[i][q] - t[i][i - 1] for i in range(p, q + 1)))
Problem p03283 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys

input = sys.stdin.readline

N, M, Q = map(int, input().split())
t = [[0] * (N + 1) for _ in range(N + 1)]
# es[L][R]:=区間[L,R]を走る列車の本数

for _ in range(M):
    l, r = map(int, input().split())
    t[l][r] += 1

for L in range(1, N + 1):
    for R in range(1, N + 1):
        t[L][R] += t[L - 1][R]
        t[L][R] += t[L][R - 1]
        t[L][R] -= t[L - 1][R - 1]
        # 累積和のテーブルを作る
        # 最終的には
        # t[L][R]には区間が[L,R]に含まれる本数を入れるが、
        # 現時点では区間が[L,R]に一致する本数しか入っていない
        # ここに区間が[L-1,R]に含まれる本数と
        # 区間が[L,R-1]に含まれる本数を足すと
        # 区間が[L,R]に含まれる範囲をカバーできるが、
        # 区間が[L-1][R-1]の範囲が重複して足されている

for _ in range(Q):
    p, q = map(int, input().split())
    print(t[q][q] - t[p - 1][q] - t[q][p - 1] + t[p - 1][p - 1])
    # 2次元累積和


Error: TLE

Fixed submission:

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

x = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    x[L][R] += 1

c = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
for i in range(1, N + 1):
    for j in range(1, N + 1):
        c[i][j] += c[i][j - 1] + x[i][j]

for _ in range(Q):
    P, Q = map(int, input().split())
    ans = 0
    for i in range(P, Q + 1):
        ans += c[i][Q] - c[i][P - 1]
    print(ans)
Problem p03283 (Python) — buggy submission, verdict: Time Limit Exceeded

a = input().split()
n = int(a[0])
m = int(a[1])
qq = int(a[2])

x = [[0] * n for _ in range(n)]

for _ in range(m):
    a = input().split()
    x[int(a[0]) - 1][int(a[1]) - 1] += 1

c = list()

for i in range(n):
    c.append(list())
    for j in range(n):
        a = x[i][j]

        if 0 < j:
            a += c[i][j - 1]

        c[i].append(a)

z = list()

for i in range(n):
    z.append(list())
    for j in range(n):
        a = c[i][j]

        if 0 < i:
            a += z[i - 1][j]

        z[i].append(a)

for _ in range(qq):
    r = 0
    a = input().split()
    p = int(a[0])
    q = int(a[1])

    if 0 < q:
        r += z[q - 1][q - 1]

    if 0 < q and 1 < p:
        r -= z[q - 1][p - 2] + z[p - 2][q - 1]

    if 1 < p:
        r += z[p - 2][p - 2]

    print(r)


Error: TLE

Fixed submission:

a = input().split()
n = int(a[0])
m = int(a[1])
qq = int(a[2])

x = [[0] * n for _ in range(n)]

for _ in range(m):
    a = input().split()
    x[int(a[0]) - 1][int(a[1]) - 1] += 1

c = list()

for i in range(n):
    c.append(list())
    for j in range(n):
        a = x[i][j]

        if 0 < j:
            a += c[i][j - 1]

        c[i].append(a)

for _ in range(qq):
    r = 0
    a = input().split()
    p = int(a[0])
    q = int(a[1])
    for j in range(p - 1, q):
        r += c[j][q - 1]
        if 1 < p:
            r -= c[j][p - 2]

    print(r)
Problem p03283 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys

input = sys.stdin.readline
N, M, Q = map(int, input().split())

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

for i in range(1, N + 1):
    for j in range(1, N + 1):
        sum_table[i][j] += (
            sum_table[i - 1][j] + sum_table[i][j - 1] - sum_table[i - 1][j - 1]
        )

for _ in range(Q):
    p, q = map(int, input().split())
    print(
        sum_table[q][q]
        - sum_table[q][p - 1]
        - sum_table[p - 1][q]
        + sum_table[p - 1][p - 1]
    )


Error: TLE

Fixed submission:

N, M, Q = map(int, input().split())
trains = [list(map(int, input().split())) for _ in range(M)]
questions = [list(map(int, input().split())) for _ in range(Q)]
for q in questions:
    print(len([t for t in trains if q[0] <= t[0] and q[1] >= t[1]]))
Problem p03283 (Python) — buggy submission, verdict: Time Limit Exceeded

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

x = [[0 for j in range(N + 1)] for i in range(N + 1)]

for _ in range(M):
    L, R = map(int, input().split())
    x[N - L][R] += 1

for i in range(1, N + 1):
    for j in range(1, N + 1):
        x[i][j] += x[i][j - 1]

for j in range(1, N + 1):
    for i in range(1, N + 1):
        x[i][j] += x[i - 1][j]

for _ in range(Q):
    p, q = map(int, input().split())
    print(x[N - p][q])


Error: TLE

Fixed submission:

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

x = [[0 for j in range(N + 1)] for i in range(N + 1)]
c = [[0 for j in range(N + 1)] for i in range(N + 1)]

for _ in range(M):
    L, R = map(int, input().split())
    x[L][R] += 1

for i in range(1, N + 1):
    for j in range(1, N + 1):
        x[i][j] += x[i][j - 1]

for _ in range(Q):
    p, q = map(int, input().split())
    print(sum(x[i][q] - x[i][p - 1] for i in range(p, q + 1)))