#agc005a. [agc005_a]STring
[agc005_a]STring
Problem Statement
We have a string , which has an even number of characters. Half the characters are S
, and the other half are T
.
Takahashi, who hates the string ST
, will perform the following operation times:
- Among the occurrences of
ST
in as (contiguous) substrings, remove the leftmost one. If there is no occurrence, do nothing.
Find the eventual length of .
Constraints
- The length of is even.
- Half the characters in are
S
, and the other half areT
.
Partial Scores
- In test cases worth points, .
Input
The input is given from Standard Input in the following format:
Output
Print the eventual length of .
Sample Input 1
TSTTSS
Sample Output 1
4
In the -st operation, the -nd and -rd characters of TSTTSS
are removed. becomes TTSS
, and since it does not contain ST
anymore, nothing is done in the remaining operations. Thus, the answer is .
Sample Input 2
SSTTST
Sample Output 2
0
will eventually become an empty string: SSTTST
⇒ STST
⇒ ST
⇒ ``.
Sample Input 3
TSSTTTSS
Sample Output 3
4
will become: TSSTTTSS
⇒ TSTTSS
⇒ TTSS
.