Algorithm and solutions for Codeforces problems