#!/usr/bin/env python



s = input()



s1 = []

for x in s:

	if not s1:

		s1.append(x)

		continue

	if x == 'T' and s1[-1] == 'S':

		# s1 = s1[:-1]

		del s1[-1]

	else:

		s1.append(x)



print(len(s1))

s = input()

sn = 0

tn = 0

for i in s:

	if i == "S":

		sn += 1

	elif i == "T":

		tn += 1

		if sn > 0:

			sn -= 1

			tn -= 1

print(sn + tn)
#!/usr/bin/env python
s = input()
s1 = []
for x in s:
    if not s1:
        s1.append(x)
        continue
    if x == "T" and s1[-1] == "S":
        # s1 = s1[:-1]
        del s1[-1]
    else:
        s1.append(x)
print(len(s1))

s = input()
sn = 0
tn = 0
for i in s:
    if i == "S":
        sn += 1
    elif i == "T":
        tn += 1
        if sn > 0:
            sn -= 1
            tn -= 1
print(sn + tn)

-#!/usr/bin/env python -s1 = [] -for x in s: -    if not s1: -        s1.append(x) -        continue -    if x == "T" and s1[-1] == "S": -        # s1 = s1[:-1] -        del s1[-1] -    else: -        s1.append(x) -print(len(s1)) +sn = 0 +tn = 0 +for i in s: +    if i == "S": +        sn += 1 +    elif i == "T": +        tn += 1 +        if sn > 0: +            sn -= 1 +            tn -= 1 +print(sn + tn)