Codeforces Cses Problem Set Weird Algorithm