CodeEff/ECCO huggingface dataset:
# Original solution
n, k = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(k)]
dp = [0]*(n+1)
dp[1] = 1
mod = 998244353

for i in range(2, n+1):
    for j in range(k):
        li = max(i-s[j][1], 1)
        ri = i-s[j][0]
        if ri < 0:
            continue
        dp[i] += sum(dp[li: ri+1])
        dp[i] %= mod
print((dp[n]))
    


# Optimized solution
n, k = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(k)]
dp = [0]*(n+1)
dp[1] = 1
mod = 998244353
dpsum = [0]*(n+1)
dpsum[1] = 1

for i in range(2, n+1):
    for j in range(k):
        li = max(i-s[j][1], 1)
        ri = i-s[j][0]
        if ri < 0:
            continue
        dp[i] += dpsum[ri]-dpsum[li-1]
        dp[i] %= mod
    dpsum[i] = dpsum[i-1]+dp[i]
print((dp[n]))
# Original solution
n, k = list(map(int, input().split()))
lr = [list(map(int,input().split())) for _ in range(k)]
s = []
mod = 998244353

for i in range(k):
    l,r = lr[i]
    for j in range(l, r+1):
        s.append(j)

li = [0]*(n+1)
li[0] = 1

for i in range(n):
    for j in s:
        if i+j > n:
            continue
        li[i+j] += li[i]
        li[i+j] %= mod

print((li[n-1]))

# Optimized solution
n, k = list(map(int, input().split()))
lr = [list(map(int, input().split())) for _ in range(k)]
s = []
mod = 998244353

dp = [0]*(n+1)
dpsum = [0]*(n+1)
dp[1] = 1
dpsum[1] = 1

for i in range(2,n+1):
    for j in lr:
        l, r = j
        li = i-r
        ri = i-l
        if ri < 0:
            continue
        li = max(1,li)
        dp[i] += dpsum[ri]-dpsum[li-1]
        dp[i] %= mod
    dpsum[i] = dpsum[i-1]+dp[i]

print((dp[n]))
# Original solution
N, K = list(map(int, input().split()))
mod = 998244353
S = []
for i in range(K):
    l, r = list(map(int, input().split()))
    for j in range(l, r+1):
        S.append(j)

S = sorted(S)
dp = [0] * (N+1)
dp[1] = 1
for i in range(1, N):
    for j in S:
        if i + j > N:
            break
        dp[i+j] = (dp[i+j] + dp[i]) % mod

print((dp[N]))

# Optimized solution
N, K = list(map(int, input().split()))
mod = 998244353
lr = [0] * K
for i in range(K):
    lr[i] = list(map(int, input().split()))
    lr[i][1] += 1

dp = [0] * (N+1)
dp[1] = 1
s = 0
for i in range(1, N):
    s += dp[i]
    for j in range(K):
        if (i + lr[j][0]) <= N:
            dp[i + lr[j][0]] = (dp[i + lr[j][0]] + s) % mod
        if (i + lr[j][1]) <= N:
            dp[i + lr[j][1]] = (dp[i + lr[j][1]] - s) % mod
        

print((dp[N]))
# Original solution
p = 998244353
n, k = list(map(int, input().split()))
LRs = []
for j in range(k):
    lj, rj = list(map(int, input().split()))
    LRs.append((lj, rj))
A = [0] * (n + 1)
i0 = min(lj for lj, rj in LRs)
A[0] = 1
A[i0] = 1
for i in range(i0 + 1, n):
    A[i] = A[i - 1]
    for j in range(k):
        lj, rj = LRs[j]
        if i - lj >= 0:
            A[i] += A[i - lj]
        if i - 1 - rj >= 0:
            A[i] -= A[i - 1 - rj]
        A[i] %= p
print((A[n - 1]))


# Optimized solution
p = 998244353
n, k = list(map(int, input().split()))
LRs = [tuple(map(int, input().split())) for _ in range(k)]
A = [0] * (2 * n + 1)
for lj, rj in LRs:
    A[lj] += 1
    A[rj + 1] -= 1
s = 0
for i in range(1, n):
    s = (s + A[i]) % p
    for lj, rj in LRs:
        A[i + lj] += s
        A[i + rj + 1] -= s
print(s)
# Original solution

