Help STPAR

I am trying to sole this and not getting the logic.
help…??

link to my code : faXMAR - Online IDE & Debugging Tool - Ideone.com
link to problem : SPOJ.com - Problem STPAR