KCOMPRESS August long challenge

I am a newbie to competitive programming, can someone please explain the logic behind this question
Link : KCOMPRES Problem - CodeChef