The documented solution to this problem is in preparation.
A program solving this problem can be found in the file squares.pas.