#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int s[200001][50]={0};
int c[200001]={0};
int m[200001]={0};
queue<int> q;
int n,k,p,cnt=0;
int main(){
freopen("hotel.in","r",stdin);
freopen("hotel.out","w",stdout);
scanf("%d%d%d",&n,&k,&p);
for (int i=1;i<=n;i++){
scanf("%d%d",&c[i],&m[i]);
for (int j=0;j<k;j++){
s[i][j]=s[i-1][j];
}
s[i][c[i]]++;
if (m[i]<=p) q.push(i);
}
for (int i=1;i<=n;i++){
int j=n+1;
while(!q.empty()){
if (q.front()<i) q.pop();
else break;
}if (q.empty()) break;
j=q.front();
cnt+=s[n][c[i]]-s[j][c[i]];
if (j!=i&&c[i]==c[j]) cnt++;
// printf("%d: %d %d\n",i,s[n][c[i]],s[j][c[i]]);
}
printf("%d",cnt);
return 0;
}