You are given a string consisting only of the characters A and B, and an integer .
For a string , define by replacing each character independently as follows:
A is replaced with AB;
B is replaced with A.
Initially, the current string is empty. You can perform the following operations:
Append the next character of to the current string. If its length becomes , the cost of this operation is .
If the current string is a non-empty string , replace it with
The cost of this operation is . It can be performed only if the resulting string is a prefix of .
Find the minimum total cost needed to obtain .
The first line contains one integer (1 \le n \le 2 \cdot 10^5).
The second line contains the string of length , consisting only of the characters A and B.
The third line contains one integer (1 \le c \le 10^9).
Print one integer — the minimum total cost needed to obtain .
Example 1
In the example, first append A. The cost of this operation is .
Now the current string is A. Since
we can perform the second operation and obtain
This operation costs , so the total cost is
Subtask ( points): n \le 20.
Subtask ( points): n \le 100.
Subtask ( points): n \le 2000.
Subtask ( points): c = 1.
Subtask ( points): No additional constraints.