fork download
  1. program C;
  2. const MAXN =100000;
  3. type elenco= array[1..MAXN] of Int64;
  4. var N, i, h:Longint;
  5. diffcoord, uguali:elenco;
  6. coordinate : array[1..MAXN, 1..2] of Int64;
  7. squares :Int64;
  8.  
  9. Procedure scambia (var a,b: Int64);
  10. var x:Int64;
  11. begin
  12. x:=a;
  13. a:=b;
  14. b:=x;
  15. end;
  16. Procedure ordinamento (estremoi,estremos: Int64; var v : elenco; ordinato:boolean);
  17. var inf, sup, medio:Int64;
  18. pivot :Int64;
  19. begin
  20. inf:=estremoi;
  21. sup:=estremos;
  22. medio:= (estremoi+estremos) div 2;
  23. pivot:=v[medio];
  24. repeat
  25. if (ordinato) then
  26. begin
  27. while (v[inf]<pivot) do inf:=inf+1;
  28. while (v[sup]>pivot) do sup:=sup-1;
  29. end;
  30. if inf<=sup then
  31. begin
  32. scambia(v[inf],v[sup]);
  33. inf:=inf+1;
  34. sup:=sup-1;
  35. end;
  36. until inf>sup;
  37. if (estremoi<sup) then ordinamento(estremoi,sup,v,ordinato);
  38. if (inf<estremos) then ordinamento(inf,estremos,v,ordinato);
  39. end;
  40.  
  41. begin
  42. read(N);
  43. for i:=1 to N do
  44. begin
  45. readln (coordinate[i][1], coordinate[i][2]);
  46. diffcoord[i]:=coordinate[i][1] - coordinate[i][2];
  47. uguali[i]:=1;
  48. end;
  49. ordinamento (1,N,diffcoord, true);
  50. squares:=0; h:=1; i:=1;
  51. while i<N do
  52. begin
  53. if diffcoord[i]=diffcoord[i+1] then begin uguali[h]:=uguali[h]+1; i:=i+1; end
  54. else begin i:=i+1; h:=h+1; end;
  55. end;
  56. for i:=1 to h do
  57. squares:=squares+(uguali[i]*(uguali[i]-1) div 2);
  58. writeln(squares);
  59. end.
  60.  
  61.  
Success #stdin #stdout 0.01s 5288KB
stdin
4
0 0
2 3
5 6
4 4


stdout
2