stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

	ll n,m;

	cin>>n>>m;

	ll p[m],y[m];

	vector<ll>py[100001];

	for(int i=0;i<m;i++)cin>>p[i]>>y[i];





	for(int i=0;i<m;i++)py[p[i]].push_back(y[i]);

	for(int i=0;i<n;i++)sort(py[i+1].begin(),py[i+1].end());

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

		printf ("%012lld\n",ll(p[i])*1000000+ int(lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i])-py[p[i]].begin())+1);

	}



/*	for(int i=0;i<m;i++){

		printf("%lld\n",*lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i]));

	}*/

	//	for(int i=0;i<m;i++)num[y[i]]=i;

	//sort(y,y+m);

	 /*for( vector<ll>::iterator i=begin(py);i!=end(py);++i) {

	      std::cout << i << std::endl;

	   }*/

}


// Faster C++ solution for the same problem (measured speedup: 3.5525986189381586x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

	ll n,m;

	cin>>n>>m;

	ll p[m],y[m];

	vector<ll>py[n+1];

	for(int i=0;i<m;i++)cin>>p[i]>>y[i];





	for(int i=0;i<m;i++)py[p[i]].push_back(y[i]);

	for(int i=0;i<n;i++)sort(py[i+1].begin(),py[i+1].end());

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

		printf ("%012lld\n",ll(p[i])*1000000+ int(lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i])-py[p[i]].begin())+1);

	}



/*	for(int i=0;i<m;i++){

		printf("%lld\n",*lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i]));

	}*/

	//	for(int i=0;i<m;i++)num[y[i]]=i;

	//sort(y,y+m);

	 /*for( vector<ll>::iterator i=begin(py);i!=end(py);++i) {

	      std::cout << i << std::endl;

	   }*/

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

#include <cstring>

#include <iostream>

#include <string>

#include <cmath>

#include <bitset>

#include <vector>

#include <map>

#include <set>

#include <queue>

#include <deque>

#include <algorithm>

#include <complex>

#include <unordered_map>

#include <random>

using namespace std;

typedef long long int ll;

typedef pair<int, int> P;

int main()

{

	vector<P> v[100001];

	int n, m;

	cin>>n>>m;

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

		int p, y;

		cin>>p>>y;

		v[p].push_back(P(y, i));

	}

	string s[100001];

	ll ans[100001];

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

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

		for(ll j=0; j<v[i].size(); j++){

			int t=v[i][j].second;

			ans[t]=i*1000000+j+1;

			ll ans1=ans[t];

			int ct=0;

			while(ans1>0){

				ans1/=10;

				ct++;

			}

			for(int k=0; k<12-ct; k++) s[t]+='0';

		}

	}

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

		cout<<s[i]<<ans[i]<<endl;

	}

	return 0;

}

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

#include <cstring>

#include <iostream>

#include <string>

#include <cmath>

#include <bitset>

#include <vector>

#include <map>

#include <set>

#include <queue>

#include <deque>

#include <algorithm>

#include <complex>

#include <unordered_map>

#include <random>

using namespace std;

typedef long long int ll;

typedef pair<int, int> P;

int main()

{

	vector<P> v[100001];

	int n, m;

	cin>>n>>m;

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

		int p, y;

		cin>>p>>y;

		v[p].push_back(P(y, i));

	}

	ll ans[100001];

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

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

		for(ll j=0; j<v[i].size(); j++){

			int t=v[i][j].second;

			ans[t]=i*1000000+j+1;

		}

	}

	for(int i=0; i<m; i++) printf("%012lld\n", ans[i]);

	return 0;

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

#include<vector>

#include<cmath>

using namespace std;



int main() {

  int N, T;

  vector<int> t;



  cin >> N >> T;

  t.resize(N);



  for (int i = 0; i < N; i++)

    cin >> t[i];



  int64_t ans = 0;

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

    if (t[i] - t[i-1] >= T)

      ans += T;

    else

      ans += t[i] - t[i-1];

  }

  ans += T;



  cout << ans << endl;

}


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



int main() {

  int N, T; scanf("%d %d\n", &N, &T);

  int t[N];



  for (int i = 0; i < N; i++)

    scanf("%d", &t[i]);



  long ans = 0;

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

    if (t[i] - t[i-1] >= T)

      ans += T;

    else

      ans += t[i] - t[i-1];

  }

  ans += T;



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

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

#include <stdio.h>

#include <algorithm>

#include <vector>

#include <assert.h>



using namespace std;



#define N 100005



int dsu[N],ret[N];

long long W[N];

vector<int> edgeS[N];

bool isGoodEdge[N];



int f(int x) {

  if(x==dsu[x]) {

    return x;

  }

  return dsu[x] = f(dsu[x]);

}

