Buggy python submission (verdict: Runtime Error):
    N, M, Q = map(int, input().split())
    rail = []
    for i in range(M):
        r = list(map(int, input().split()))
        rail.append(r)
     
    query = []
    for i in range(Q):
        q = list(map(int, input().split()))
        query.append(q)
     
    f = [[0 for i in range(N)] for j in range(N)]
    g = [[0 for i in range(N)] for j in range(N)]
     
    for i in range(M):
        f[rail[i][0]-1][rail[i][1]-1] += 1
     
    for i in range(N):
        j = 0
        while j + i < N:
            if i == 0:
                g[j][j+i] = f[j][j+i]
            else:
                g[j][j+i] = f[j][j+i] + g[j+1][j+i] + g[j][j+i-1] - g[j+1][j+i-1]
            j += 1
     
    for i in range(Q):
        print(g[query[i][0]-1][query[i][1]-1])

Fixed submission:

N, M, Q = map(int, input().split())
rail = []
for i in range(M):
    r = list(map(int, input().split()))
    rail.append(r)
 
query = []
for i in range(Q):
    q = list(map(int, input().split()))
    query.append(q)
 
f = [[0 for i in range(N)] for j in range(N)]
g = [[0 for i in range(N)] for j in range(N)]
 
for i in range(M):
    f[rail[i][0]-1][rail[i][1]-1] += 1
 
for i in range(N):
    j = 0
    while j + i < N:
        if i == 0:
            g[j][j+i] = f[j][j+i]
        else:
            g[j][j+i] = f[j][j+i] + g[j+1][j+i] + g[j][j+i-1] - g[j+1][j+i-1]
        j += 1
 
for i in range(Q):
    print(g[query[i][0]-1][query[i][1]-1])

Buggy python submission (verdict: Time Limit Exceeded):
#encoding utf-8

import numpy as np

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

L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

p = []
q = []

for i in range(Q):
    pa, qa = map(int, input().split())
    p.append(pa)
    q.append(qa)

MAP = np.zeros((N, N))
for i in range(M):
    MAP[L[i]-1][R[i]-1] += 1

C = np.zeros((N, N))
C[0][0] = MAP[0][0]
for i in range(N):
    count = 0
    for j in range(N):
        count += MAP[i][j]
        C[i][j] = count
# 
# print(MAP)
# print(C)

for i in range(Q):
    count = 0
    for j in range(q[i]-p[i]+1):
        if j == 0:
            count += C[p[i]-1+j][q[i]-1]
        else:
            count += C[p[i]-1+j][q[i]-1]-C[p[i]-1+j][p[i]-1]
    print(int(count))


Fixed submission:

N, M, Q = map(int, input().split())
rail = []
for i in range(M):
    r = list(map(int, input().split()))
    rail.append(r)
 
query = []
for i in range(Q):
    q = list(map(int, input().split()))
    query.append(q)
 
f = [[0 for i in range(N)] for j in range(N)]
g = [[0 for i in range(N)] for j in range(N)]
 
for i in range(M):
    f[rail[i][0]-1][rail[i][1]-1] += 1
 
for i in range(N):
    j = 0
    while j + i < N:
        if i == 0:
            g[j][j+i] = f[j][j+i]
        else:
            g[j][j+i] = f[j][j+i] + g[j+1][j+i] + g[j][j+i-1] - g[j+1][j+i-1]
        j += 1
 
for i in range(Q):
    print(g[query[i][0]-1][query[i][1]-1])

Buggy python submission (verdict: Time Limit Exceeded):
#encoding utf-8

import numpy as np

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

L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

p = []
q = []

for i in range(Q):
    pa, qa = map(int, input().split())
    p.append(pa)
    q.append(qa)

EXP_map = np.zeros((N,N))
for i in range(M):
    EXP_map[L[i]-1][R[i]-1] += 1

def Answer(i):
    return int(EXP_map[(p[i]-1):(q[i]),(p[i]-1):(q[i])].sum())

for i in range(Q):
    print(Answer(i))


Fixed submission:

N, M, Q = map(int, input().split())
rail = []
for i in range(M):
    r = list(map(int, input().split()))
    rail.append(r)
 
query = []
for i in range(Q):
    q = list(map(int, input().split()))
    query.append(q)
 
f = [[0 for i in range(N)] for j in range(N)]
g = [[0 for i in range(N)] for j in range(N)]
 
for i in range(M):
    f[rail[i][0]-1][rail[i][1]-1] += 1
 
for i in range(N):
    j = 0
    while j + i < N:
        if i == 0:
            g[j][j+i] = f[j][j+i]
        else:
            g[j][j+i] = f[j][j+i] + g[j+1][j+i] + g[j][j+i-1] - g[j+1][j+i-1]
        j += 1
 
for i in range(Q):
    print(g[query[i][0]-1][query[i][1]-1])

Buggy python submission (verdict: Time Limit Exceeded):
#encoding utf-8

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

L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

p = []
q = []

for i in range(Q):
    pa, qa = map(int, input().split())
    p.append(pa)
    q.append(qa)

# def Answer(i):
#     count = 0
#     for j in range(M):
#         if p[i] <= L[j] and R[j] <= q[i]:
#             count += 1
#     return count

for i in range(Q):
    count = 0
    for j in range(M):
        if p[i] <= L[j] and R[j] <= q[i]:
            count += 1
    print(count)


Fixed submission:

N, M, Q = map(int, input().split())
rail = []
for i in range(M):
    r = list(map(int, input().split()))
    rail.append(r)
 
query = []
for i in range(Q):
    q = list(map(int, input().split()))
    query.append(q)
 
f = [[0 for i in range(N)] for j in range(N)]
g = [[0 for i in range(N)] for j in range(N)]
 
for i in range(M):
    f[rail[i][0]-1][rail[i][1]-1] += 1
 
for i in range(N):
    j = 0
    while j + i < N:
        if i == 0:
            g[j][j+i] = f[j][j+i]
        else:
            g[j][j+i] = f[j][j+i] + g[j+1][j+i] + g[j][j+i-1] - g[j+1][j+i-1]
        j += 1
 
for i in range(Q):
    print(g[query[i][0]-1][query[i][1]-1])

Buggy python submission (verdict: Time Limit Exceeded):
#encoding utf-8

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

L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

p = []
q = []

for i in range(Q):
    pa, qa = map(int, input().split())
    p.append(pa)
    q.append(qa)

def Answer(i):
    count = 0
    for j in range(M):
        if p[i] <= L[j] and R[j] <= q[i]:
            count += 1
    return count

for i in range(Q):
    print(Answer(i))


Fixed submission:

N, M, Q = map(int, input().split())
rail = []
for i in range(M):
    r = list(map(int, input().split()))
    rail.append(r)
 
query = []
for i in range(Q):
    q = list(map(int, input().split()))
    query.append(q)
 
f = [[0 for i in range(N)] for j in range(N)]
g = [[0 for i in range(N)] for j in range(N)]
 
for i in range(M):
    f[rail[i][0]-1][rail[i][1]-1] += 1
 
for i in range(N):
    j = 0
    while j + i < N:
        if i == 0:
            g[j][j+i] = f[j][j+i]
        else:
            g[j][j+i] = f[j][j+i] + g[j+1][j+i] + g[j][j+i-1] - g[j+1][j+i-1]
        j += 1
 
for i in range(Q):
    print(g[query[i][0]-1][query[i][1]-1])