Problem:
 Score: 400 points    Problem Statement  In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1 , 2 , 3 , ..., N from west to east.
A company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i ).
Takahashi the king is interested in the following Q matters:   The number of the trains that runs strictly within the section from City p_i to City q_i , that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i .   Although he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him.      Constraints   N is an integer between 1 and 500 (inclusive).  M is an integer between 1 and 200 \ 000 (inclusive).  Q is an integer between 1 and 100 \ 000 (inclusive).  1 \leq L_i \leq R_i \leq N  (1 \leq i \leq M)  1 \leq p_i \leq q_i \leq N  (1 \leq i \leq Q)         Input  Input is given from Standard Input in the following format:  N  M  Q  L_1  R_1  L_2  R_2  :  L_M  R_M  p_1  q_1  p_2  q_2  :  p_Q  q_Q       Output  Print Q lines. The i -th line should contain the number of the trains that runs strictly within the section from City p_i to City q_i .        Sample Input 1 2 3 1
1 1
1 2
2 2
1 2      Sample Output 1 3  As all the trains runs within the section from City 1 to City 2 , the answer to the only query is 3 .       Sample Input 2 10 3 2
1 5
2 8
7 10
1 7
3 10      Sample Output 2 1
1  The first query is on the section from City 1 to 7 . There is only one train that runs strictly within that section: Train 1 .
The second query is on the section from City 3 to 10 . There is only one train that runs strictly within that section: Train 3 .       Sample Input 3 10 10 10
1 6
2 9
4 5
4 7
4 7
5 8
6 6
6 7
7 9
10 10
1 8
1 9
1 10
2 8
2 9
2 10
3 8
3 9
3 10
1 10      Sample Output 3 7
9
10
6
8
9
6
7
8
10

Solution (Python):
imos = [[0 for j in range(501)]for i in range(501)]
query = []
N,M,Q = map(int,input().split())
for i in range(M):
    L,R = map(int,input().split())
    imos[L][R] += 1
for i in range(Q):
    p,qq = map(int,input().split())
    query.append([p,qq])
for i in range(501):
    for j in range(1,501):
        imos[i][j] += imos[i][j-1]
for i in range(501):
    for j in range(1,501):
        imos[i][j] += imos[i-1][j]
for q in query:
    print(imos[N][q[1]]-imos[q[0]-1][q[1]])

Solution (Python):
n, m, q = map(int, input().split())

x = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    x[a-1][b-1] += 1

for j in range(1, n):
    for k in range(n-j):
        x[k][j+k] += x[k][j+k-1] + x[k+1][j+k] - x[k+1][j+k-1]

y = []
for i in range(q):
    a, b = map(int, input().split())
    y.append(x[a-1][b-1])
    
for i in range(q):
    print(y[i])

Solution (Python):
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M, Q] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    table = [[0 for i in range(N+1)] for i in range(N+1)]
    
    for i in range(M):
        input_raw = read_func().strip().split()
        [L, R] = [long(input_raw[0]), long(input_raw[1])]
        table[L][R] += 1;

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

    for i in range(Q):
        input_raw = read_func().strip().split()
        [p, q] = [long(input_raw[0]), long(input_raw[1])]
        print table[p][q]

if __name__ == '__main__':
    main()

Solution (Python):
N,M,X = map(int,input().split())

L,R = [],[]
for i in range(M):
    l,r = map(int,input().split())
    L.append(l-1)
    R.append(r-1)
P,Q = [],[]
for i in range(X):
    p,q = map(int,input().split())
    P.append(p-1)
    Q.append(q-1)

A = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(M):
    l,r = L[i],R[i]
    A[r][0] += 1
    A[r][l+1] -= 1
    A[N][0] -= 1 
    A[N][l+1] += 1

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

for i in range(X):
    p,q = P[i],Q[i]
    print(A[q][p])

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

train = [[0 for j1 in range(N)] for i1 in range(N)]
st = [[0 for j2 in range(N+1)] for i2 in range(N)]
s = [[0 for j3 in range(N+1)] for i3 in range(N)]


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

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

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


    for i in range(Q):
        p, q = map(int, input().split())
        print(s[p-1][q])


if __name__ == '__main__':
    main()

