output_description: Print the eventual length of X.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      X
attempt: import math
  import copy
  from operator import mul
  from functools import reduce
  from collections import defaultdict
  from collections import Counter
  from collections import deque
  
  # 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
  from itertools import product
  
  # 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
  from itertools import permutations
  
  # 組み合わせ {}_len(seq) C_n: combinations(seq, n)
  from itertools import combinations
  
  # 一次元累積和
  from itertools import accumulate
  from bisect import bisect_left, bisect_right
  
  # import numpy as np
  # from scipy.special import perm
  # from scipy.special import comb
  
  
  def inside(y, x, H, W):
      return 0 <= y < H and 0 <= x < W
  
  
  # 四方向: 右, 下, 左, 上
  dy = [0, -1, 0, 1]
  dx = [1, 0, -1, 0]
  
  
  def i_inpl():
      return int(input())
  
  
  def l_inpl():
      return list(map(int, input().split()))
  
  
  INF = float("inf")
  
  ########
  X = input()
  
  cnt = 0
  sum_cnt = 0
  for xi in X:
      if xi == "S":
          cnt += 1
      else:
          if cnt > 0:
              cnt -= 1
              sum_cnt += 1
  
  print(len(X) - sum_cnt * 2)
  
problem_description: Statement
  
  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.
samples: [{"input": "TSTTSS", "output": "4\n    \n\nIn the 1-st operation, the 2-nd and 3-rd characters of `TSTTSS` are removed. X\nbecomes `TTSS`, and since it does not contain `ST` anymore, nothing is done in\nthe remaining 10^{10000}-1 operations. Thus, the answer is 4.\n\n* * *"}, {"input": "SSTTST", "output": "0\n    \n\nX will eventually become an empty string: `SSTTST` \u21d2 `STST` \u21d2 `ST` \u21d2 ``.\n\n* * *"}, {"input": "TSSTTTSS", "output": "4\n    \n\nX will become: `TSSTTTSS` \u21d2 `TSTTSS` \u21d2 `TTSS`."}]