a and then there were k codeforces solution