n,m,q=list(map(int,input().split()))
counts=[[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l,r=list(map(int,input().split()))
    counts[l-1][r-1]+=1
cumsum=[[0 for _ in range(n+1)] for _ in range(n)]
for i in range(n):
    for j in range(n):
        cumsum[i][j+1]=cumsum[i][j]+counts[i][j]
    
for _ in range(q):
    l,r=list(map(int,input().split()))
    print((sum(cumsum[i][r]-cumsum[i][l-1] for i in range(l-1,r))))

# Optimized solution
n,m,q=list(map(int,input().split()))
counts=[[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l,r=list(map(int,input().split()))
    counts[l-1][r-1]+=1
cumsum=[[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(n):
    for j in range(n):
        cumsum[i+1][j+1]=cumsum[i+1][j]+counts[i][j]
for j in range(n+1):
    for i in range(n):
        cumsum[i+1][j]+=cumsum[i][j]
        
for _ in range(q):
    l,r=list(map(int,input().split()))
    print((cumsum[r][r]-cumsum[r][l-1]-cumsum[l-1][r]+cumsum[l-1][l-1]))
# Original solution
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, Q: int, L: "List[int]", R: "List[int]", p: "List[int]", q: "List[int]"):
    matrix = [[0]*(N+1) for _ in range(N+1)]

    for i in range(M):
        matrix[L[i]][R[i]] += 1

    for j in range(Q):
        answer = 0
        for k in range(p[j],q[j]+1): 
            for l in range(p[j],q[j]+1):
                answer += matrix[k][l]
        print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    p = [int()] * (Q)  # type: "List[int]"
    q = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        p[i] = int(next(tokens))
        q[i] = int(next(tokens))
    solve(N, M, Q, L, R, p, q)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, Q: int, L: "List[int]", R: "List[int]", p: "List[int]", q: "List[int]"):
    matrix = [[0]*(N+1) for _ in range(N+1)]

    for i in range(M):
        matrix[L[i]][R[i]] += 1

    ruisekiwa = [[0]*(N+1) for _ in range(N+1)]
    for i in range(N):
        for j in range(N):
            ruisekiwa[i+1][j+1] = ruisekiwa[i][j+1] + ruisekiwa[i+1][j] - ruisekiwa[i][j] + matrix[i+1][j+1]
    for j in range(Q):
        qq = q[j]
        pp = p[j]
        answer = ruisekiwa[qq][qq] - ruisekiwa[qq][pp-1] - ruisekiwa[pp-1][qq] + ruisekiwa[pp-1][pp-1]

        print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    p = [int()] * (Q)  # type: "List[int]"
    q = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        p[i] = int(next(tokens))
        q[i] = int(next(tokens))
    solve(N, M, Q, L, R, p, q)

if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, Q: int, L: "List[int]", R: "List[int]", p: "List[int]", q: "List[int]"):
    matrix = [[0]*(N+1) for _ in range(N+1)]

    for i in range(M):
        matrix[L[i]][R[i]] += 1

    ruisekiwa = [[0]*(N+1) for _ in range(N+1)]
    for i in range(N):
        for j in range(N):
            ruisekiwa[i+1][j+1] = ruisekiwa[i][j+1] + ruisekiwa[i+1][j] - ruisekiwa[i][j] + matrix[i+1][j+1]
    for j in range(Q):
        qq = q[j]
        pp = p[j]
        answer = ruisekiwa[qq][qq] - ruisekiwa[qq][pp-1] - ruisekiwa[pp-1][qq] + ruisekiwa[pp-1][pp-1]

        print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    p = [int()] * (Q)  # type: "List[int]"
    q = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        p[i] = int(next(tokens))
        q[i] = int(next(tokens))
    solve(N, M, Q, L, R, p, q)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, Q: int, L: "List[int]", R: "List[int]", p: "List[int]", q: "List[int]"):
    matrix = [[0]*(N+1) for _ in range(N+1)]

    for i in range(M):
        matrix[L[i]][R[i]] += 1
    
    for i in range(1,N+1):
        for j in range(1,N+1):
            matrix[i][j] += matrix[i-1][j]+matrix[i][j-1]-matrix[i-1][j-1]
    
    for i in range(Q):
        pp,qq = p[i],q[i]
        print((matrix[qq][qq]-matrix[pp-1][qq]-matrix[qq][pp-1]+matrix[pp-1][pp-1]))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    p = [int()] * (Q)  # type: "List[int]"
    q = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        p[i] = int(next(tokens))
        q[i] = int(next(tokens))
    solve(N, M, Q, L, R, p, q)

if __name__ == '__main__':
    main()
# Original solution
import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return list(map(int,input().split()))
def lmp(): return list(map(int,input().split()))

n,m,Q=mp()
grid=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
    l,r=mp()
    for j in range(1,l+1):
        for k in range(r,n+1):
            grid[j][k]+=1
for i in range(Q):
    p,q=mp()
    print((grid[p][q]))



# Optimized solution
import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return list(map(int,input().split()))
def lmp(): return list(map(int,input().split()))

n,m,Q=mp()
grid=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
    l,r=mp()
    for k in range(1,l+1):
        grid[k][r]+=1

for i in range(n):
    for k in range(n):
        grid[i][k+1]+=grid[i][k]



for i in range(Q):
    p,q=mp()
    print((grid[p][q]))
# Original solution

def main():
    N,M,Q = list(map(int, input().split()))

    
    X = [[0 for _ in range(N)] for _ in range(N)]
    """
    for i in range(M):
        l,r = map(int, input().split())
        X[l-1][r-1] += 1
    """

    LR = [list(map(int, input().split())) for _ in range(M)]
    query = [tuple(map(int, input().split())) for _ in range(Q)]

    for l,r in LR:
        X[l-1][r-1] += 1

    """
    C[i][j]：iから出発してjまで（ｊを含む）のどこかに行くもの
    C[i][j] = X[i][i] + X[i][i+1] + ... + X[i][j-1] + X[i][j]
    """
    C =  [[0 for _ in range(N)] for _ in range(N)]
    for i in range(N):
        for j in range(N):
            C[i][j] = C[i][j-1] + X[i][j]


    """
    print("---------------")
    for a in C:
        print(a)
    """

    for p,q in query:
        cnt = 0
        for r in range(p-1,q):
            cnt += C[r][q-1]
        print(cnt)


if __name__ == "__main__":
    main()

# Optimized solution
N,M,Q = list(map(int, input().split()))
train = [[0 for _ in range(N)] for _ in range(N)]

for _ in range(M):
    l,r = list(map(int, input().split()))
    train[l-1][r-1] += 1

query = [tuple(map(int, input().split())) for _ in range(Q)]

"""
l~rの間を走ってるやつ
→ {l~l + l~l+1 + l~l+2 + ... + l~r} + {l+1~l+1 + l+1~l+2 + ... + l+1~r} + ... + {r~r}
の発想
"""
accum = [[0 for _ in range(N)] for _ in range(N)]

for l in range(N):
    for r in range(l,N):
        if l == r:
            accum[l][r] = train[l][r]
        else:
            # l始まりでrまでのどこかに行くやつ = l始まりでr-までのどこかに行くやつ + l始まりでrまで行くやつ
            accum[l][r] = accum[l][r-1] + train[l][r]


for p,q in query:
    cnt = 0
    # l~rの間に完全に収まるもの = l始まりでrまでのどこかで止まるもの + l+1始まりでrまでのどこかで止まるもの + ... + r-1始まりでrまでのどこかで止まるもの + r始まりでrまでのどこかで止まるもの
    for i in range(p-1,q):
        cnt += accum[i][q-1]

    print(cnt)
# Original solution
n,m,q=list(map(int,input().split()))
h=[[0]*(n) for _ in range(n)]
for i in range(m):
    l,r=list(map(int,input().split()))
    l-=1
    r-=1
    h[n-1-l][r]+=1
ans=0
for i in range(n):
    for j in range(n-1):
        h[i][j+1] += h[i][j]
 
for j in range(n):
    for i in range(n-1):
        h[i+1][j] += h[i][j]
 
for i in range(q):
    x,y=list(map(int,input().split()))
    x-=1
    y-=1
    print((h[n-1-x][y]))

# Optimized solution
n,m,q=list(map(int,input().split()))
g=[[0]*n for _ in [0]*n]
for i in range(m):
    l,r=list(map(int,input().split()))
    l-=1
    r-=1
    g[n-l-1][r]+=1
for i in range(n):
    for j in range(n-1):
        g[i][j+1]+=g[i][j]

for i in range(n):
    for j in range(n-1):
        g[j+1][i]+=g[j][i]

for i in range(q):
    p,w=list(map(int,input().split()))
    p-=1
    w-=1
    print((g[n-1-p][w]))
# Original solution
N, M, Q = list(map(int, input().split()))

train = []
for i in range(0, N):
	train.append([])
for i in range(0, M):
	L, R = list(map(int, input().split()))
	train[L-1].append(R)
for i in range(0, N):
	train[i-1].sort()

counter = []
for i in range(0, N):
	lst = []
	for j in range(0, N):
		lst.append(0)
	for j in range(0, len(train[i])):
		lst[train[i][j]-1] = lst[train[i][j]-1] + 1
	for j in range(1, len(lst)):
		lst[j] = lst[j-1] + lst[j]
	counter.append(lst)

for i in range(0, Q):
	p, q = list(map(int, input().split()))
	cnt = 0
	for j in range(p-1, q):
		cnt = cnt + counter[j][q-1]
	print(cnt)


# Optimized solution
N, M, Q = list(map(int, input().split()))

train = []
for i in range(0, N):
	train.append([])
for i in range(0, M):
	L, R = list(map(int, input().split()))
	train[L-1].append(R)
for i in range(0, N):
	train[i-1].sort()

counter = []
for i in range(0, N):
	lst = []
	for j in range(0, N):
		lst.append(0)
	for j in range(0, len(train[i])):
		lst[train[i][j]-1] = lst[train[i][j]-1] + 1
	for j in range(1, len(lst)):
		lst[j] = lst[j-1] + lst[j]
	counter.append(lst)
for i in range(1, N):
	for j in range(0, N):
		counter[N-1-i][j] = counter[N-1-i][j] + counter[N-i][j]

for i in range(0, Q):
	p, q = list(map(int, input().split()))
	print(counter[p-1][q-1])
# Original solution
N, M, Q = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
Y = [list(map(int, input().split())) for _ in range(Q)]

p = [[0] * (N + 1) for _ in range(N + 1)]

for l, r in X:
    p[l][r] += 1
    
for i in range(1, N + 1):
    for j in range(1, N + 1):
        p[i][j] += p[i][j - 1]
        
for i in range(1, N + 1):
    for j in range(1, N + 1):
        p[i][j] += p[i - 1][j]
        
for l, r in Y:
    ans = p[r][r] + p[l - 1][l - 1] - p[l - 1][r] - p[r][l - 1]
    print(ans)


# Optimized solution
N, M, Q = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
Y = [list(map(int, input().split())) for _ in range(Q)]

grid = [[0] * (N + 1) for _ in range(N + 1)]
for l, r in X:
    grid[l][r] += 1

for i in range(N):
    for j in range(N):
        grid[i + 1][j + 1] += grid[i][j + 1]

for i in range(N):
    for j in range(N):
        grid[i + 1][j + 1] += grid[i + 1][j]

for p, q in Y:
    print((grid[q][q] + grid[p - 1][p - 1] - grid[p - 1][q] - grid[q][p - 1]))
# Original solution
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)


def read_values():
    return list(map(int, input().split()))


def read_index():
    return [x - 1 for x in list(map(int, input().split()))]


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def functional(N, mod):
    F = [1] * (N + 1)
    for i in range(N):
        F[i + 1] = (i + 1) * F[i] % mod
    return F


def main():
    N, M, Q = read_values()
    T = [list(read_index()) for _ in range(M)]
    L0 = [0] * N
    R0 = [0] * N
    for i, (l, r) in enumerate(T):
        L0[r] += 1 << i
        R0[l] += 1 << i

    for i in range(1, N):
        L0[i] += L0[i - 1]
        R0[-i - 1] += R0[-i]

    res = [0] * Q
    for i in range(Q):
        p, q = read_index()
        t = R0[p] & L0[q]
        res[i] = str(bin(t).count("1"))

    print(("\n".join(res)))


if __name__ == "__main__":
    main()

# Optimized solution
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)


