Problem with MDOLLS (SPOJ)

Here is a link to my solution and i cant figure out the mistake.
CodeChef: Practical coding for everyone.

Question : SPOJ.com - Problem MDOLLS
It is a SPOJ question. I have just uploaded the solution to codechef for reference.

Please help,
Thanks.