WA on test #7.
Code for problem 26E.