void merge(int x,int y,int id,int wei) {

  x = f(x),y = f(y);

  if(x!=y) {

    if(edgeS[x].size()<edgeS[y].size()) {

      swap(x,y);

    }

    dsu[y] = x;

    W[x] += W[y];

    while(edgeS[y].size()>0) {

      edgeS[x].push_back(edgeS[y].back());

      edgeS[y].pop_back();

    }

  }

  edgeS[x].push_back(id);

  if(W[x]>=wei) {

    while(edgeS[x].size()>0) {

      isGoodEdge[edgeS[x].back()] = true;

      edgeS[x].pop_back();

    }

  }

}

void solve() {

  int n,m;

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

  pair<int,pair<int,int> > edgeS[N];

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

    dsu[i] = i;

    scanf("%lld",&W[i]);

  }

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

    scanf("%d %d %d",&edgeS[i].second.first,&edgeS[i].second.second,&edgeS[i].first);

  }

  sort(edgeS,edgeS+m);

  int R = 0;

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

    int w = edgeS[i].first;

    int a = edgeS[i].second.first, b = edgeS[i].second.second;

    merge(a,b,i,w);

  }

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

    if(isGoodEdge[i]) {

      ++R;

    }

  }

  printf("%d\n",m - R);

}



int main() {

  //freopen("input.txt","r",stdin);

  solve();

  return 0;

}


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

#include <stdio.h>

#include <algorithm>

#include <vector>

#include <assert.h>

#include <memory.h>



using namespace std;



#define N 100001



int dsu[N],numUnsat[N];

long long sum[N];

int f(int x) {

  return dsu[x] ==x ? x : dsu[x] = f(dsu[x]);

}

void merge(int &ret,int x,int y,int wei) {

  x = f(x),y = f(y);

  if(x==y) {

    ++numUnsat[x];

  } else {

    sum[x] += sum[y];

    dsu[y] = x;

    numUnsat[x] = numUnsat[x] + numUnsat[y] + 1;

  }

  if(sum[x]>=wei) {

    ret += numUnsat[x];

    numUnsat[x] = 0;

  }

}

void solve() {

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

  pair<int,pair<int,int> > edge[N];

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

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

    dsu[i] = i;

    numUnsat[i] = 0;

    sum[i] = x;

  }

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

    int a,b,w;scanf("%d %d %d ",&a,&b,&w);

    edge[i] = make_pair(w,make_pair(a,b));

  }

  sort(edge,edge+m);

  int ret = 0;

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

    merge(ret, edge[i].second.first,edge[i].second.second,edge[i].first);

  }

  printf("%d\n",m-ret);

}



int main() {

  //freopen("input.txt","r",stdin);

  solve();

  return 0;

}
// Slower C++ solution:
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)

#pragma GCC optimize(2)

#include<iostream>

#include<algorithm>

#define l first

#define r second

using namespace std;

typedef long long ll;

typedef pair<int,int> pii;

const int N=200010;

const ll mod=998244353;

int n,k;

ll f[N],s[N];

pii a[N];

int main()

{

    IO;

    int T=1;

    //cin>>T;

    while(T--)

    {

        cin>>n>>k;

        for(int i=1;i<=n;i++) cin>>a[i].l>>a[i].r;

        f[1]=1;

        s[1]=1;

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

        {

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

                f[i]=(f[i]+s[max(0,i-a[j].l)]-s[max(0,i-a[j].r-1)])%mod;;

            s[i]=(s[i-1]+f[i])%mod;

        }    

        cout<<(f[n]+mod)%mod<<'\n';

    }

    return 0;

}

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

#define mod 998244353

#define max(a,b) ((a)>(b)?(a):(b))

struct interval{

    int l,r;

}a[200003];

long long f[200003]={0,1},s[200003]={0,1};

int n,k;

int main(){

    scanf("%d%d",&n,&k);

    for(int i=1;i<=k;i++) scanf("%d%d",&a[i].l,&a[i].r);

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

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

            if(i>a[j].l) f[i]=(f[i]+(s[i-a[j].l]-s[max(i-a[j].r-1,0)])%mod)%mod;

        }

        s[i]=(s[i-1]+f[i])%mod;

    }

    printf("%lld\n",(f[n]+mod)%mod);

    return 0;

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

using namespace std;

int dp[1010][1010];

int main()

{

	int n,m,q,i,x,y,j,k;

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

	memset(dp,0,sizeof(dp));

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

	{

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

		dp[x][y]++;

	}

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

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

		{

			k=i+j;

			dp[i][k]=dp[i][k]+dp[i+1][k]+dp[i][k-1];

			if(j>1)dp[i][k]-=dp[i+1][k-1];

		}

	while(q--)

	{

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

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

	}







	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.202596488445367x):
#include <bits/stdc++.h>



using namespace std;



int rang[510][510],f[510][510];

int main()

