stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#pragma GCC optimize(2)

#include<bits/stdc++.h>

#define LL long long

#define int LL

const LL inf=0x3f3f3f3f;

using namespace std;

template<typename tp> inline void read(tp &x)

{

	x=0; char c=getchar(); bool f=0;

	for(;c<'0'||c>'9';f|=(c=='-'),c = getchar());

	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c = getchar());

	if(f) x=-x;

}

int n,m,q;

vector<int> x[510];

signed main()

{

	read(n),read(m),read(q);

	for(int i=1,l,r;i<=m;i++)

	{

		read(l),read(r);

		x[l].push_back(r);

	}

	for(int i=1;i<=n;i++)

		sort(x[i].begin(),x[i].end());

	for(int i=1,l,r;i<=q;i++)

	{

		read(l),read(r);

		int ret=0;

		for(int j=l;j<=r;j++)

			ret+=upper_bound(x[j].begin(),x[j].end(),r)-x[j].begin();

		printf("%lld\n",ret);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.080950488638294x):
//看题解了，重做 

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int NN = 700;

int x, y, ans, n, m, q, a[NN][NN], b[NN][NN], c[NN][NN];



int main(){

	//freopen("atcoderabc106d.in", "r", stdin);

	

	scanf("%d%d%d", &n, &m, &q);

	for (int i=1; i<=m; i++) {

		scanf("%d%d", &x, &y);

		a[x][y]++;

	}

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) b[i][j] += a[i][k];  //b[i][j]表示以i为起点，终点在j及j之前的边的个数 

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) c[i][j] += b[k][j];  //c[i][j]即为所求 

	

	

	while (q--){

		scanf("%d%d", &x, &y);

		printf("%d\n", c[x][y]);

		//printf("%d %d %d\n", r[y] - l[x-1], r[y], l[x-1]);

	} 

	

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int mp[505][505],dp[505][505];

int main()

{

	int n,m,q,l,r;

	scanf("%d%d%d",&n,&m,&q);

	for(int i=1;i<=m;i++)

	{

		scanf("%d%d",&l,&r);

		mp[l][r]++;

	}

	for(int i=1;i<=n;i++)

	{

		for(int j=1;j<=n;j++)

		{

			dp[i][j]=dp[i][j-1]+mp[i][j];

		}

	}

	for(int i=1;i<=q;i++)

	{

		int ans=0;

		scanf("%d%d",&l,&r);

		for(int i=l;i<=r;i++)

		{

			ans+=dp[i][r]-dp[i][l-1];

		}

		printf("%d\n",ans);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.015753967435707x):
//看题解了，重做 

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int NN = 700;

int x, y, ans, n, m, q, a[NN][NN], b[NN][NN], c[NN][NN];



int main(){

	//freopen("atcoderabc106d.in", "r", stdin);

	

	scanf("%d%d%d", &n, &m, &q);

	for (int i=1; i<=m; i++) {

		scanf("%d%d", &x, &y);

		a[x][y]++;

	}

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) b[i][j] += a[i][k];  //b[i][j]表示以i为起点，终点在j及j之前的边的个数 

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) c[i][j] += b[k][j];  //c[i][j]即为所求 

	

	

	while (q--){

		scanf("%d%d", &x, &y);

		printf("%d\n", c[x][y]);

		//printf("%d %d %d\n", r[y] - l[x-1], r[y], l[x-1]);

	} 

	

	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <cstring>

#include <iostream>

#include <algorithm>

#define LL long long



using namespace std;



const int MAXN=502,MAXM=2000011;

int n,m,q;

int sum[MAXN][MAXN];

int Query(int l,int r)

{

	return sum[r][r]-sum[r][l-1]-sum[l-1][r]+sum[l-1][l-1];

}

int main()

