Why I am getting wrong answer in RAINBOWA?

Problem :- RAINBOWA
https://www.codechef.com/viewsolution/18991268

Correct your logic its an easy problem, follow the editorial if required.

Here is one of the lots of Test Cases for which your code fails:

1
13
1234567654321