def read_values():
    return list(map(int, input().split()))


def read_index():
    return [x - 1 for x in list(map(int, input().split()))]


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def functional(N, mod):
    F = [1] * (N + 1)
    for i in range(N):
        F[i + 1] = (i + 1) * F[i] % mod
    return F


def main():
    N, M, Q = read_values()
    S = [[0 for _ in range(N + 1)] for __ in range(N + 1)]
    
    for _ in range(M):
        l, r = read_values()
        S[l][r] += 1

    for l in range(N):
        for r in range(N):
            S[l + 1][r + 1] += S[l + 1][r] + S[l][r + 1] - S[l][r] 

    res = [0] * Q
    for i in range(Q):
        p, q = read_values()
        res[i] = str(S[q][q] - S[p - 1][q] - S[q][p - 1] + S[p - 1][p - 1])
    print(("\n".join(res)))


if __name__ == "__main__":
    main()
# Original solution
from copy import deepcopy

N, M, Q = [int(elem) for elem in input().split(' ')]
lines = [[int(elem) for elem in input().split(' ')] for _ in range(M)]
queries = [[int(elem) for elem in input().split(' ')] for _ in range(Q)]


def cuml_1d(N, lines, queries):
    coords = [[0] * N for _ in range(N)]
    for l, r in lines:
        coords[l - 1][r - 1] += 1

    cuml_coords = deepcopy(coords)
    for l in range(N):
        for r in range(1, N):
            cuml_coords[l][r] = cuml_coords[l][r - 1] + coords[l][r]

    for query in queries:
        p, q = query[0] - 1, query[1] - 1
        num_lines = 0
        for l in range(p, max(q + 1, N)):
            if p == 0:
                num_lines += cuml_coords[l][q]
            else:
                num_lines += cuml_coords[l][q] - cuml_coords[l][p - 1]
        print(num_lines)

