import java.util.Scanner

object Main extends App  {
  val sc = new Scanner(System.in)

  val iS = sc.next

  val s = iS.toVector :+ 'Z'
  
  val res =
    s.foldLeft((0L,0L)){case ((strL, stackL), ch) =>
        ch match{
          case 'S'                => (strL, stackL + 1L)
          case 'T' if stackL == 0 => (strL, stackL - 1L)
          case 'T'                => (strL + 1L, stackL)
          case _                  => (strL + stackL, 0L)
        }
    }._1

  println(res)
}
