Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
import bisect

n, m, Q = map(int, input().split())
train = [list(map(int, input().split())) + [i] for i in range(m)]
train_L = []
train_R = []
L_n = []
R_n = []
for i in sorted(train, key=itemgetter(0)):
    train_L.append(i[0])
    L_n.append(i[2])
for i in sorted(train, key=itemgetter(1)):
    train_R.append(i[1])
    R_n.append(i[2])
for i in range(Q):
    p, q = map(int, input().split())
    p_set = set(L_n[bisect.bisect_left(train_L, p):])
    q_set = set(R_n[:bisect.bisect_right(train_R, q)])
    print(len(p_set & q_set))

Fixed submission:
def getSumRange(L, R):
    ans = sum[R][R] - sum[R][L - 1] - sum[L - 1][R] + sum[L - 1][L - 1]
    return ans

n, m, Q = map(int, input().split())
L = [0] * m
R = [0] * m
for i in range(m):
    L[i], R[i] = map(int, input().split())
p = [0] * Q
q = [0] * Q
for i in range(Q):
    p[i], q[i] = map(int, input().split())

sum = [[0] * (n + 1) for i in range(n + 1)]
for i in range(m):
    sum[L[i]][R[i]] += 1
for i in range(n + 1):
    for j in range(n + 1):
        sum[i][j] += sum[i - 1][j]
        sum[i][j] += sum[i][j - 1]
        sum[i][j] -= sum[i - 1][j - 1]

for i in range(Q):
    ans = getSumRange(p[i], q[i])
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m, Q = map(int, input().split())
lr = [[0] * n for i in range(n)]
for _ in range(m):
  l, r = map(int, input().split())
  lr[l-1][r-1] += 1
pq = [list(map(int, input().split())) for _ in range(Q)]
for i in pq:
  p = i[0]
  q = i[1]
  ans = 0
  for j in range(p-1, q):
    for k in range(p-1, q):
      ans += lr[j][k]
  print(ans)

Fixed submission:
def getSumRange(L, R):
    ans = sum[R][R] - sum[R][L - 1] - sum[L - 1][R] + sum[L - 1][L - 1]
    return ans

n, m, Q = map(int, input().split())
L = [0] * m
R = [0] * m
for i in range(m):
    L[i], R[i] = map(int, input().split())
p = [0] * Q
q = [0] * Q
for i in range(Q):
    p[i], q[i] = map(int, input().split())

sum = [[0] * (n + 1) for i in range(n + 1)]
for i in range(m):
    sum[L[i]][R[i]] += 1
for i in range(n + 1):
    for j in range(n + 1):
        sum[i][j] += sum[i - 1][j]
        sum[i][j] += sum[i][j - 1]
        sum[i][j] -= sum[i - 1][j - 1]

for i in range(Q):
    ans = getSumRange(p[i], q[i])
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m, Q = map(int, input().split())
lr = sorted([list(map(int, input().split())) for _ in range(m)])
pq = [list(map(int, input().split())) for _ in range(Q)]
a = [k[0] for k in lr]
for i in pq:
  p = i[0]
  q = i[1]
  ans = 0
  b = a[:]
  b.append(p)
  b = sorted(b)
  for j in lr[b.index(p):]:
    l = j[0]
    r = j[1]
    if p <= l and r <= q:
      ans += 1
  print(ans)

Fixed submission:
def getSumRange(L, R):
    ans = sum[R][R] - sum[R][L - 1] - sum[L - 1][R] + sum[L - 1][L - 1]
    return ans

n, m, Q = map(int, input().split())
L = [0] * m
R = [0] * m
for i in range(m):
    L[i], R[i] = map(int, input().split())
p = [0] * Q
q = [0] * Q
for i in range(Q):
    p[i], q[i] = map(int, input().split())

sum = [[0] * (n + 1) for i in range(n + 1)]
for i in range(m):
    sum[L[i]][R[i]] += 1
for i in range(n + 1):
    for j in range(n + 1):
        sum[i][j] += sum[i - 1][j]
        sum[i][j] += sum[i][j - 1]
        sum[i][j] -= sum[i - 1][j - 1]

for i in range(Q):
    ans = getSumRange(p[i], q[i])
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m, Q = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(m)]
pq = [list(map(int, input().split())) for _ in range(Q)]
for i in pq:
  p = i[0]
  q = i[1]
  ans = 0
  for j in lr:
    l = j[0]
    r = j[1]
    if p <= l and r <= q:
      ans += 1
  print(ans)

Fixed submission:
def getSumRange(L, R):
    ans = sum[R][R] - sum[R][L - 1] - sum[L - 1][R] + sum[L - 1][L - 1]
    return ans

n, m, Q = map(int, input().split())
L = [0] * m
R = [0] * m
for i in range(m):
    L[i], R[i] = map(int, input().split())
p = [0] * Q
q = [0] * Q
for i in range(Q):
    p[i], q[i] = map(int, input().split())

sum = [[0] * (n + 1) for i in range(n + 1)]
for i in range(m):
    sum[L[i]][R[i]] += 1
for i in range(n + 1):
    for j in range(n + 1):
        sum[i][j] += sum[i - 1][j]
        sum[i][j] += sum[i][j - 1]
        sum[i][j] -= sum[i - 1][j - 1]

for i in range(Q):
    ans = getSumRange(p[i], q[i])
    print(ans)