문제
Bessie has recently received a painting set, and she wants to paint the long fence at one end of her pasture. The fence consists of
Initially, all fence segments are uncolored. Bessie can color any contiguous range of segments with a single color in a single brush stroke as long as she never paints a lighter color over a darker color (she can only paint darker colors over lighter colors).
For example, an initially uncolored segment of length four can be colored as follows:
.... -> BBB. -> BBLL -> BQQL
Running short on time, Bessie thinks she may need to leave some consecutive range of fence segments unpainted! Currently, she is considering
For each candidate range, what is the minimum number of strokes needed to paint every fence segment outside those in the range with its desired color while leaving all fence segments inside the range uncolored? Note that Bessie does not actually do any painting during this process, so the answers for each candidate range are independent.
입력
The first line contains
The next line contains a string of length
The next
출력
For each of the
예제1
8 2
ABBAABCB
3 6
1 4
4
3
In this example, excluding the sub-range corresponding to the desired pattern
.... -> AA.. -> ABBB -> ABCB