#R005A. [AGC005A] STring
[AGC005A] STring
Score : points
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
STin 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 .
TSTTSS
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 .
SSTTST
0
will eventually become an empty string: SSTTST ⇒ STST ⇒ ST ⇒ ``.
TSSTTTSS
4
will become: TSSTTTSS ⇒ TSTTSS ⇒ TTSS.