Codeforces 984C. Finite or not?

NoSuchKey