Yet Another Monster Killing Problem

CodeForces - 1257D