Initial version, WA on test #3.
Code for problem 364A.