PROXY help!

Can anyone tell me what’s wrong with my solution?
https://www.codechef.com/viewsolution/24856563

i have been submitting it again and again making some modifications but still getting WA.

Take input
3
PPP
and
4
PPPP
then make some more modifications
(it should print 0)

U are not getting the minimum in all cases. For example, suppose the given string already has required number of P,it should print 0.
(PPAPPPPPPPPP— ur code gives 1)
Here, this might help: https://www.codechef.com/viewsolution/24602289