(use util.match)
(use srfi-1)

(define (list-init n func)
  (let loop ([i n])
    (if (zero? i)
      ()
      (cons (func) (loop (- i 1))))))

(define (vector-init n func)
  (define vec (make-vector n))
  (dotimes (i n)
    (vector-set! vec i (func)))
  vec)

; ---------------------------

(print
(let* ([ST (symbol->string (read))]
       [n (string-length ST)])
  (let loop([s 0][t 0][l 0][r 1][total 0])
    (cond [(= r n) (- n total (* (min s t) 2))]
          [(< s t) (loop 0 0 (+ l 1) (+ r 1) (+ total s (- t 1)))]
          [(char=? #\S (~ ST l) (~ ST r)) (loop (+ s 1) t (+ l 1) (+ r 1) total)]
          [(char=? #\T (~ ST l) (~ ST r)) (loop s (+ t 1) (+ l 1) (+ r 1) total)]
          [(and (char=? #\S (~ ST l))
                (char=? #\T (~ ST r)))
           (loop (+ s 1) (+ t 1) (+ l 1) (+ r 1) total)]
          [else (loop 0 0 (+ l 1) (+ r 1) (+ total s t))])))
)