title: Count number of pairs of points with given Manhattan distance
body: <p>I have of <strong>P</strong> points with integer coordinates (denoted by <strong>(xi,yi)</strong> ).</p>
  
  <p>0 &lt;= xi &lt;= n ; 0 &lt;= yi &lt;= m
  (i=1,2...P)</p>
  
  <p>2 &lt;= n,m &lt;= 100</p>
  
  <p>I am interested to find how many pairs of points are exactly <strong>d</strong> distance apart. It is clear that 1 &lt;= d &lt;= m+n-2 and P&lt;= m* n. I want to calculate number of pairs for each <strong>d</strong>. What is the fastest way to that? (I can find this by looping over d and for each d checking every pair. which is very slow process)</p>
  
  <pre><code>e.g.
  points : (0,2);(0,3);(2,1)
  for d=1 : 1 pair
  for d=2 : 0 pairs
  for d=3 : 1 pair
  for d=4 : 1 pair
  for d=5 : 0 pairs
  </code></pre>