{

    int n,m,q;

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

        

    int l,r;

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

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

        rang[l][r]++;

    }

            

    for(int i=n; i>=1; i--) {

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

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

        }

    }



    while(q--){

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

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

    }





    return 0;

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

using namespace std;

int dp[1010][1010];

int main()

{

	int n,m,q,i,x,y,j,k;

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

	memset(dp,0,sizeof(dp));

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

	{

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

		dp[x][y]++;

	}

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

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

		{

			k=i+j;

			dp[i][k]=dp[i][k]+dp[i+1][k]+dp[i][k-1];

			if(j>1)dp[i][k]-=dp[i+1][k-1];

		}

	while(q--)

	{

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

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

	}







	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.527386548643905x):
// vjudge 259706 D

#include <cstdio>

#include <algorithm>

#include <vector>

const int MAXN = 510;



std::vector<int> T[MAXN];

int N, M, Q;



namespace FastIO {

	template <typename T>

	void read(T & x) {

		x = 0; register char ch = getchar();

		for (; ch < '0' || ch > '9'; ch = getchar());

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

	}

}



int main() {

	using FastIO::read;

	read(N), read(M), read(Q);

	for (int i = 0, Li, Ri; i < M; i++) {

		read(Li), read(Ri);

		T[Li].push_back(Ri);

	}

	for (int i = 1; i <= 500; i++) std::sort(T[i].begin(), T[i].end());

	for (int i = 0, l, r; i < Q; i++) {

		read(l), read(r);

		int ans = 0;

		for (; l <= r; l++) {

//			printf("l=%d ?%d\n", l, std::upper_bound(T[l].begin(), T[l].end(), r) == T[l].end());

			ans += std::upper_bound(T[l].begin(), T[l].end(), r) - T[l].begin();

		}

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

	}

	return 0;

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

using namespace std;

int dp[1010][1010];

int main()

{

	int n,m,q,i,x,y,j,k;

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

	memset(dp,0,sizeof(dp));

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

	{

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

		dp[x][y]++;

	}

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

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

		{

			k=i+j;

			dp[i][k]=dp[i][k]+dp[i+1][k]+dp[i][k-1];

			if(j>1)dp[i][k]-=dp[i+1][k-1];

		}

	while(q--)

	{

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

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

	}







	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.196624295282934x):
#include<bits/stdc++.h>

using namespace std;



const int maxn=505;

int n,m,q,dif[maxn][maxn],ans[maxn][maxn],f[maxn][maxn],l,r;



int main(){

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

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

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

		dif[l][r]++;

	}

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

		ans[j][j]=dif[j][j];

		for (int i=j-1;i>=1;i--) ans[i][j]=ans[i+1][j]+dif[i][j];

	}

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

		f[i][i]=dif[i][i];

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

	}

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

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

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

	}

	return 0;

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

using namespace std;

int dp[1010][1010];

int main()

{

	int n,m,q,i,x,y,j,k;

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

	memset(dp,0,sizeof(dp));

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

	{

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

		dp[x][y]++;

	}

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

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

		{

			k=i+j;

			dp[i][k]=dp[i][k]+dp[i+1][k]+dp[i][k-1];

			if(j>1)dp[i][k]-=dp[i+1][k-1];

		}

	while(q--)

	{

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

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

	}







	return 0;

}

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

#include <cstdlib>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <cctype>



const int M=2e5+11;

using namespace std;

struct node{

	int l, r, ans, id;

	bool q;

}a[M*2];



int n, m, Q, num[1011];



bool cmp(node x, node y) {

	if (x.r!=y.r) return x.r<y.r;

	else return x.q<y.q;

}



bool cmp0(node x, node y) {

	if (x.q!=y.q) return x.q>y.q; 

    else return x.id<y.id;

}



inline int get() {

    int X=0,W=0; char CH=0;

    while(!isdigit(CH)) {W|=CH=='-';CH=getchar();}

    while(isdigit(CH)) X=(X<<3)+(X<<1)+(CH^48), CH=getchar();

    return W?-X:X;

}

 

int main() {

	n=get(), m=get(), Q=get();

	for (register int i=1; i<=m; i++) a[i].l=get(), a[i].r=get();

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

	    a[i].l=get(), a[i].r=get(), a[i].id=i, a[i].q=true;

	

	sort(a+1, a+m+Q+1, cmp);

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

		if (!a[i].q) num[a[i].l]++;

		else {

			int sum=0;

			for (int j=a[i].l; j<=a[i].r; j++) 

			    sum+=num[j];

			a[i].ans=sum;

		}

	}	

	

	sort(a+1, a+m+Q+1, cmp0);

	

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

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

 	return 0;

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

using namespace std;

int dp[1010][1010];

int main()

