Has anybody solved the "counitng in Byteland problem in daily code byte"?

my code is working only for 2 test cases and 3rd case is giving wrong answer and other three test cases show the time limit error…
can anybody share the logic used by hi/ her???