{

	scanf("%d%d%d",&n,&m,&q);

	

	for(int i=1;i<=m;i++)

	{

		int tx,ty;

		scanf("%d%d",&tx,&ty);

		sum[tx][ty]++;

		sum[ty][tx]++;

	}

	

	for(int i=1;i<=n;i++)

	{

		for(int j=1;j<=n;j++)

		{

			sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];

		}

	}

	

	for(int i=1;i<=q;i++)

	{

		int tx,ty;

		scanf("%d%d",&tx,&ty);

		printf("%d\n",Query(tx,ty)/2);

	}

	

	

	return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.015532373144097x):
//看题解了，重做 

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int NN = 700;

int x, y, ans, n, m, q, a[NN][NN], b[NN][NN], c[NN][NN];



int main(){

	//freopen("atcoderabc106d.in", "r", stdin);

	

	scanf("%d%d%d", &n, &m, &q);

	for (int i=1; i<=m; i++) {

		scanf("%d%d", &x, &y);

		a[x][y]++;

	}

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) b[i][j] += a[i][k];  //b[i][j]表示以i为起点，终点在j及j之前的边的个数 

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) c[i][j] += b[k][j];  //c[i][j]即为所求 

	

	

	while (q--){

		scanf("%d%d", &x, &y);

		printf("%d\n", c[x][y]);

		//printf("%d %d %d\n", r[y] - l[x-1], r[y], l[x-1]);

	} 

	

	return 0;

}
// Slower C++ solution:
#include<algorithm>

#include<cstdio>

#include<iostream>

#include<cstdlib>

#define lowbit(x) ((x)&(-(x)))

#define MAXN 1010

using namespace std;

int c[MAXN][MAXN];

int query(int x,int y)

{

	int f=0;

	while(x>0)

	{

		int tmp=y;

		while(tmp>0)

		{

			f+=c[x][tmp];

			tmp-=lowbit(tmp);

		}

		x-=lowbit(x);

	}

	return f;

}

void modify(int x,int y,int v)

{

	while(x<MAXN-10)

	{

		int tmp=y;

		while(tmp<MAXN-10)

		{

			c[x][tmp]+=v;

			tmp+=lowbit(tmp);

		}

		x+=lowbit(x);

	}

}

inline void change(int x,int y,int x1,int y1,int v)

{

	modify(x,y,v);

	modify(x1+1,y,-v);

	modify(x,y1+1,-v);

	modify(x1+1,y1+1,v);

}

int main()

{

	int n,m,Q,l,r;

	scanf("%d%d%d",&n,&m,&Q);

	for(int i=1;i<=m;i++)

	{

		scanf("%d%d",&l,&r);

		change(1,r,l,n,1);

	}

	while(Q--)

	{

		int q1,q2;

		scanf("%d%d",&q1,&q2);

		printf("%d\n",query(q1,q2));

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.027561906310516x):
//看题解了，重做 

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int NN = 700;

int x, y, ans, n, m, q, a[NN][NN], b[NN][NN], c[NN][NN];



int main(){

	//freopen("atcoderabc106d.in", "r", stdin);

	

	scanf("%d%d%d", &n, &m, &q);

	for (int i=1; i<=m; i++) {

		scanf("%d%d", &x, &y);

		a[x][y]++;

	}

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) b[i][j] += a[i][k];  //b[i][j]表示以i为起点，终点在j及j之前的边的个数 

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) c[i][j] += b[k][j];  //c[i][j]即为所求 

	

	

	while (q--){

		scanf("%d%d", &x, &y);

		printf("%d\n", c[x][y]);

		//printf("%d %d %d\n", r[y] - l[x-1], r[y], l[x-1]);

	} 

	

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define LL long long

#define db double

using namespace std;



template <typename T> inline void read(T &x) {

    int c = getchar();

    bool fg = false;

    for (x = 0; !isdigit(c); c = getchar()) {

        if (c == '-') {

            fg = true;

        }

    }

    for (; isdigit(c); c = getchar()) {

        x = x * 10 + c - '0';

    }

    if (fg) {

        x = -x;

    }

}

const int MAXN = 550;

const int INF = 0x3f3f3f3f;



int f[MAXN][MAXN], n, m, q;



