Instead of writing your ICS4U final exam, your CS teacher Mr. G challenges you to a puzzle! He has laid out a line of pass the course get a good mark, Mr. G asks you to determine the maximum possible score that can be obtained after performing a sequence of
Constraints
For all subtasks:
will not exceed the number of heads in the initial setup.- There is at least one coin that is initially heads.
Points Awarded | |
---|---|
2 points | |
4 points | |
9 points |
Input Specification
The first line contains a string of length H
representing heads and T
representing tails.
The second line contains one integer
Output Specification
Output the maximum score that can be obtained.
Sample Input
THTTHH
3
Sample Output
15
Explanation for Sample Output
The optimal solution is to flip coins
Comments