Codeforces 330D: Time Limit Exceeded