How can I find adjacent duplicates of a specific character in a string? And then delete some of the duplications but not all.

Let's say I have:

```
`str= "KKKKKLLLLLLLLLLLLLLLOOOPPPPLLL"`

```

The only duplicated letter I'm interested in is `L`. I would like to reduce `L` adjacent duplications -> if `L` is part of a line of 15 adjacent duplications, I want it to lose 5 adjacent duplicates. If it is in a line of 3, I want it to lose 1 `L`

Final output should be:

`KKKKKLLLLLLLLLLOOOPPPPLL`

Sorry if this makes very little sense, hopefully you understand what I mean. Any help would be hugely appreciated!!

EDIT: It won't always be reduced by one third, or by the same fraction.

Final note for clarification. My end game: There will be a randomly generated string with a length of a few hundred. The lengths of the duplications will decide how much it needs to reduced by, which is half or less than half. So a line of 50 'L', will need to be reduced by <=25 . A line 64 reduced by <=32. But not reduced by 0. This just seems incredibly complicated to…