Buggy python submission (verdict: Time Limit Exceeded):
def run(n, m, qq, l, r, p, q):
    cnt = []
    # lでソート済みと仮定
    # lr = []
    # for i in range(m):
    #     lr.append([l[i], r[i]])
    # print(lr)
    # sort_l = sorted(lr, key=lambda x: -x[1][0])
    # print(sort_l)
    dic = {}
    for i in range(qq):
        tmp_cnt = 0
        if (p[i], q[i]) in dic:
            cnt.append(dic[(p[i], q[i])])
        else:
            for j in range(m):
                if p[i] <= l[j] and r[j] <= q[i]:
                    tmp_cnt += 1
            cnt.append(tmp_cnt)
            dic[(p[i], q[i])] = tmp_cnt
    return cnt


def search_li(l, p):
    left = 0
    right = len(l) - 1

    while left <= right:
        mid = (left + right) // 2
        if l[mid] >= p:
            left = mid
            result = mid
        else:
            right = mid - 1
        return result


def read_line():
    n, m, qq = map(int, input().split())
    l = []
    r = []
    for i in range(m):
        tl, tr = map(int, input().split())
        l.append(tl)
        r.append(tr)
    p = []
    q = []
    for i in range(qq):
        tp, tq = map(int, input().split())
        p.append(tp)
        q.append(tq)
    return (n, m, qq, l, r, p, q)


def main():
    n, m, qq, l, r, p, q = read_line()
    ret = run(n, m, qq, l, r, p, q)
    for i in range(len(ret)):
        print(ret[i])


if __name__ == '__main__':
    main()


Fixed submission:
def run(n, m, qq, l, r, p, q):
    cnt = {}
    sum = {}
    ret = []
    for i in range(n+1):
        for j in range(n+1):
            cnt[i, j] = 0
            sum[i, j] = 0
    for i in range(m):
        cnt[(l[i], r[i])] += 1
    for i in range(1, n+1):
        for j in range(1, n+1):
            sum[i, j] = cnt[i, j] + sum[i-1, j] + sum[i, j-1] - sum[i-1, j-1]
    for i in range(qq):
        ret.append(sum[q[i], q[i]] - sum[p[i]-1, q[i]] - sum[q[i], p[i]-1] + sum[p[i]-1, p[i]-1])
    return ret


def read_line():
    n, m, qq = map(int, input().split())
    l = []
    r = []
    for i in range(m):
        tl, tr = map(int, input().split())
        l.append(tl)
        r.append(tr)
    p = []
    q = []
    for i in range(qq):
        tp, tq = map(int, input().split())
        p.append(tp)
        q.append(tq)
    return (n, m, qq, l, r, p, q)


def main():
    n, m, qq, l, r, p, q = read_line()
    ret = run(n, m, qq, l, r, p, q)
    for i in range(len(ret)):
        print(ret[i])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def run(n, m, qq, l, r, p, q):
    cnt = []
    for i in range(qq):
        tmp_cnt = 0
        for j in range(m):
            if p[i] <= l[j] and r[j] <= q[i]:
                tmp_cnt += 1
        cnt.append(tmp_cnt)
    return cnt


def read_line():
    n, m, qq = map(int, input().split())
    l = []
    r = []
    for i in range(m):
        tl, tr = map(int, input().split())
        l.append(tl)
        r.append(tr)
    p = []
    q = []
    for i in range(qq):
        tp, tq = map(int, input().split())
        p.append(tp)
        q.append(tq)
    return (n, m, qq, l, r, p, q)


def main():
    n, m, qq, l, r, p, q = read_line()
    ret = run(n, m, qq, l, r, p, q)
    for i in range(len(ret)):
        print(ret[i])


if __name__ == '__main__':
    main()


Fixed submission:
def run(n, m, qq, l, r, p, q):
    cnt = {}
    sum = {}
    ret = []
    for i in range(n+1):
        for j in range(n+1):
            cnt[i, j] = 0
            sum[i, j] = 0
    for i in range(m):
        cnt[(l[i], r[i])] += 1
    for i in range(1, n+1):
        for j in range(1, n+1):
            sum[i, j] = cnt[i, j] + sum[i-1, j] + sum[i, j-1] - sum[i-1, j-1]
    for i in range(qq):
        ret.append(sum[q[i], q[i]] - sum[p[i]-1, q[i]] - sum[q[i], p[i]-1] + sum[p[i]-1, p[i]-1])
    return ret


def read_line():
    n, m, qq = map(int, input().split())
    l = []
    r = []
    for i in range(m):
        tl, tr = map(int, input().split())
        l.append(tl)
        r.append(tr)
    p = []
    q = []
    for i in range(qq):
        tp, tq = map(int, input().split())
        p.append(tp)
        q.append(tq)
    return (n, m, qq, l, r, p, q)


def main():
    n, m, qq, l, r, p, q = read_line()
    ret = run(n, m, qq, l, r, p, q)
    for i in range(len(ret)):
        print(ret[i])


if __name__ == '__main__':
    main()