int n, k, p; int sum[N], money, style, is_low; int nxt[N], head[N], after[N]; int ans;
vector<int> alls[55];
intmain() {
scanf("%d%d%d", &n, &k, &p); for(re int i = 1; i <= n; i ++) { scanf("%d%d", &style, &money); if(money <= p) is_low = 1; else is_low = 0; sum[i] = sum[i - 1] + is_low; alls[style].push_back(i); }
for(re int i = 0; i < k; i ++) { for(int j = 1; j < alls[i].size(); j ++) { nxt[alls[i][j - 1]] = alls[i][j]; after[alls[i][j - 1]] = alls[i].size() - j; } }
// for(int i = 1; i <= n; i ++) // cout << after[i] << endl;
for(re int i = 1; i <= n; i ++) { bool flag = false; int v = nxt[i]; while(v != 0) { if(sum[v] - sum[i - 1] > 0) is_low = 1, flag = true; else is_low = 0; ans += is_low; if(flag) { ans += after[v]; break; } v = nxt[v]; } }