Solve Codeforces #284, Problem 2C