Initial version
TLE on test #18.
Code for problem 46E.