Buggy python submission (verdict: Time Limit Exceeded):
n, m, q = map(int, input().split())
start_sets = [set() for _ in range(n+2)]
end_sets = [set() for _ in range(n+2)]
for i in range(m):
    l, r = map(int, input().split())
    start_sets[l].add(i)
    end_sets[r].add(i)

for i in range(1, n+2):
    start_sets[i] |= start_sets[i-1]
    end_sets[i] |= end_sets[i-1]

ans = []
for _ in range(q):
    p, q = map(int, input().split())
    start = start_sets[q]-start_sets[p-1]
    end = end_sets[q] - end_sets[p-1]
    res = start & end
    ans.append(len(res))
print(*ans, sep="\n")

Fixed submission:
N,M,Q = map(int,input().split())
l = [[0 for i in range(N)] for j in range(N)]
 
for _ in range(M):
    L,R = map(int,input().split())
    l[L-1][R-1] += 1
 
csum = [[0 for i in range(N+1)] for j in range(N+1)]
 
for i in range(1,N+1):
    for j in range(1,N+1):
        csum[i][j] = csum[i][j-1] + csum[i-1][j] - csum[i-1][j-1] + l[i-1][j-1]
 
for _ in range(Q):
    p,q = map(int,input().split())
    print(csum[q][q]-csum[q][p-1]-csum[p-1][q]+csum[p-1][p-1])

Buggy python submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
start_sets = [set() for _ in range(n+2)]
end_sets = [set() for _ in range(n+2)]
for i in range(m):
    l, r = map(int, input().split())
    start_sets[l].add(i)
    end_sets[r].add(i)

for i in range(1, n+2):
    start_sets[i] |= start_sets[i-1]
    end_sets[i] |= end_sets[i-1]

ans = []
for _ in range(q):
    p, q = map(int, input().split())
    start = start_sets[q]-start_sets[p-1]
    end = end_sets[q] - end_sets[p-1]
    res = start & end
    ans.append(len(res))
print(*ans, sep="\n")

Fixed submission:
N,M,Q = map(int,input().split())
l = [[0 for i in range(N)] for j in range(N)]
 
for _ in range(M):
    L,R = map(int,input().split())
    l[L-1][R-1] += 1
 
csum = [[0 for i in range(N+1)] for j in range(N+1)]
 
for i in range(1,N+1):
    for j in range(1,N+1):
        csum[i][j] = csum[i][j-1] + csum[i-1][j] - csum[i-1][j-1] + l[i-1][j-1]
 
for _ in range(Q):
    p,q = map(int,input().split())
    print(csum[q][q]-csum[q][p-1]-csum[p-1][q]+csum[p-1][p-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, m, Q = [int(i) for i in input().split()]
l_list = []
r_list = []
p_list = []
q_list = []
for _ in range(m):
    l, r = [int(i) for i in input().split()]
    l_list.append(l)
    r_list.append(r)

for _ in range(Q):
    p, q = [int(i) for i in input().split()]
    p_list.append(p)
    q_list.append(q)


start_map = [[] for i in range(n)]
end_map = [[] for i in range(n)]

for i in range(m):
    l = l_list[i]
    r = r_list[i]

    start_map[l - 1].append(i)
    end_map[r - 1].append(i)

for i in range(Q):
    count = 0
    p = p_list[i]
    q = q_list[i]
    start_list = []
    end_list = []
    for j in range(p, q+1):
        start_list.extend(start_map[j-1])
        end_list.extend(end_map[j-1])
    rail_set = set(start_list) & set(end_list)

    print(len(rail_set))





Fixed submission:
N,M,Q = map(int,input().split())
l = [[0 for i in range(N)] for j in range(N)]
 
for _ in range(M):
    L,R = map(int,input().split())
    l[L-1][R-1] += 1
 
csum = [[0 for i in range(N+1)] for j in range(N+1)]
 
for i in range(1,N+1):
    for j in range(1,N+1):
        csum[i][j] = csum[i][j-1] + csum[i-1][j] - csum[i-1][j-1] + l[i-1][j-1]
 
for _ in range(Q):
    p,q = map(int,input().split())
    print(csum[q][q]-csum[q][p-1]-csum[p-1][q]+csum[p-1][p-1])