signed main() {

	read(n), read(m), read(q);

	for(int i = 1; i <= m; i++) {

		int l, r;

		read(l), read(r);

		f[l][r]++;

		f[r][l]++;

	}

	for(int i = 1; i <= n; i++) {

		for(int j = 1; j <= n; j++) {

			f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + f[i][j];

		}

	}

	while(q--) {

		int l, r;

		read(l), read(r);

		int ans = f[r][r] - f[r][l - 1] - f[l - 1][r] + f[l - 1][l - 1];

		printf("%d\n", ans >> 1);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.994153016904358x):
//看题解了，重做 

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int NN = 700;

int x, y, ans, n, m, q, a[NN][NN], b[NN][NN], c[NN][NN];



int main(){

	//freopen("atcoderabc106d.in", "r", stdin);

	

	scanf("%d%d%d", &n, &m, &q);

	for (int i=1; i<=m; i++) {

		scanf("%d%d", &x, &y);

		a[x][y]++;

	}

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) b[i][j] += a[i][k];  //b[i][j]表示以i为起点，终点在j及j之前的边的个数 

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) c[i][j] += b[k][j];  //c[i][j]即为所求 

	

	

	while (q--){

		scanf("%d%d", &x, &y);

		printf("%d\n", c[x][y]);

		//printf("%d %d %d\n", r[y] - l[x-1], r[y], l[x-1]);

	} 

	

	return 0;

}
// Slower C++ solution:
#include<map>

#include<set>

#include<stack>

#include<cmath>

#include<queue>

#include<cstdio>

#include<string>

#include<vector>

#include<cstring>

#include<iostream>

#include<algorithm>

#define inf 0x3f3f3f3f

using namespace std;



int a[505][505], f[505][505];



int main()

{

	int n, m, q, l, r;

	scanf("%d%d%d", &n, &m, &q);

	for (int i = 1; i <= m; ++i) 

	{

		scanf("%d%d", &l, &r);

		a[l][r]++;

	}

	for (int i = 1; i <= n; ++i) f[i][i] = a[i][i];

	for (int i = 1; i <= n - 1; ++i) f[i][i + 1] = a[i][i + 1] + f[i + 1][i + 1] + f[i][i];

	for (int k = 2; k <= n - 1; ++k)

		for (int i = 1; i <= n - k; ++i) 

			f[i][i + k] = a[i][i + k] + f[i][i + k - 1] + f[i + 1][i + k] - f[i + 1][i + k - 1];

	for (int i = 1; i <= q; ++i)

	{

		scanf("%d%d", &l, &r);

		printf("%d\n", f[l][r]);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.016938817413944x):
//看题解了，重做 

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int NN = 700;

int x, y, ans, n, m, q, a[NN][NN], b[NN][NN], c[NN][NN];



int main(){

	//freopen("atcoderabc106d.in", "r", stdin);

	

	scanf("%d%d%d", &n, &m, &q);

	for (int i=1; i<=m; i++) {

		scanf("%d%d", &x, &y);

		a[x][y]++;

	}

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) b[i][j] += a[i][k];  //b[i][j]表示以i为起点，终点在j及j之前的边的个数 

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) c[i][j] += b[k][j];  //c[i][j]即为所求 

	

	

	while (q--){

		scanf("%d%d", &x, &y);

		printf("%d\n", c[x][y]);

		//printf("%d %d %d\n", r[y] - l[x-1], r[y], l[x-1]);

	} 

	

	return 0;

}
// Slower C++ solution:
#pragma GCC optimize(2)

#include<bits/stdc++.h>

#define LL long long

#define int LL

const LL inf=0x3f3f3f3f;

using namespace std;

template<typename tp> inline void read(tp &x)

{

	x=0; char c=getchar(); bool f=0;

	for(;c<'0'||c>'9';f|=(c=='-'),c = getchar());

	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c = getchar());

	if(f) x=-x;

}

int n,m,q;

vector<int> x[510];

signed main()

