#K14181. Minimal Operations to Avoid Excessive Consecutive Characters
Minimal Operations to Avoid Excessive Consecutive Characters
Minimal Operations to Avoid Excessive Consecutive Characters
In this problem, you are given an integer ( k ) and a string ( s ). Your task is to determine the minimum number of operations required so that no character in ( s ) appears more than ( k ) times consecutively. An operation is defined as the removal of a single character from the string. Specifically, for any consecutive block of identical characters of length ( L ) where ( L > k ), the number of removals needed for that block is given by ( \left\lfloor \frac{L-1}{k} \right\rfloor ). Your solution should read from the standard input and write the result to the standard output.
inputFormat
The input consists of two lines:
- The first line contains a single integer \( k \) (\(1 \leq k \leq 10^5\)), which specifies the maximum allowed number of consecutive characters.
- The second line contains the string \( s \) (\(1 \leq |s| \leq 10^5\)), consisting of lowercase English letters.
outputFormat
Output a single integer representing the minimum number of operations required so that no character appears more than \( k \) times consecutively in the string \( s \).
## sample2
aaabbbcc
2