X = eval(input())

stack = []

for e in X:

    if e == "S":

        stack.append(e)

    elif stack == []:

        stack.append(e)

    elif stack[-1] == "T":

        stack.append(e)

    elif stack[-1] == "S":

        stack.pop(-1)

print((len(stack)))
from collections import deque



X = eval(input())



dq = deque()



for x in X:

    if not dq:

        dq.append(x)

    elif dq[-1] == "S" and x == "T":

        dq.pop()

    else:

        dq.append(x)

    

ans = len(dq)

print(ans)
X = eval(input())
stack = []
for e in X:
    if e == "S":
        stack.append(e)
    elif stack == []:
        stack.append(e)
    elif stack[-1] == "T":
        stack.append(e)
    elif stack[-1] == "S":
        stack.pop(-1)
print((len(stack)))

from collections import deque

X = eval(input())
dq = deque()
for x in X:
    if not dq:
        dq.append(x)
    elif dq[-1] == "S" and x == "T":
        dq.pop()
    else:
        dq.append(x)
ans = len(dq)
print(ans)

+from collections import deque + -stack = [] -for e in X: -    if e == "S": -        stack.append(e) -    elif stack == []: -        stack.append(e) -    elif stack[-1] == "T": -        stack.append(e) -    elif stack[-1] == "S": -        stack.pop(-1) -print((len(stack))) +dq = deque() +for x in X: +    if not dq: +        dq.append(x) +    elif dq[-1] == "S" and x == "T": +        dq.pop() +    else: +        dq.append(x) +ans = len(dq) +print(ans)