You are given a string
s
You perform the following operation until the string becomes
empty: choose some
consecutive substring
of equal characters,
erase it from the string and glue the remaining two parts
together (any of them can be empty) in the same order. For
example, if you erase the substring
111 from the string
111110, you will get the string
110. When you delete
a substring of length
l
Your task is to calculate the maximum number of points that you can score in total, if you have to make the given string empty.
The first line contains a single integer
t
The first line of each testcase contains three integers
n
The second line contains the string
s
For each testcase, print a single integer — the maximum number of points that you can score.
3 3 2 0 000 5 -2 5 11001 6 1 -4 100111
6 15 -2
In the first example, it is enough to delete the entire
string, then we will get
2⋅3+0=6
In the second example, if we delete characters one by one,
then for each deleted character we will get
(−2)⋅1+5=3
In the third example, we can delete the substring
00 from the string
100111, we get
1⋅2+(−4)=−2
| Name | |||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| No items | |||||||||||||||||||||||||||||||


