import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = getLine >>= print . solve

solve :: String -> Int
solve ss = count . map ((,) <$> head <*> length) $ group ss 
    where
        n = length ss
        count xs = check n xs
        check acc (('S', xl) : ('T', yl) : zs)
            | xl > yl = check (acc - 2 * yl) $ ('S', xl - yl) : zs
            | otherwise = check (acc - 2 * xl) zs
        check acc (('S', xl) : ('S', yl) : zs) = check acc $ ('S', xl + yl) : zs
        check acc ((_, _) : zs) = check acc zs
        check acc _ = acc

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine