main=print =<< solve 0 <$> getLine

solve a "" = a
solve a x = solve (a + abs (nt-ns)) xr
    where
        nt = length $ takeWhile (=='S') x
        ns = length $ takeWhile (=='T') $ dropWhile (=='S') x
        xr = dropWhile (=='T') $ dropWhile (=='S') x