fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #ifndef M
  4. #define M 1000000007
  5. #endif
  6.  
  7. typedef long long ll;
  8. typedef pair<ll,ll>pp;
  9. typedef std::vector<pp> vpp;
  10. #ifndef pb
  11. #define pb push_back
  12. #endif
  13. int min(int x,int y){return(x<y)?x:y;}
  14. int max(int x,int y){return(x>y)?x:y;}
  15. int n=0;
  16. char ch;
  17. int a[2000005]={0},b[2000005]={0};
  18. int main(int argc, char const *argv[])
  19. {
  20. int n,x,y;
  21. scanf("%d",&n);
  22. while(n--)
  23. {
  24. scanf("%d %d",&x,&y);
  25. int z=x+y;
  26. a[z]++;
  27. if(x>=y)
  28. b[x-y]++;
  29. else
  30. b[1000000+(y-x)]++;
  31. }
  32. ll k=0;
  33. for(int i=0;i<=2000002;i++)
  34. {
  35. if(a[i]>0)
  36. {
  37. ll z=a[i];
  38. z*=a[i]-1;
  39. z/=2;
  40. k+=z;
  41. }
  42. if(b[i]>0)
  43. {
  44. ll z=b[i];
  45. z*=b[i]-1;
  46. z/=2;
  47. k+=z;
  48. }
  49. }
  50. printf("%lld\n",k );
  51. return 0;
  52. }
Success #stdin #stdout 0.01s 19040KB
stdin
5
1 1
1 5
3 3
5 1
5 5
stdout
6