Problems
Bessie is given a positive integer
String + represents string concatenation. For example, "COWCOW" and "CC" are examples of square strings but "COWO" and "OC" are not.
In a single operation, Bessie can remove any subsequence
Your job is to help Bessie determine whether it is possible to transform S
into an empty string. Additionally, if it is possible, then you must provide a way to do so.
Bessie is also given a parameter
If
If
Input
The first line contains
(
The first line of each test case has
The second line of each test case has
The sum of
Output
For each test case, output either one or two lines using the following procedure.
If it is impossible to transform
Otherwise, on the first line print
Subtask
| # | Score | Condition |
|---|---|---|
| #1 | 20 | |
| #2 | 30 | |
| #3 | 50 | |
Example #1
3 1
3
COWOWCWCO
4
WCOCOWWCOCOW
6
COWCOWOWCOWCOWCOWC
-1
1
1 1 1 1 1 1 1 1 1 1 1 1
3
3 3 2 3 3 2 1 1 1 1 1 1 1 1 1 1 1 1
For the last test, the optimal number of operations is two, so any valid construction with either
For
In the first operation, remove the last twelve characters. Now we're left with COWCOW.
In the second operation, remove the subsequence WW. Now we're left with COCO.
In the last operation, remove all remaining characters.
Example #2
3 0
3
COWOWCWCO
4
WCOCOWWCOCOW
6
COWCOWOWCOWCOWCOWC
-1
1
1 1 1 1 1 1 1 1 1 1 1 1
2
1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2