x = eval(input())



ans = ""

for i in x:

  ans += i

  if len(ans) >= 2 and (ans[-2] == "S" and ans[-1] == "T"):

    ans = ans[:-2]



print((len(ans)))
x = eval(input())



s = list()

cnt = 0

for c in x:

    if c == "S":

        s.append(c)

    elif c == "T" and len(s) != 0:

        s.pop()

        cnt += 1



print((len(x)-cnt*2))
x = eval(input())
ans = ""
for i in x:
    ans += i
    if len(ans) >= 2 and (ans[-2] == "S" and ans[-1] == "T"):
        ans = ans[:-2]
print((len(ans)))

x = eval(input())
s = list()
cnt = 0
for c in x:
    if c == "S":
        s.append(c)
    elif c == "T" and len(s) != 0:
        s.pop()
        cnt += 1
print((len(x) - cnt * 2))

-ans = "" -for i in x: -    ans += i -    if len(ans) >= 2 and (ans[-2] == "S" and ans[-1] == "T"): -        ans = ans[:-2] -print((len(ans))) +s = list() +cnt = 0 +for c in x: +    if c == "S": +        s.append(c) +    elif c == "T" and len(s) != 0: +        s.pop() +        cnt += 1 +print((len(x) - cnt * 2))