TLE on test #11.
Code for problem 85D.