Codeforces Round #516 E. Dwarves, Hats and Extrasensory Abilities

NoSuchKey