HeapGreedyMath
A CPU must run a list of tasks, each labelled with a capital letter. One task runs per time unit (or the CPU idles). Between two runs of the same task there must be at least n time units of cooling. Find the least number of time units needed to finish every task.
Input
Line 1: the tasks as a string of capital letters. Line 2: the cooldown n.
Output
Print the minimum number of time units.
Constraints
1 <= number of tasks <= 10^4 0 <= n <= 100
Example 1
Input
AAABBB 2
Output
8
A B idle A B idle A B takes 8 units.
Example 2
Input
AAABBB 0
Output
6
No cooldown, so just 6 units.