{

	read(n),read(m),read(q);

	for(int i=1,l,r;i<=m;i++)

	{

		read(l),read(r);

		x[l].push_back(r);

	}

	for(int i=1;i<=n;i++)

		sort(x[i].begin(),x[i].end());

	for(int i=1,l,r;i<=q;i++)

	{

		read(l),read(r);

		int ret=0;

		for(int j=l;j<=r;j++)

			ret+=upper_bound(x[j].begin(),x[j].end(),r)-x[j].begin();

		printf("%lld\n",ret);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.0793909696462975x):
//看题解了，重做 

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int NN = 700;

int x, y, ans, n, m, q, a[NN][NN], b[NN][NN], c[NN][NN];



int main(){

	//freopen("atcoderabc106d.in", "r", stdin);

	

	scanf("%d%d%d", &n, &m, &q);

	for (int i=1; i<=m; i++) {

		scanf("%d%d", &x, &y);

		a[x][y]++;

	}

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) b[i][j] += a[i][k];  //b[i][j]表示以i为起点，终点在j及j之前的边的个数 

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) c[i][j] += b[k][j];  //c[i][j]即为所求 

	

	

	while (q--){

		scanf("%d%d", &x, &y);

		printf("%d\n", c[x][y]);

		//printf("%d %d %d\n", r[y] - l[x-1], r[y], l[x-1]);

	} 

	

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int mp[505][505],dp[505][505];

int main()

{

	int n,m,q,l,r;

	scanf("%d%d%d",&n,&m,&q);

	for(int i=1;i<=m;i++)

	{

		scanf("%d%d",&l,&r);

		mp[l][r]++;

	}

	for(int i=1;i<=n;i++)

	{

		for(int j=1;j<=n;j++)

		{

			dp[i][j]=dp[i][j-1]+mp[i][j];

		}

	}

	for(int i=1;i<=q;i++)

	{

		int ans=0;

		scanf("%d%d",&l,&r);

		for(int i=l;i<=r;i++)

		{

			ans+=dp[i][r]-dp[i][l-1];

		}

		printf("%d\n",ans);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.014214459505274x):
//看题解了，重做 

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int NN = 700;

int x, y, ans, n, m, q, a[NN][NN], b[NN][NN], c[NN][NN];



int main(){

	//freopen("atcoderabc106d.in", "r", stdin);

	

	scanf("%d%d%d", &n, &m, &q);

	for (int i=1; i<=m; i++) {

		scanf("%d%d", &x, &y);

		a[x][y]++;

	}

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) b[i][j] += a[i][k];  //b[i][j]表示以i为起点，终点在j及j之前的边的个数 

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) c[i][j] += b[k][j];  //c[i][j]即为所求 

	

	

	while (q--){

		scanf("%d%d", &x, &y);

		printf("%d\n", c[x][y]);

		//printf("%d %d %d\n", r[y] - l[x-1], r[y], l[x-1]);

	} 

	

	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <cstring>

#include <iostream>

#include <algorithm>

#define LL long long



using namespace std;



const int MAXN=502,MAXM=2000011;

int n,m,q;

int sum[MAXN][MAXN];

int Query(int l,int r)

{

	return sum[r][r]-sum[r][l-1]-sum[l-1][r]+sum[l-1][l-1];

}

int main()

{

	scanf("%d%d%d",&n,&m,&q);

	

	for(int i=1;i<=m;i++)

	{

		int tx,ty;

		scanf("%d%d",&tx,&ty);

		sum[tx][ty]++;

		sum[ty][tx]++;

	}

	

	for(int i=1;i<=n;i++)

	{

		for(int j=1;j<=n;j++)

		{

			sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];

		}

	}

	

	for(int i=1;i<=q;i++)

	{

		int tx,ty;

		scanf("%d%d",&tx,&ty);

		printf("%d\n",Query(tx,ty)/2);

	}

	

	

	return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.0139929332285975x):
//看题解了，重做 

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int NN = 700;

int x, y, ans, n, m, q, a[NN][NN], b[NN][NN], c[NN][NN];



