{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative
import Data.List (group)
import Debug.Trace

rmST :: [String] -> [String]
rmST [] = []
rmST [x] = [x]
rmST (s:t:ss) =
  if head s == 'S'
    then drop l s:drop l t:rmST ss
    else s: rmST (t:ss)
  where l = min (length s) (length t)

solve' s =
  if s' == s then s else solve' ((group.concat) s')
  where s' = rmST s

main = do
  ss <- group <$> getLine
  print $ sum $ map length $ solve' ss
