Initial version - WA on test #4.
TLE on test #11.
WA on test #31.
Code for problem 371E.