int main(){

	//freopen("atcoderabc106d.in", "r", stdin);

	

	scanf("%d%d%d", &n, &m, &q);

	for (int i=1; i<=m; i++) {

		scanf("%d%d", &x, &y);

		a[x][y]++;

	}

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) b[i][j] += a[i][k];  //b[i][j]表示以i为起点，终点在j及j之前的边的个数 

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) c[i][j] += b[k][j];  //c[i][j]即为所求 

	

	

	while (q--){

		scanf("%d%d", &x, &y);

		printf("%d\n", c[x][y]);

		//printf("%d %d %d\n", r[y] - l[x-1], r[y], l[x-1]);

	} 

	

	return 0;

}
// Slower C++ solution:
#include<algorithm>

#include<cstdio>

#include<iostream>

#include<cstdlib>

#define lowbit(x) ((x)&(-(x)))

#define MAXN 1010

using namespace std;

int c[MAXN][MAXN];

int query(int x,int y)

{

	int f=0;

	while(x>0)

	{

		int tmp=y;

		while(tmp>0)

		{

			f+=c[x][tmp];

			tmp-=lowbit(tmp);

		}

		x-=lowbit(x);

	}

	return f;

}

void modify(int x,int y,int v)

{

	while(x<MAXN-10)

	{

		int tmp=y;

		while(tmp<MAXN-10)

		{

			c[x][tmp]+=v;

			tmp+=lowbit(tmp);

		}

		x+=lowbit(x);

	}

}

inline void change(int x,int y,int x1,int y1,int v)

{

	modify(x,y,v);

	modify(x1+1,y,-v);

	modify(x,y1+1,-v);

	modify(x1+1,y1+1,v);

}

int main()

{

	int n,m,Q,l,r;

	scanf("%d%d%d",&n,&m,&Q);

	for(int i=1;i<=m;i++)

	{

		scanf("%d%d",&l,&r);

		change(1,r,l,n,1);

	}

	while(Q--)

	{

		int q1,q2;

		scanf("%d%d",&q1,&q2);

		printf("%d\n",query(q1,q2));

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.026018774116282x):
//看题解了，重做 

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int NN = 700;

int x, y, ans, n, m, q, a[NN][NN], b[NN][NN], c[NN][NN];



int main(){

	//freopen("atcoderabc106d.in", "r", stdin);

	

	scanf("%d%d%d", &n, &m, &q);

	for (int i=1; i<=m; i++) {

		scanf("%d%d", &x, &y);

		a[x][y]++;

	}

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) b[i][j] += a[i][k];  //b[i][j]表示以i为起点，终点在j及j之前的边的个数 

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) c[i][j] += b[k][j];  //c[i][j]即为所求 

	

	

	while (q--){

		scanf("%d%d", &x, &y);

		printf("%d\n", c[x][y]);

		//printf("%d %d %d\n", r[y] - l[x-1], r[y], l[x-1]);

	} 

	

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define LL long long

#define db double

using namespace std;



template <typename T> inline void read(T &x) {

    int c = getchar();

    bool fg = false;

    for (x = 0; !isdigit(c); c = getchar()) {

        if (c == '-') {

            fg = true;

        }

    }

    for (; isdigit(c); c = getchar()) {

        x = x * 10 + c - '0';

    }

    if (fg) {

        x = -x;

    }

}

const int MAXN = 550;

const int INF = 0x3f3f3f3f;



int f[MAXN][MAXN], n, m, q;