#cuml_1d(N, lines, queries)


def cuml_2d(N, lines, queries):
    coords = [[0] * N for _ in range(N)]
    for l, r in lines:
        coords[l - 1][r - 1] += 1
    cuml_l = deepcopy(coords)
    for r in range(N):
        for l in range(1, N):
            cuml_l[l][r] = cuml_l[l - 1][r] + coords[l][r]
    cuml_2d = deepcopy(cuml_l)
    for l in range(N):
        for r in range(1, N):
            cuml_2d[l][r] = cuml_2d[l][r - 1] + cuml_l[l][r]
    
    for query in queries:
        p, q = query[0] - 1, query[1] - 1
        if p != 0:
            num_lines = cuml_2d[q][q] - cuml_2d[q][p-1] - cuml_2d[p-1][q] + cuml_2d[p-1][p-1]
        else:
            num_lines = cuml_2d[q][q]
        print(num_lines)

cuml_2d(N, lines, queries)


# Optimized solution
import sys 
fin = sys.stdin.readline

N, M, Q = [int(elem) for elem in fin().split()]
trains = [[int(elem) - 1 for elem in fin().split()] for _ in range(M)]
queries = [[int(elem) - 1 for elem in fin().split()] for _ in range(Q)]

map_2D = [[0] * N for _ in range(N)]
for l, r in trains:
    map_2D[l][r] += 1

