Codeforces #660 (Div. 2) B. Captain Flint and a Long Voyage

NoSuchKey