signed main() {

	read(n), read(m), read(q);

	for(int i = 1; i <= m; i++) {

		int l, r;

		read(l), read(r);

		f[l][r]++;

		f[r][l]++;

	}

	for(int i = 1; i <= n; i++) {

		for(int j = 1; j <= n; j++) {

			f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + f[i][j];

		}

	}

	while(q--) {

		int l, r;

		read(l), read(r);

		int ans = f[r][r] - f[r][l - 1] - f[l - 1][r] + f[l - 1][l - 1];

		printf("%d\n", ans >> 1);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.992620139050851x):
//看题解了，重做 

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int NN = 700;

int x, y, ans, n, m, q, a[NN][NN], b[NN][NN], c[NN][NN];



int main(){

	//freopen("atcoderabc106d.in", "r", stdin);

	

	scanf("%d%d%d", &n, &m, &q);

	for (int i=1; i<=m; i++) {

		scanf("%d%d", &x, &y);

		a[x][y]++;

	}

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) b[i][j] += a[i][k];  //b[i][j]表示以i为起点，终点在j及j之前的边的个数 

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) c[i][j] += b[k][j];  //c[i][j]即为所求 

	

	

	while (q--){

		scanf("%d%d", &x, &y);

		printf("%d\n", c[x][y]);

		//printf("%d %d %d\n", r[y] - l[x-1], r[y], l[x-1]);

	} 

	

	return 0;

}
// Slower C++ solution:
#include<map>

#include<set>

#include<stack>

#include<cmath>

#include<queue>

#include<cstdio>

#include<string>

#include<vector>

#include<cstring>

#include<iostream>

#include<algorithm>

#define inf 0x3f3f3f3f

using namespace std;



int a[505][505], f[505][505];



int main()

{

	int n, m, q, l, r;

	scanf("%d%d%d", &n, &m, &q);

	for (int i = 1; i <= m; ++i) 

	{

		scanf("%d%d", &l, &r);

		a[l][r]++;

	}

	for (int i = 1; i <= n; ++i) f[i][i] = a[i][i];

	for (int i = 1; i <= n - 1; ++i) f[i][i + 1] = a[i][i + 1] + f[i + 1][i + 1] + f[i][i];

	for (int k = 2; k <= n - 1; ++k)

		for (int i = 1; i <= n - k; ++i) 

			f[i][i + k] = a[i][i + k] + f[i][i + k - 1] + f[i + 1][i + k] - f[i + 1][i + k - 1];

	for (int i = 1; i <= q; ++i)

	{

		scanf("%d%d", &l, &r);

		printf("%d\n", f[l][r]);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.015398945812177x):
//看题解了，重做 

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int NN = 700;

int x, y, ans, n, m, q, a[NN][NN], b[NN][NN], c[NN][NN];



int main(){

	//freopen("atcoderabc106d.in", "r", stdin);

	

	scanf("%d%d%d", &n, &m, &q);

	for (int i=1; i<=m; i++) {

		scanf("%d%d", &x, &y);

		a[x][y]++;

	}

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) b[i][j] += a[i][k];  //b[i][j]表示以i为起点，终点在j及j之前的边的个数 

	

	for (int i=1; i<=n; i++)

		for (int j=i; j<=n; j++)

			for (int k=i; k<=j; k++) c[i][j] += b[k][j];  //c[i][j]即为所求 

	

	

	while (q--){

		scanf("%d%d", &x, &y);

		printf("%d\n", c[x][y]);

		//printf("%d %d %d\n", r[y] - l[x-1], r[y], l[x-1]);

	} 

	

	return 0;

}
// Slower C++ solution:
#pragma GCC optimize(2)

#include<bits/stdc++.h>

#define LL long long

#define int LL

const LL inf=0x3f3f3f3f;

using namespace std;

template<typename tp> inline void read(tp &x)

{

	x=0; char c=getchar(); bool f=0;

	for(;c<'0'||c>'9';f|=(c=='-'),c = getchar());

	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c = getchar());

	if(f) x=-x;

}

int n,m,q;

vector<int> x[510];

signed main()

