Spoj question

Can anyone point out my mistake?
Question link: https://www.spoj.com/problems/MLASERP/
My code: https://ideone.com/mPaPKk