s = input()[::-1]

n = len(s)

tmp = 0

ans = 0

for i in range(n):

    if s[i] == 'S':

        tmp += 1

    else:

        tmp -= 1

    ans = max(ans, tmp)



print((ans * 2))
from collections import deque



s = eval(input())

n = len(s)

que = deque()

for i in range(n):

    if s[i] == 'S':

        que.append(s[i])

    else:

        if len(que) == 0:

            que.append(s[i])

        elif que[-1] == 'T':

            que.append(s[i])

        else:

            que.pop()

    

print((len(que)))
s = input()[::-1]
n = len(s)
tmp = 0
ans = 0
for i in range(n):
    if s[i] == "S":
        tmp += 1
    else:
        tmp -= 1
    ans = max(ans, tmp)
print((ans * 2))

from collections import deque

s = eval(input())
n = len(s)
que = deque()
for i in range(n):
    if s[i] == "S":
        que.append(s[i])
    else:
        if len(que) == 0:
            que.append(s[i])
        elif que[-1] == "T":
            que.append(s[i])
        else:
            que.pop()
print((len(que)))

-s = input()[::-1] +from collections import deque + +s = eval(input()) -tmp = 0 -ans = 0 +que = deque() -        tmp += 1 +        que.append(s[i]) -        tmp -= 1 -    ans = max(ans, tmp) -print((ans * 2)) +        if len(que) == 0: +            que.append(s[i]) +        elif que[-1] == "T": +            que.append(s[i]) +        else: +            que.pop() +print((len(que)))