Scanf.scanf "%s" (fun s ->
    let n = String.length s in

    let rec loop i tame acc =
        if i = n then acc else
            if s.[i] = 'S' then loop (i + 1) (tame + 1) (acc + 1) else
                if tame > 0 then loop (i + 1) (tame - 1) (acc - 1) else
                    loop (i + 1) tame (acc + 1)
    in
    loop 0 0 0 |> Printf.printf "%d\n"
)