program hotel(input,output);
var
i,color,x,p,n,k,jsq,j,ans:longint;
gs,a,f,s,c:array[-1..200000] of longint;
begin
assign(input,'hotel.in');
reset(input);
assign(output,'hotel.out');
rewrite(output);
readln(n,k,p);
for i:=1 to n do
begin
readln(color,x);
c[color]:=c[color]+1;
if x<=p then gs[i]:=gs[i-1]+1
else gs[i]:=gs[i-1];
f[i]:=a[color];
s[i]:=s[f[i]];
if (gs[i]-gs[f[i]-1]>0)and(f[i]<>0) then begin
s[i]:=c[color]-1;
ans:=ans+s[i];
end
else ans:=ans+s[f[i]];
a[color]:=i;
end;
writeln(ans);
close(input);
close(output);
end.