Codeforces Beta Round 96 (Div. 1)
C
Logo Turtle
Codeforces
1800
原题
← BD →
翻译中…

A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward").

翻译中…

You are given a list of commands that will be given to the turtle. You have to change exactly $*n*$ commands from the list (one command can be changed several times). How far from the starting point can the turtle move after it follows all the commands of the modified list?

翻译中…

Input

翻译中…

The first line of input contains a string $*commands*$ — the original list of commands. The string $*commands*$ contains between 1 and 100 characters, inclusive, and contains only characters "T" and "F".

翻译中…

The second line contains an integer $*n*$ ($1 ≤ *n* ≤ 50$) — the number of commands you have to change in the list.

翻译中…

Output

翻译中…

Output the maximum distance from the starting point to the ending point of the turtle's path. The ending point of the turtle's path is turtle's coordinate after it follows all the commands of the modified list.

翻译中…

Note

翻译中…

In the first example the best option is to change the second command ("T") to "F" — this way the turtle will cover a distance of 2 units.

翻译中…

In the second example you have to change two commands. One of the ways to cover maximal distance of 6 units is to change the fourth command and first or last one.

翻译中…

样例

Input #1
FT
1
Output #1
2
InputCopy OutputCopy
Input #2
FFFTFFF
2
Output #2
6
InputCopy OutputCopy
题目信息
题号
132C
时间限制
2 s
内存限制
256 MB
标签
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。