STring

AtCoder
IDagc005_a
Time1000ms
Memory256MB
Difficulty
We have a string $X$, 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 $10^{10000}$ times: * Among the occurrences of `ST` in $X$ as (contiguous) substrings, remove the leftmost one. If there is no occurrence, do nothing. Find the eventual length of $X$. ## Constraints * $2 ≦ |X| ≦ 200,000$ * The length of $X$ is even. * Half the characters in $X$ are `S`, and the other half are `T`. ## Input The input is given from Standard Input in the following format: $X$ ## Partial Scores * In test cases worth $200$ points, $|X| ≦ 200$. [samples]
Samples
Input #1
TSTTSS
Output #1
4

In the $1$\-st operation, the $2$\-nd and $3$\-rd characters of `TSTTSS` are removed. $X$ becomes `TTSS`, and since it does not contain `ST` anymore, nothing is done in the remaining $10^{10000}-1$ operations. Thus, the answer is $4$.
Input #2
SSTTST
Output #2
0

$X$ will eventually become an empty string: `SSTTST` ⇒ `STST` ⇒ `ST` ⇒ \`\`.
Input #3
TSSTTTSS
Output #3
4

$X$ will become: `TSSTTTSS` ⇒ `TSTTSS` ⇒ `TTSS`.
API Response (JSON)
{
  "problem": {
    "name": "STring",
    "description": {
      "content": "We have a string $X$, 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 $10^{1",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc005_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have a string $X$, which has an even number of characters. Half the characters are `S`, and the other half are `T`.\nTakahashi, who hates the string `ST`, will perform the following operation $10^{1...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments