from collections import deque

X = eval(input())

L = deque([])

for e in X:

    if e == "T" and len(L) > 0 and L[-1] == "S":

        L.pop()

    else:

        L.append(e)



print((len(L)))

X = eval(input())

N = len(X)

c = 0

s, t = 0, 0

for k in range(N):

    if X[k] == "S":

        s += 1

    else:

        t += 1

        if s > 0 and t > 0:

            s -= 1

            t -= 1

            c += 2

print((N-c))

from collections import deque

X = eval(input())
L = deque([])
for e in X:
    if e == "T" and len(L) > 0 and L[-1] == "S":
        L.pop()
    else:
        L.append(e)
print((len(L)))

X = eval(input())
N = len(X)
c = 0
s, t = 0, 0
for k in range(N):
    if X[k] == "S":
        s += 1
    else:
        t += 1
        if s > 0 and t > 0:
            s -= 1
            t -= 1
            c += 2
print((N - c))

-from collections import deque - -L = deque([]) -for e in X: -    if e == "T" and len(L) > 0 and L[-1] == "S": -        L.pop() +N = len(X) +c = 0 +s, t = 0, 0 +for k in range(N): +    if X[k] == "S": +        s += 1 -        L.append(e) -print((len(L))) +        t += 1 +        if s > 0 and t > 0: +            s -= 1 +            t -= 1 +            c += 2 +print((N - c))