C++ sol for another codeforces problem