Counting-out Rhyme

CodeForces - 792B