Solution (Python):
n, m, Q = map(int, input().split())
v = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    l, r = map(int, input().split())
    v[r - 1][l - 1] += 1
    


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



for i in range(n):
    for j in range(1, n):
        k = n - j - 1
        v[i][k] += v[i][k + 1]



for i in range(Q):
    p, q = map(int, input().split())
    print(v[q-1][p-1])

Solution (Python):



n,m,Q = list(map(int,input().split()))	




A=[[0 for i in range(n)] for j in range(n)]
for _ in range(m):
    a,b= list(map(int,input().split()))



    A[a-1][b-1]+=1


ruiseki=[[0 for i in range(n+1)] for j in range(n+1)]
for i in range(1,n+1):
    for j in range(n):

        ruiseki[i][j+1]=ruiseki[i][j] +ruiseki[i-1][j+1] - ruiseki[i-1][j] + A[i-1][j]



p=[]
q=[]
for _ in range(Q):
    a,b= list(map(int,input().split()))
    p.append(a-1)
    q.append(b-1)




for i in range(Q):
    print(ruiseki[q[i]+1][q[i]+1] - ruiseki[p[i]][q[i]+1] - ruiseki[q[i]+1][p[i]] + ruiseki[p[i]][p[i]])

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

D = [[0]*(N+1) for i in range(N+1)]
for i in range(M):
    L, R = map(int, input().split())
    L, R = sorted([L, R])
    D[L][R] += 1

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

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

for i in range(Q):
    p, q = map(int, input().split())
    p, q = sorted([p, q])
    print(D[p][q])

Solution (Python):
N, M, Q = map(int, input().split())
ct = [[0] * N for _ in range(N)]

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

m = [[0] * N for _ in range(N)]
for i in range(N):
  rowsum = 0
  for j in range(N):
    rowsum += ct[i][j]
    m[i][j] = rowsum
    if i > 0:
      m[i][j] += m[i-1][j]

