s = ''.join(input().split('ST'))

while 1:

    i = s.find('ST')

    if i > -1:

        cnt = 0

        for j in range(min(i, len(s)-2-i)):

            if s[i-j-1] == 'S' and s[i+j+2] == 'T':

                cnt += 1

            else:

                break

        s = s[:i-cnt] + s[i+cnt+2:]

    else:

        break

print((len(s)))
s = ''.join(input().split('ST'))

cnts = 0

cnt = 0

for i in s:

    if i == 'S' :

        cnts += 1

    elif cnts > 0:

        cnts -= 1

        cnt += 1

print((len(s)-cnt*2))
s = "".join(input().split("ST"))
while 1:
    i = s.find("ST")
    if i > -1:
        cnt = 0
        for j in range(min(i, len(s) - 2 - i)):
            if s[i - j - 1] == "S" and s[i + j + 2] == "T":
                cnt += 1
            else:
                break
        s = s[: i - cnt] + s[i + cnt + 2 :]
    else:
        break
print((len(s)))

s = "".join(input().split("ST"))
cnts = 0
cnt = 0
for i in s:
    if i == "S":
        cnts += 1
    elif cnts > 0:
        cnts -= 1
        cnt += 1
print((len(s) - cnt * 2))

-while 1: -    i = s.find("ST") -    if i > -1: -        cnt = 0 -        for j in range(min(i, len(s) - 2 - i)): -            if s[i - j - 1] == "S" and s[i + j + 2] == "T": -                cnt += 1 -            else: -                break -        s = s[: i - cnt] + s[i + cnt + 2 :] -    else: -        break -print((len(s))) +cnts = 0 +cnt = 0 +for i in s: +    if i == "S": +        cnts += 1 +    elif cnts > 0: +        cnts -= 1 +        cnt += 1 +print((len(s) - cnt * 2))