Codeforces Round #483 (Div. 2) C. Finite or not?

NoSuchKey