{

	int n,m,q,i,x,y,j,k;

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

	memset(dp,0,sizeof(dp));

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

	{

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

		dp[x][y]++;

	}

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

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

		{

			k=i+j;

			dp[i][k]=dp[i][k]+dp[i+1][k]+dp[i][k-1];

			if(j>1)dp[i][k]-=dp[i+1][k-1];

		}

	while(q--)

	{

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

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

	}







	return 0;

}

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

#include <cstring>

#include <string>

#include <cstdio>

#include <cmath>

using namespace std;

const int N = 5e2 + 10;

int n, m, q;

int dp[N][N], a[N][N];

int main()

{

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

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

    {

        int x, y;

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

        a[x][y]++;

    }

    for (int i = n; i >= 1; i--)

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

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

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

    {

        int x, y;

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

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

    }

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

using namespace std;

int dp[1010][1010];

int main()

{

	int n,m,q,i,x,y,j,k;

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

	memset(dp,0,sizeof(dp));

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

	{

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

		dp[x][y]++;

	}

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

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

		{

			k=i+j;

			dp[i][k]=dp[i][k]+dp[i+1][k]+dp[i][k-1];

			if(j>1)dp[i][k]-=dp[i+1][k-1];

		}

	while(q--)

	{

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

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

	}







	return 0;

}

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

#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 rang[510][510],f[510][510];

int main()

{

    int n,m,q;

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

        

    int l,r;

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

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

        rang[l][r]++;

    }

            

    for(int i=n; i>=1; i--) {

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

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

        }

    }



    while(q--){

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

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

    }





    return 0;

}

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

#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:
// vjudge 259706 D

#include <cstdio>

#include <algorithm>

#include <vector>

const int MAXN = 510;



std::vector<int> T[MAXN];

int N, M, Q;



namespace FastIO {

	template <typename T>

	void read(T & x) {

		x = 0; register char ch = getchar();

		for (; ch < '0' || ch > '9'; ch = getchar());

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

	}

}



int main() {

	using FastIO::read;

	read(N), read(M), read(Q);

	for (int i = 0, Li, Ri; i < M; i++) {

		read(Li), read(Ri);

		T[Li].push_back(Ri);

	}

	for (int i = 1; i <= 500; i++) std::sort(T[i].begin(), T[i].end());

	for (int i = 0, l, r; i < Q; i++) {

		read(l), read(r);

		int ans = 0;

		for (; l <= r; l++) {

//			printf("l=%d ?%d\n", l, std::upper_bound(T[l].begin(), T[l].end(), r) == T[l].end());

			ans += std::upper_bound(T[l].begin(), T[l].end(), r) - T[l].begin();

		}

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

	}

	return 0;

}

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

#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;



const int maxn=505;

int n,m,q,dif[maxn][maxn],ans[maxn][maxn],f[maxn][maxn],l,r;



int main(){

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

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

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

		dif[l][r]++;

	}

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

		ans[j][j]=dif[j][j];

		for (int i=j-1;i>=1;i--) ans[i][j]=ans[i+1][j]+dif[i][j];

	}

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

		f[i][i]=dif[i][i];

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

	}

	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.021770432458108x):
//看题解了，重做 

#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 <iostream>

#include <cstdlib>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <cctype>



const int M=2e5+11;

using namespace std;

struct node{

	int l, r, ans, id;

	bool q;

}a[M*2];



int n, m, Q, num[1011];



bool cmp(node x, node y) {

	if (x.r!=y.r) return x.r<y.r;

	else return x.q<y.q;

}



bool cmp0(node x, node y) {

	if (x.q!=y.q) return x.q>y.q; 

    else return x.id<y.id;

}



inline int get() {

    int X=0,W=0; char CH=0;

    while(!isdigit(CH)) {W|=CH=='-';CH=getchar();}

    while(isdigit(CH)) X=(X<<3)+(X<<1)+(CH^48), CH=getchar();

    return W?-X:X;

}

 

int main() {

	n=get(), m=get(), Q=get();

	for (register int i=1; i<=m; i++) a[i].l=get(), a[i].r=get();

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

	    a[i].l=get(), a[i].r=get(), a[i].id=i, a[i].q=true;

	

	sort(a+1, a+m+Q+1, cmp);

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

		if (!a[i].q) num[a[i].l]++;

		else {

			int sum=0;

			for (int j=a[i].l; j<=a[i].r; j++) 

			    sum+=num[j];

			a[i].ans=sum;

		}

	}	

	

	sort(a+1, a+m+Q+1, cmp0);

	

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

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

 	return 0;

}

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

#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 <iostream>

#include <cstring>

#include <string>

#include <cstdio>

#include <cmath>

using namespace std;

const int N = 5e2 + 10;

int n, m, q;

int dp[N][N], a[N][N];

int main()

{

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

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

    {

        int x, y;

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

        a[x][y]++;

    }

    for (int i = n; i >= 1; i--)

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

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

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

    {

        int x, y;

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

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

    }

}

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

#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;

}