This is a codechef Rise and Fall of Power problem