Buggy python submission (verdict: Time Limit Exceeded):
def main():
    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 question in questions:
        a, b = question
        # result = [train for train in trains if a <= train[0] and train[1] <= b]
        result = list(filter(lambda x: a <= x[0] and x[1] <= b, trains))
        print(len(result))

if __name__ == '__main__':
    main()


Fixed submission:
n, m, q = map(int, input().split())
cities = [[0 for _ in range(n+1)] for _ in range(n+2)]
trains = [list(map(int, input().split())) for _ in range(m)]
quests = [list(map(int, input().split())) for _ in range(q)]

for train in trains:
    x, y = train[0], train[1]
    cities[x][y] += 1

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

for quest in quests:
    p, q = quest[0], quest[1]
    print(cities[p][q])

Buggy python submission (verdict: Time Limit Exceeded):
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 question in questions:
    x, y = question
    result = [train for train in trains if x <= train[0] and train[1] <= y]
    print(len(result))


Fixed submission:
n, m, q = map(int, input().split())
cities = [[0 for _ in range(n+1)] for _ in range(n+2)]
trains = [list(map(int, input().split())) for _ in range(m)]
quests = [list(map(int, input().split())) for _ in range(q)]

for train in trains:
    x, y = train[0], train[1]
    cities[x][y] += 1

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

for quest in quests:
    p, q = quest[0], quest[1]
    print(cities[p][q])

Buggy python submission (verdict: Time Limit Exceeded):
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 question in questions:
    x, y = question
    cnt = 0
    for train in trains:
        l, r = train
        if x <= l and r <= y: cnt += 1
    print(cnt)


Fixed submission:
n, m, q = map(int, input().split())
cities = [[0 for _ in range(n+1)] for _ in range(n+2)]
trains = [list(map(int, input().split())) for _ in range(m)]
quests = [list(map(int, input().split())) for _ in range(q)]

for train in trains:
    x, y = train[0], train[1]
    cities[x][y] += 1

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

for quest in quests:
    p, q = quest[0], quest[1]
    print(cities[p][q])

Buggy python submission (verdict: Time Limit Exceeded):
n, m, q = map(int, input().split())
M = [list(map(int, input().split())) for _ in range(m)]
Q = [list(map(int, input().split())) for _ in range(q)]

for q in Q:
    x, y = q
    cnt = 0
    for m in M:
        l, r = m
        if x <= l and r <= y:
            cnt += 1
    print(cnt)


Fixed submission:
n, m, q = map(int, input().split())
cities = [[0 for _ in range(n+1)] for _ in range(n+2)]
trains = [list(map(int, input().split())) for _ in range(m)]
quests = [list(map(int, input().split())) for _ in range(q)]

for train in trains:
    x, y = train[0], train[1]
    cities[x][y] += 1

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

for quest in quests:
    p, q = quest[0], quest[1]
    print(cities[p][q])