Initial version - WA on test #8.
Second version - WA on test #21.
Code for problem 336D.