Codeforces solutions.