for i in range(Q):
  p, q = map(int, input().split())
  p -= 1
  q -= 1
  ans = m[q][q]
  if p > 0:
    ans = ans - m[p-1][q] - m[q][p-1] + m[p-1][p-1]
  print(ans // 2)

Solution (Python):
import sys
sys.setrecursionlimit(int(1e9))

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

cnt = [[0] * 501 for i in range (501)]
for i in range(M):
    L, R = list(map(int,input().split()))
    cnt[L][R] = cnt[L][R] + 1

H, W = (501, 501)
for i in range(H):
    for j in range(1, W):
        cnt[i][j] = cnt[i][j] + cnt[i][j-1]

for j in range(W):
    for i in range(1, H):
        cnt[i][j] = cnt[i][j] + cnt[i-1][j]

def Sum(l, r):
    return cnt[r][r] - cnt[l][r] - cnt[r][l] + cnt[l][l]

for i in range(Q):
    l, r = list(map(int, input().split()))
    ans = Sum(l-1, r)
    print(ans)

Solution (Python):

N, M, Q = map(int, input().split())
dat_mat = [[0]*N for _ in range(N)]

for _ in range(M):
    L, R = map(int, input().split())
    dat_mat[L-1][R-1] += 1
    
dat_mat_left = [[0]*N for _ in range(N)]
dat_mat_res = [[0]*N for _ in range(N)]
for L in range(N):
    c = 0
    for R in range(L, N):
        c += dat_mat[L][R]
        dat_mat_left[L][R] = c
        
for R in range(N-1, -1, -1):
    c = 0
    for L in range(R, -1, -1):
        c += dat_mat_left[L][R]
        dat_mat_res[L][R] = c
        
res_list = [0]*Q
for q in range(Q):
    L, R = map(int, input().split())
    res_list[q] = dat_mat_res[L-1][R-1]

for a in res_list:
    print(a)

Solution (Python):

def inpl(): return map(int, input().split())
N, M, Q = inpl()

imos2d = [[0]*(N+2) for _ in range(N+2)]
S = [[0]*(N+2) for _ in range(N+2)]
S2 = [[0]*(N+2) for _ in range(N+2)]

for _ in range(M):
    L, R = inpl()
    imos2d[0][R] += 1
    imos2d[L+1][R] -= 1


for i in range(N+2):
    S[i][0] = imos2d[i][0]
    for j in range(N+1):
        S[i][j+1] = S[i][j] + imos2d[i][j+1]

S2[0] = [s for s in S[0]]
for i in range(N+1):
    for j in range(N+2):
        S2[i+1][j] = S2[i][j] + S[i+1][j]

for _ in range(Q):
    p, q = inpl()
    print(S2[p][q])

Solution (Python):

n,m,qq=map(int,input().split())
dp = [[0 for i in range(n+5)] for j in range(n+5)]
for i in range(m):
    l,r=map(int,input().split())
    l-=1
    r-=1
    dp[l][r]+=1
for i in range(n):
    for j in range(n-1):
        dp[i][j+1]+=dp[i][j]
for j in range(n):
    for i in range(n-1,0,-1):
        dp[i-1][j]+=dp[i][j]
for i in range(qq):
    p,q=map(int,input().split())
    p-=1
    q-=1
    if q==n-1:
        print(dp[p][q])
    else :
     print(dp[p][q]-dp[q+1][q])

Solution (Python):

def inpl(): return map(int, input().split())
N, M, Q = inpl()

imos2d = [[0]*(N+2) for _ in range(N+2)]
S = [[0]*(N+2) for _ in range(N+2)]
S2 = [[0]*(N+2) for _ in range(N+2)]

for _ in range(M):
    L, R = inpl()
    imos2d[0][R] += 1
    imos2d[L+1][R] -= 1


for i in range(N+2):
    S[i][0] = imos2d[i][0]
    for j in range(N+1):
        S[i][j+1] = S[i][j] + imos2d[i][j+1]

S2[0] = [s for s in S[0]]
for i in range(N+1):
    for j in range(N+2):
        S2[i+1][j] = S2[i][j] + S[i+1][j]

for _ in range(Q):
    p, q = inpl()
    print(S2[p][q])

Solution (Python):

n,m,qq=map(int,input().split())
dp = [[0 for i in range(n+5)] for j in range(n+5)]
for i in range(m):
    l,r=map(int,input().split())
    l-=1
    r-=1
    dp[l][r]+=1
for i in range(n):
    for j in range(n-1):
        dp[i][j+1]+=dp[i][j]
for j in range(n):
    for i in range(n-1,0,-1):
        dp[i-1][j]+=dp[i][j]
for i in range(qq):
    p,q=map(int,input().split())
    p-=1
    q-=1
    if q==n-1:
        print(dp[p][q])
    else :
     print(dp[p][q]-dp[q+1][q])

Solution (Python):
from itertools import accumulate

n, m, q = map(int, input().split())
rails = [[0] * n for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    rails[l - 1][r - 1] += 1
rails = [list(accumulate(s)) for s in rails]
rails = [list(reversed(list(accumulate(reversed(s))))) for s in zip(*rails)]
buf = []
for _ in range(q):
    p, q = map(int, input().split())
    buf.append(rails[q - 1][p - 1])
print('\n'.join(map(str, buf)))

Solution (Python):
n,m,q = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(m)]
p = [list(map(int, input().split()))+ [i] for i in range(q)]
l.extend(p)
l = sorted(l,key= lambda x:x[1])
ka = [0] * n
ans = []
for i in l:
  if len(i) == 2:
    ka[i[0]-1] += 1
  else:
    ans.append([i[2],sum(ka[i[0]-1:i[1]])])
ans = sorted(ans)
for i in range(len(ans)):
  print(ans[i][1])

Solution (Python):
N,M,Q=map(int,input().split())
L=[0 for i in range(M)]
R=[0 for i in range(M)]
p=[0 for i in range(Q)]
q=[0 for i in range(Q)]
ans=[0 for i in range(Q)]
B=[[0 for i in range(N+1)] for i in range(N+1)]
C=[[0 for i in range(N+1)] for i in range(N+1)]
D=[[0 for i in range(N+1)] for i in range(N+1)]
for i in range(M):
    L[i],R[i]=map(int,input().split())
    L[i]-=1
    R[i]-=1
for i in range(Q):
    p[i],q[i]=map(int,input().split())
    p[i]-=1
    q[i]-=1
for i in range(M):
    B[R[i]][0]+=1
    B[R[i]][L[i]+1]-=1
    B[N][0]-=1
    B[N][L[i]+1]+=1
for i in range(N+1):
    for j in range(N+1):
        if i==0:
            C[i][j]=B[i][j]
        else:
            C[i][j]=B[i][j]+C[i-1][j]
for i in range(N+1):
    for j in range(N+1):
        if j==0:
            D[i][j]=C[i][j]
        else:
            D[i][j]=C[i][j]+D[i][j-1]
for i in range(Q):
    ans[i]=D[q[i]][p[i]]

for line in ans:
    print(line)

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N, M, Q = reads()

mat = [[0] * N for _ in range(N)]
for _ in range(M):
  l, r = reads()
  l, r = l-1, r-1
  mat[l][r] += 1

acc = [[0] * (N+1) for _ in range(N+1)]
for i in range(N):
  vec = [0] + list(accumulate(mat[i]))
  acc[i+1] = [acc[i][j] + vec[j] for j in range(N+1)]

for _ in range(Q):
  p, q = reads()
  p, q = p-1, q-1
  ans = acc[N][q+1] - acc[p][q+1]
  print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

N, M, Q = map(int, input().split())
D = [[0]*N for i in range(N)]
E = [[-1]*N for i in range(N)]

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

def dfs(l, r):
    if not l <= r:
        return 0
    if l == r:
        return D[l][r]
    if E[l][r] != -1:
        return E[l][r]
    E[l][r] = res = D[l][r] + dfs(l+1, r) + dfs(l, r-1) - dfs(l+1, r-1)
    return res

ans = []
for i in range(Q):
    p, q = map(int, input().split())
    ans.append(dfs(p-1, q-1))
print(*ans, sep='\n')

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

N, M, Q = map(int, input().split())
D = [[0]*N for i in range(N)]
E = [[-1]*N for i in range(N)]

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

def dfs(l, r):
    if not l <= r:
        return 0
    if l == r:
        return D[l][r]
    if E[l][r] != -1:
        return E[l][r]
    E[l][r] = res = D[l][r] + dfs(l+1, r) + dfs(l, r-1) - dfs(l+1, r-1)
    return res

ans = []
for i in range(Q):
    p, q = map(int, input().split())
    ans.append(dfs(p-1, q-1))
print(*ans, sep='\n')

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,M,Q = inpl()
kukan = []

for i in range(M):
	l,r = inpl()
	kukan.append([r,-1,l])


for i in range(Q):
	p,q = inpl()
	kukan.append([q,i,p])

kukan.sort()

li = [0]*(N+1)
ans = [0]*Q
for t,flag,s in kukan:
	if flag == -1: 
		li[s] += 1
	else:
		ans[flag] = sum(li[s:t+1])

for a in ans:
	print(a)

Solution (Python):
n,m,q=map(int,raw_input().split())
lrs=[map(int,raw_input().split()) for _ in range(m)]
a=[[0 for j in range(n)] for i in range(n)]
for l,r in lrs:a[l-1][r-1]+=1
cnt=[[0 for j in range(n)] for i in range(n)]
for y in range(n):
 v = 0
 for x in range(y,-1,-1):
  v+=a[x][y]
  cnt[x][y]=cnt[x][y-1]+v
for _ in range(q):
 l,r=map(int,raw_input().split())
 print cnt[l-1][r-1]

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N, M, Q = reads()

mat = [[0] * N for _ in range(N)]
for _ in range(M):
  l, r = reads()
  l, r = l-1, r-1
  mat[l][r] += 1

acc = [[0] * (N+1) for _ in range(N+1)]
for i in range(N):
  vec = [0] + list(accumulate(mat[i]))
  acc[i+1] = [acc[i][j] + vec[j] for j in range(N+1)]

for _ in range(Q):
  p, q = reads()
  p, q = p-1, q-1
  ans = acc[N][q+1] - acc[p][q+1]
  print(ans)

Solution (Python):
s=input().split()
n,m,q=int(s[0]),int(s[1]),int(s[2])
arr=[[0 for i in range(n+3)] for j in range(n+3)]
for i in range(m):
    s=input().split()
    l,r=int(s[0]),int(s[1])
    for j in range(l+1):
        arr[j][r]+=1
for i in range(q):
    s=input().split()
    p,q=int(s[0]),int(s[1])
    print(sum(arr[p][1:q+1]))