cuml_1D = [[0] * N for _ in range(N)]
# vertical
for j in range(N):
    cuml_sum = 0
    for i in reversed(list(range(j + 1))):
        cuml_sum += map_2D[i][j]
        cuml_1D[i][j] = cuml_sum

cuml_2D = [[0] * N for _ in range(N)]
# horizontal
for i in range(N):
    cuml_sum = 0
    for j in range(N):
        cuml_sum += cuml_1D[i][j]
        cuml_2D[i][j] = cuml_sum

for p, q in queries:
    print((cuml_2D[p][q]))
# Original solution
# Reference: https://ikatakos.com/pot/programming_algorithm/data_structure/binary_indexed_tree
# Fenwick Tree
class BinaryIndexedTree:
    # a = [0] * n
    # O(n)
    def __init__(self, n):
        self.size = n
        self.data = [0] * (n+1)

    # return sum(a[0:i])
    # O(log(n))
    def cumulative_sum(self, i):
        ans = 0
        while i > 0:
            ans += self.data[i]
            i -= i & -i
        return ans

    # a[i] += x
    # O(log(n))
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.data[i] += x
            i += i & -i

from sys import stdin
input = stdin.buffer.readline

def main():
    n, m, q = list(map(int, input().split()))
    lr = [tuple(map(int, input().split())) for _ in range(m)]
    pq = [(0, 0, 0)] * q
    for ind in range(q):
        i, j = list(map(int, input().split()))
        pq[ind] = (i, j, ind)

    lr.sort(key=lambda x: x[0])
    l = [i for i, j in lr]
    r = [j for i, j in lr]
    pq.sort(key=lambda x: x[0])

    BIT = BinaryIndexedTree(n+1)
    for i in r:
        BIT.add(i, 1)

    # search r[lr_ind:]
    lr_ind = 0
    ans = [0] * q
    for left, right, pq_ind in pq:
        while lr_ind < m and l[lr_ind] < left:
            BIT.add(r[lr_ind], -1)
            lr_ind += 1

        ans[pq_ind] = BIT.cumulative_sum(right+1)

    for i in ans:
        print(i)

