ans=0

stack=[]

for s in eval(input()):

    if len(stack)>0 and s=="T":

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

            del stack[-1]

        else:

            stack.append(s)

    else:

        stack.append(s)

print((len(stack)))
s=eval(input())

stack=[]

ans=0

for i in s:

    if i=="S":

        stack.append(1)

    elif len(stack)>0 and i=="T":

        stack.pop()

        ans+=1

print((len(s)-ans*2))

ans = 0
stack = []
for s in eval(input()):
    if len(stack) > 0 and s == "T":
        if stack[-1] == "S":
            del stack[-1]
        else:
            stack.append(s)
    else:
        stack.append(s)
print((len(stack)))

s = eval(input())
stack = []
ans = 0
for i in s:
    if i == "S":
        stack.append(1)
    elif len(stack) > 0 and i == "T":
        stack.pop()
        ans += 1
print((len(s) - ans * 2))

+s = eval(input()) +stack = [] -stack = [] -for s in eval(input()): -    if len(stack) > 0 and s == "T": -        if stack[-1] == "S": -            del stack[-1] -        else: -            stack.append(s) -    else: -        stack.append(s) -print((len(stack))) +for i in s: +    if i == "S": +        stack.append(1) +    elif len(stack) > 0 and i == "T": +        stack.pop() +        ans += 1 +print((len(s) - ans * 2))