{

	read(n),read(m),read(q);

	for(int i=1,l,r;i<=m;i++)

	{

		read(l),read(r);

		x[l].push_back(r);

	}

	for(int i=1;i<=n;i++)

		sort(x[i].begin(),x[i].end());

	for(int i=1,l,r;i<=q;i++)

	{

		read(l),read(r);

		int ret=0;

		for(int j=l;j<=r;j++)

			ret+=upper_bound(x[j].begin(),x[j].end(),r)-x[j].begin();

		printf("%lld\n",ret);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.188649300303087x):
#include <cstdio>

#include <cstring>

#include <algorithm>

void Unused(...) {}

#ifndef DEBUG

  #define echo(...) Unused(__VA_ARGS__)

#else

  #define echo(...) fprintf(stderr, __VA_ARGS__)

#endif



const int MaxN = 500 + 7;

const int MaxM = int(3e5) + 7;



struct Inv

{

    int l, r;

    int idx;

    friend bool operator<(const Inv &a, const Inv &b)

    {

        return a.l == b.l ? a.idx < b.idx : a.l > b.l;

    }

};

Inv rd[MaxM];



int n, m, q;

int ans[MaxM];



int vol[MaxN];

int lowbit(int x) { return x & (-x); }



int query(int v)

{

    int res = 0;

    for (; v > 0; v -= lowbit(v))

        res += vol[v];

    return res;

}

void update(int v)

{

    for (; v < MaxN; v += lowbit(v))

        ++vol[v];

}



int main()

{

    scanf("%d %d %d", &n, &m, &q);

    for (int i = 1; i <= m; ++i)

        scanf("%d %d", &rd[i].l, &rd[i].r);

    for (int i = 1; i <= q; ++i)

    {

        scanf("%d %d", &rd[i + m].l, &rd[i + m].r);

        rd[i + m].idx = i;

    }

    std::sort(rd + 1, rd + m + q + 1);



    for (int i = 1; i <= m + q; ++i)

    {

        // query

        if (rd[i].idx > 0)

            ans[rd[i].idx] = query(rd[i].r);

        else

            update(rd[i].r);

    }

    for (int i = 1; i <= q; ++i)

        printf("%d\n", ans[i]);



    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int mp[505][505],dp[505][505];

int main()

{

	int n,m,q,l,r;

	scanf("%d%d%d",&n,&m,&q);

	for(int i=1;i<=m;i++)

	{

		scanf("%d%d",&l,&r);

		mp[l][r]++;

	}

	for(int i=1;i<=n;i++)

	{

		for(int j=1;j<=n;j++)

		{

			dp[i][j]=dp[i][j-1]+mp[i][j];

		}

	}

	for(int i=1;i<=q;i++)

	{

		int ans=0;

		scanf("%d%d",&l,&r);

		for(int i=l;i<=r;i++)

		{

			ans+=dp[i][r]-dp[i][l-1];

		}

		printf("%d\n",ans);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.122070835333503x):
#include <cstdio>

#include <cstring>

#include <algorithm>

void Unused(...) {}

#ifndef DEBUG

  #define echo(...) Unused(__VA_ARGS__)

#else

  #define echo(...) fprintf(stderr, __VA_ARGS__)

#endif



const int MaxN = 500 + 7;

const int MaxM = int(3e5) + 7;



struct Inv

{

    int l, r;

    int idx;

    friend bool operator<(const Inv &a, const Inv &b)

    {

        return a.l == b.l ? a.idx < b.idx : a.l > b.l;

    }

};

Inv rd[MaxM];



int n, m, q;

int ans[MaxM];



int vol[MaxN];

int lowbit(int x) { return x & (-x); }



int query(int v)

{

    int res = 0;

    for (; v > 0; v -= lowbit(v))

        res += vol[v];

    return res;

}

void update(int v)

{

    for (; v < MaxN; v += lowbit(v))

        ++vol[v];

}



int main()

{

    scanf("%d %d %d", &n, &m, &q);

    for (int i = 1; i <= m; ++i)

        scanf("%d %d", &rd[i].l, &rd[i].r);

    for (int i = 1; i <= q; ++i)

    {

        scanf("%d %d", &rd[i + m].l, &rd[i + m].r);

        rd[i + m].idx = i;

    }

    std::sort(rd + 1, rd + m + q + 1);



    for (int i = 1; i <= m + q; ++i)

    {

        // query

        if (rd[i].idx > 0)

            ans[rd[i].idx] = query(rd[i].r);

        else

            update(rd[i].r);

    }

    for (int i = 1; i <= q; ++i)

        printf("%d\n", ans[i]);



    return 0;

}