Initial version.
Initial implementation - efficiency not good enough.
Code for problem 35D.