Getting WA for The Rise and Fall of Power

,

Can someone tell whats wrong with my solution to this problem.
Problem-A4 Problem - CodeChef
My solution-CodeChef: Practical coding for everyone