WPROB - AC on first two, WA on third subtask

My idea is something like the editorial, I try all 6 cases.
I process the input character by character, and I keep track of how many of each color have I processed.

Example: if I want to sort by order r->g->b, and I enter ‘r’, then I need to move it to the left by already_entered[g]+already_entered[b] places. For the same order, if I enter ‘g’, then I need to move it to the left by already_entered[b] places. If I enter ‘b’, I don’t move it.

My code gives AC for the first two subtasks, but WA for the third one and I can’t seem to find my mistake. Shouldn’t the same approach work for big cases as well?

http://www.codechef.com/viewsolution/6335844

I have implemented the same idea given in editorial and its working for all subtask.

http://www.codechef.com/viewsolution/6335940