Ralph and Mushrooms

CodeForces - 894E