Codeforces Round #232 (Div. 2), Problem D