problem 1028 (time limit exceeded)