Write a square-counting program A well-known puzzle involves counting how many squares can be made using the points on a 3x3 grid:

.  .  .
.  .  .
.  .  .


The answer is 6 &mdash; four small squares, one large square, and one square formed from the top, left, bottom, and right pegs, with edges along the diagonals of the squares.

Your task is to build a program that counts the total number of squares that can be formed from a set of points.

Your program will take input in one of two formats (of your choosing):


An M by N grid  consisting of either . or . . represents a point on the grid that a square can be a corner of, and all spaces on the grid are exactly one unit apart horizontally or vertically.
A list of coordinate pairs representing points that a square can be on.


and return the number of distinct squares that can be formed using the points provided. Your program must return a correct solution for every possible input.



For example, take the input above but where the center square is missing:

...
. .
...


There are only two possible squares here (the big one and the diagonal one), so the program should return 2.



The shortest code to do this in any language wins.
Python, 95

Takes a list of coordinates from stdin.

l=input();print(sum((c-d+b,d+c-a)in l and(a-d+b,b+c-a)in l for a,b in l for c,d in l)-len(l))/4


Explanation:


   For each pair of points (a,b) and (c,d), check if the square with additional points (c-d+b,d+c-a) and (a-d+b,b+c-a) is in the list.  This counts each square 4 times, and each point once (when (a,b) = (c,d)), so subtracting the number of points and dividing by 4 gives the number of squares.