Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from bisect import bisect_right
from operator import itemgetter

N,M,Q = II()
x = []
for _ in range(M):
    L,R = II()
    x.append((L-1, R-1))
query = []
for _ in range(Q):
    p0,q0 = II()
    query.append((p0-1,q0-1))

x.sort(key=itemgetter(1))

y = [[float('inf')]*M for _ in range(N)]
c = [0]*N
for i in range(M):
    for j in range(x[i][0]+1):
        y[j][c[j]] = x[i][1]
        c[j] += 1

ans = 0
for q in query:
    print(bisect_right(y[q[0]], q[1]))

Fixed submission:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,M,Q = II()
x = []
for i in range(M):
    L,R = II()
    x.append([L-1, R-1])

p = [0]*Q
q = [0]*Q
for i in range(Q):
    p0,q0 = II()
    p[i] = p0-1
    q[i] = q0-1

a = [[0]*N for _ in range(N)]
for i in range(M):
    a[x[i][0]][x[i][1]] += 1

c = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if j==0:
            temp = 0
        else:
            temp = c[i][j-1]
        c[i][j] = temp + a[i][j]

for i in range(Q):
    ans = 0
    for j in range(p[i],q[i]+1):
        ans += c[j][q[i]]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from bisect import bisect_right

N,M,Q = II()
x = []
for i in range(M):
    L,R = II()
    x.append([L-1, R-1])
p,q = Line(Q)


x.sort(key = lambda x:x[1])

y = [[float('inf')]*M for _ in range(N)]
c = [0]*N
for i in range(M):
    for j in range(x[i][0]+1):
        y[j][c[j]] = x[i][1]
        c[j] += 1

ans = 0
for i in range(Q):
    print(bisect_right(y[p[i]-1], q[i]-1))

Fixed submission:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,M,Q = II()
x = []
for i in range(M):
    L,R = II()
    x.append([L-1, R-1])

p = [0]*Q
q = [0]*Q
for i in range(Q):
    p0,q0 = II()
    p[i] = p0-1
    q[i] = q0-1

a = [[0]*N for _ in range(N)]
for i in range(M):
    a[x[i][0]][x[i][1]] += 1

c = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if j==0:
            temp = 0
        else:
            temp = c[i][j-1]
        c[i][j] = temp + a[i][j]

for i in range(Q):
    ans = 0
    for j in range(p[i],q[i]+1):
        ans += c[j][q[i]]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from bisect import bisect_right

N,M,Q = II()
x = []
for i in range(M):
    L,R = II()
    x.append([L-1, R-1])
p,q = Line(Q)


x.sort(key = lambda x:x[1])

y = [[] for _ in range(N)]
for i in range(M):
    for j in range(x[i][0]+1):
        y[j].append(x[i][1])

ans = 0
for i in range(Q):
    print(bisect_right(y[p[i]-1], q[i]-1))

Fixed submission:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,M,Q = II()
x = []
for i in range(M):
    L,R = II()
    x.append([L-1, R-1])

p = [0]*Q
q = [0]*Q
for i in range(Q):
    p0,q0 = II()
    p[i] = p0-1
    q[i] = q0-1

a = [[0]*N for _ in range(N)]
for i in range(M):
    a[x[i][0]][x[i][1]] += 1

c = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if j==0:
            temp = 0
        else:
            temp = c[i][j-1]
        c[i][j] = temp + a[i][j]

for i in range(Q):
    ans = 0
    for j in range(p[i],q[i]+1):
        ans += c[j][q[i]]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from bisect import bisect_right

N,M,Q = II()
x = []
for i in range(M):
    L,R = II()
    x.append([L-1, R-1])
p,q = Line(Q)


x.sort(key = lambda x:x[1])

y = [[] for _ in range(N)]
for i in range(M):
    for j in range(x[i][0]+1):
        y[j].append(x[i][1])

ans = 0
for i in range(Q):
    print(bisect_right(y[p[i]-1], q[i]-1))

Fixed submission:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,M,Q = II()
x = []
for i in range(M):
    L,R = II()
    x.append([L-1, R-1])

p = [0]*Q
q = [0]*Q
for i in range(Q):
    p0,q0 = II()
    p[i] = p0-1
    q[i] = q0-1

a = [[0]*N for _ in range(N)]
for i in range(M):
    a[x[i][0]][x[i][1]] += 1

c = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if j==0:
            temp = 0
        else:
            temp = c[i][j-1]
        c[i][j] = temp + a[i][j]

for i in range(Q):
    ans = 0
    for j in range(p[i],q[i]+1):
        ans += c[j][q[i]]
    print(ans)