main()

# Optimized solution
from sys import stdin
input = stdin.buffer.readline

def main():
    n, m, q = list(map(int, input().split()))

    # Two-dimensional Cumulative Sum
    cs = [[0] * (n+1) for _ in range(n+1)]

    for _ in range(m):
        l, r = list(map(int, input().split()))
        cs[l][r] += 1

    for l in range(1, n+1):
        for r in range(1, n+1):
            cs[l][r] += cs[l][r-1]
        for r in range(1, n+1):
            cs[l][r] += cs[l-1][r]

    ans = [-1] * q
    for lap in range(q):
        l, r = list(map(int, input().split()))
        ans[lap] = cs[n][r] - cs[l-1][r]

    for i in ans:
        print(i)

main()
# Original solution
N,M,Q = list(map(int,input().split()))
Train = [list(map(int,input().split())) for i in range(M)]
Query = [list(map(int,input().split())) for i in range(Q)]

City = [[0]*N for i in range(N)]
Accum = [[0]*(N+1) for i in range(N+1)]

for train in Train:
  City[train[0]-1][train[1]-1] += 1

for i in range(N):
  for j in range(N):
    Accum[i+1][j+1] = Accum[i+1][j] + City[i][j]
for j in range(N):
  for i in range(N):
    Accum[i+1][j+1] += Accum[i][j+1]

for query in Query:
  print((
    Accum[query[1]][query[1]]
  - Accum[query[1]][query[0]-1]
  - Accum[query[0]-1][query[1]]
  + Accum[query[0]-1][query[0]-1]
    ))

# Optimized solution
import sys
input = sys.stdin.readline

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

D = [[0 for j in range(N)] for i in range(N)]

for _ in range(M):
    l, r = list(map(int, input().split()))
    D[l - 1][r - 1] += 1

for i in range(N):
    for j in range(1, N):
        D[i][j] += D[i][j - 1]

for j in range(N):
    for i in range(N - 1)[::-1]:
        D[i][j] += D[i + 1][j]

for _ in range(Q):
    p, q = list(map(int, input().split()))
    print((D[p - 1][q - 1]))
# Original solution
# ABC106D - AtCoder Express 2
from itertools import accumulate as acc


def main():
    # 2D cumulative sum
    N, M, Q, *X = list(map(int, open(0).read().split()))
    LR, PQ = X[: 2 * M], X[2 * M :]
    rails = [[0] * (N + 1) for _ in range(N + 1)]
    for l, r in zip(*[iter(LR)] * 2):
        rails[l][r] += 1
    rails = tuple(tuple(acc(a)) for a in rails)
    rails = tuple(tuple(acc(a[::-1]))[::-1] for a in zip(*rails))
    ans = []
    for p, q in zip(*[iter(PQ)] * 2):
        ans.append(rails[q][p])
    print(("\n".join(map(str, ans))))


if __name__ == "__main__":
    main()

# Optimized solution
# ABC106D - AtCoder Express 2
from itertools import accumulate as acc


def main():
    # 2D cumulative sum
    N, M, Q, *X = list(map(int, open(0).read().split()))
    LR, PQ = X[: 2 * M], X[2 * M :]
    rails = [[0] * (N + 1) for _ in range(N + 1)]
    for l, r in zip(*[iter(LR)] * 2):
        rails[l][r] += 1
    rails = [list(acc(a)) for a in rails]
    rails = [list(acc(a[::-1]))[::-1] for a in zip(*rails)]
    ans = []
    for p, q in zip(*[iter(PQ)] * 2):
        ans.append(rails[q][p])
    print(("\n".join(map(str, ans))))


if __name__ == "__main__":
    main()