problem 1145 (time limit exceeded)