Having lived nearly twenty years without a lover, Trung decided to go to the temple to seek love. After completing all the rituals, Trung received a love charm. The charm contains a string of length ~n~ consisting of only two letters ~\texttt{O}~ or ~\texttt{K}~. With deep understanding of his own destiny, Trung knows that the effectiveness of the charm depends on the consecutive pairs of letters. Specifically:
The pair ~\texttt{OK}~ has an effect, so if the charm has ~a~ pairs of ~\texttt{OK}~, the effectiveness of the charm will increase by ~a^2~.
The pair ~\texttt{KO}~ has a counter-effect, so if the charm has ~b~ pairs of ~\texttt{KO}~, the effectiveness of the charm will decrease by ~b^2~.
In other words, if the charm has ~a~ pairs of ~\texttt{OK}~ and ~b~ pairs of ~\texttt{KO}~, the effectiveness of the charm will be ~a^2 - b^2~. For example, if the charm contains the string ~\texttt{OOOKOO}~, then ~a = 1~, ~b = 1~, so the effectiveness of the charm will be ~1^2 - 1^2 = 0~.
Trung is not very satisfied with his charm, so he asked the temple for another charm. However, the temple only allows Trung to change the current charm up to ~k~ times, each time Trung can choose any two letters on the charm and swap them. Help Trung obtain a love charm with the maximum possible effectiveness!
Input
Each test contains multiple test cases. The first line contains the number of test cases ~t~ (~1 \leq t \leq 10\,000~). The description of each test case is as follows.
The first line contains two positive integers ~n~ and ~k~ (~2 \leq n \leq 10^5~, ~1 \leq k \leq 10~) — the length of the string written on the charm and the maximum number of transformations.
The second line contains a string ~s~ consisting of ~n~ characters ~\texttt{O}~ or ~\texttt{K}~, describing the string written on the charm.
The sum of ~n~ over all test cases is guaranteed not to exceed ~10^5~.
Output
For each test case, output an integer which is the maximum effectiveness the charm can achieve.
Scoring
Subtask | Score | Constraints |
---|---|---|
1 | ~250~ | Sum of ~n~ does not exceed ~100~, ~k = 1~ |
2 | ~750~ | ~k = 1~ |
3 | ~1250~ | No additional constraints |
Total | ~2250~ |
Sample Input 1
5
2 1
KO
2 1
OK
7 1
OOOKKKK
7 1
KKOOKKK
10 2
KOOKOKKKOO
Sample Output 1
1
1
5
3
9
Notes
In the first test case, the optimal swapping sequence is ~\mathtt{KO}~ ~\to \mathtt{OK}~. The resulting charm has an effectiveness of ~1~.
In the second test case, it is optimal to keep the string as ~\mathtt{OK}~, with an effectiveness of ~1~.
In the fifth test case, an optimal swapping sequence is ~\mathtt{KO}~~\mathtt{OKOKKKOO} \to \mathtt{OKOKOK}~~\texttt{K}~~\texttt{KO}~~\texttt{O}~ ~\to \mathtt{OKOKOKOKOK}~, resulting in a charm with an effectiveness of ~9~.
Comments
Mình xin đóng góp lời giải cho bài này như sau:
Subtask 1:
Subtask 2:
Subtask 3: